Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Added extra setting option using which client can enable/disable options #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pages/javascripts/pages/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,12 @@ <h2>Settings</h2>
<td>angular.noop</td>
<td>Related the "Smart Button Text" feature, if a function provided - it will called with two paramters: The item's text and the original item, the return value will displayed instead of the item's display property. This feature is useful when you want to convert the displayed text into something else.</td>
</tr>
<tr>
<td>allowSelectionProp</td>
<td>String</td>
<td>undefined</td>
<td>Name of the property that should be used to determine it should allow user to select the option or not</td>
</tr>
</tbody>
</table>
<h2>Events</h2>
Expand Down
12 changes: 9 additions & 3 deletions src/angularjs-dropdown-multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
template += '<li role="presentation" ng-repeat="option in options | filter: searchFilter">';
}

template += '<a role="menuitem" tabindex="-1" ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))">';
template += '<a role="menuitem" tabindex="-1" ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))" ng-disabled="settings.allowSelectionProp && getPropertyForObject(option, settings.allowSelectionProp) === false">';

if (checkboxes) {
template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> {{getPropertyForObject(option, settings.displayProp)}}</label></div></a>';
template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" ng-disabled="settings.allowSelectionProp &&getPropertyForObject(option, settings.allowSelectionProp) === false" /> {{getPropertyForObject(option, settings.displayProp)}}</label></div></a>';
} else {
template += '<span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a>';
}
Expand Down Expand Up @@ -93,7 +93,8 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
groupBy: $attrs.groupBy || undefined,
groupByTextProvider: null,
smartButtonMaxItems: 0,
smartButtonTextConverter: angular.noop
smartButtonTextConverter: angular.noop,
allowSelectionProp: undefined
};

$scope.texts = {
Expand Down Expand Up @@ -257,6 +258,11 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
finalObj = findObj;
}

if($scope.settings.allowSelectionProp && getPropertyForObject(_.find($scope.options, findObj), $scope.settings.allowSelectionProp) === false) {
//Disabled option
return;
}

if ($scope.singleSelection) {
clearObject($scope.selectedModel);
angular.extend($scope.selectedModel, finalObj);
Expand Down