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

Added Id property of settings #445

Open
wants to merge 2 commits 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
23 changes: 12 additions & 11 deletions src/app/component/angularjs-dropdown-multiselect.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function dropdownMultiselectController(
};

const settings = {
id: undefined,
dynamicTitle: true,
scrollable: false,
scrollableHeight: '300px',
Expand Down Expand Up @@ -153,7 +154,7 @@ export default function dropdownMultiselectController(
orderFunction,
});

$scope.externalEvents.onInitDone();
$scope.externalEvents.onInitDone(settings.id);

function focusFirstOption() {
setTimeout(() => {
Expand Down Expand Up @@ -206,7 +207,7 @@ export default function dropdownMultiselectController(
$scope.setSelectedItem(item, false, false);
}
});
$scope.externalEvents.onSelectionChanged();
$scope.externalEvents.onSelectionChanged(settings.id);
}

function getGroupLabel(groupValue) {
Expand Down Expand Up @@ -301,24 +302,24 @@ export default function dropdownMultiselectController(

function selectAll() {
$scope.deselectAll(true);
$scope.externalEvents.onSelectAll();
$scope.externalEvents.onSelectAll(settings.id);

const searchResult = $filter('filter')($scope.options, $scope.getFilter($scope.input.searchFilter));
angular.forEach(searchResult, (value) => {
$scope.setSelectedItem(value, true, false);
});
$scope.externalEvents.onSelectionChanged();
$scope.externalEvents.onSelectionChanged(settings.id);
$scope.selectedGroup = null;
}

function deselectAll(dontSendEvent = false) {
if (!dontSendEvent) {
$scope.externalEvents.onDeselectAll();
$scope.externalEvents.onDeselectAll(settings.id);
}

$scope.selectedModel.splice(0, $scope.selectedModel.length);
if (!dontSendEvent) {
$scope.externalEvents.onSelectionChanged();
$scope.externalEvents.onSelectionChanged(settings.id);
}
$scope.selectedGroup = null;
}
Expand All @@ -336,33 +337,33 @@ export default function dropdownMultiselectController(

if (!dontRemove && exists) {
$scope.selectedModel.splice(indexOfOption, 1);
$scope.externalEvents.onItemDeselect(option);
$scope.externalEvents.onItemDeselect(option, settings.id);
if ($scope.settings.closeOnDeselect) {
$scope.close();
}
} else if (!exists && ($scope.settings.selectionLimit === 0 || $scope.selectedModel.length < $scope.settings.selectionLimit)) {
$scope.selectedModel.push(option);
if (fireSelectionChange) {
$scope.externalEvents.onItemSelect(option);
$scope.externalEvents.onItemSelect(option, settings.id);
}
if ($scope.settings.closeOnSelect) {
$scope.close();
}
if ($scope.settings.selectionLimit > 0 && $scope.selectedModel.length === $scope.settings.selectionLimit) {
$scope.externalEvents.onMaxSelectionReached();
$scope.externalEvents.onMaxSelectionReached(settings.id);
}
} else if ($scope.settings.selectionLimit === 1 && !exists && $scope.selectedModel.length === $scope.settings.selectionLimit) {
$scope.selectedModel.splice(0, 1);
$scope.selectedModel.push(option);
if (fireSelectionChange) {
$scope.externalEvents.onItemSelect(option);
$scope.externalEvents.onItemSelect(option, settings.id);
}
if ($scope.settings.closeOnSelect) {
$scope.close();
}
}
if (fireSelectionChange) {
$scope.externalEvents.onSelectionChanged();
$scope.externalEvents.onSelectionChanged(settings.id);
}
$scope.selectedGroup = null;
}
Expand Down
20 changes: 13 additions & 7 deletions src/app/main/main.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ <h2>Settings</h2>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>string</td>
<td>undefined</td>
<td>Useful in case of multiple filters with a single event listener. Sent to all listeners so the function can identify which filter triggered the event (see below).</td>
</tr>
<tr>
<td>dynamicTitle</td>
<td>Boolean</td>
Expand Down Expand Up @@ -1367,37 +1373,37 @@ <h2>Events</h2>
<tbody>
<tr>
<td>onItemSelect</td>
<td>item</td>
<td>item, id</td>
<td>Fired when selecting an item.</td>
</tr>
<tr>
<td>onItemDeselect</td>
<td>item</td>
<td>item, id</td>
<td>Fired when unselecting an item.</td>
</tr>
<tr>
<td>onSelectAll</td>
<td></td>
<td>id</td>
<td>Fired when clicking select all.</td>
</tr>
<tr>
<td>onDeselectAll</td>
<td></td>
<td>id</td>
<td>Fired when clicking unselect all.</td>
</tr>
<tr>
<td>onInitDone</td>
<td></td>
<td>id</td>
<td>Fired when the directive done with the "link" phase.</td>
</tr>
<tr>
<td>onMaxSelectionReached</td>
<td></td>
<td>id</td>
<td>Fired when the user reaches the max allowed selected items.</td>
</tr>
<tr>
<td>onSelectionChanged</td>
<td></td>
<td>id</td>
<td>Fired when the selection changes.</td>
</tr>
</tbody>
Expand Down