Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('app').controller('entityLookupModalController', entityLookupModalController);
- entityLookupModalController.$inject = ['$scope', '$modalInstance', 'options'];
- function entityLookupModalController($scope, $modalInstance, options) {
- let self = this;
- self.gridOptions = {
- enableRowSelection: true,
- enableRowHeaderSelection: false,
- multiSelect: false,
- enableFiltering: true,
- onRegisterApi: onRegisterApi,
- data: getData(),
- rowTemplate: ` <div ng-dblclick="grid.appScope.dblclickHandler(row.entity)"
- ng-repeat="col in colContainer.renderedColumns track by col.colDef.name"
- class="ui-grid-cell" ui-grid-cell></div>`
- };
- _.assign(self.gridOptions, _.omit(options, 'data'));
- $scope.dblclickHandler = (val)=> {
- $modalInstance.close(val);
- };
- self.selectedItem = null;
- self.ok = closeAndReturnSelectedOption;
- self.cancel = closeWithoutReturn;
- function onRegisterApi(gridApi) {
- // set gridApi on scope
- self.gridApi = gridApi;
- gridApi.selection.on.rowSelectionChanged($scope, (row) => {
- self.selectedItem = row.isSelected ? row.entity : null;
- });
- }
- function getData() {
- return options.data.map((row)=> {
- let obj = !_.isPlainObject(row.value)
- ? { lookup: row.value }
- : row.value;
- obj.key = row.id || _.uniqueId();
- return obj;
- });
- }
- function closeAndReturnSelectedOption() {
- if (self.selectedItem !== null) {
- $modalInstance.close(self.selectedItem);
- }
- }
- function closeWithoutReturn() {
- $modalInstance.dismiss('cancel');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement