123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /**
- * Created by robin on 11/3/15.
- */
-
- angular.module('luticateUtils')
- .directive('luEditTable', ['dialogs', 'luticateDialogErrorHelper', 'luticateAuthCache',
- function(dialogs, luticateDialogErrorHelper, luticateAuthCache) {
- return {
- restrict: 'E',
- scope: {
- options: '&'
- },
- templateUrl: "/luticate/lutable.html",
- link: function ($scope, element, attrs) {
-
- $scope.tableOptions = $scope.options();
- $scope.tableOptions.luEditTableScope = $scope;
-
- if ($scope.tableOptions.onItemDeleted == null) {
- $scope.tableOptions.onItemDeleted = function(item)
- {
- }
- }
- if ($scope.tableOptions.onItemEdited == null) {
- $scope.tableOptions.onItemEdited = function(item)
- {
- }
- }
- if ($scope.tableOptions.onItemAdded == null) {
- $scope.tableOptions.onItemAdded = function(item)
- {
- }
- }
- if ($scope.tableOptions.onItemClicked == null) {
- $scope.tableOptions.onItemClicked = function (item) {
- var ctrl = $scope.tableOptions.getEditController();
- dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', item)
- .result.then(function (data) {
- $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
- $scope.tableOptions.onItemEdited(data);
- });
- };
- }
- if ($scope.tableOptions.addItem == null) {
- $scope.tableOptions.addItem = function()
- {
- var ctrl = $scope.tableOptions.getEditController();
- dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', $scope.tableOptions.editData)
- .result.then(function (data) {
- $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
- $scope.tableOptions.onItemAdded(data);
- });
- }
- }
-
-
- if ($scope.tableOptions.canDel == null) {
- $scope.tableOptions.canDel = function()
- {
- return false;
- }
- }
- if (typeof $scope.tableOptions.canDel == 'string') {
- var permDel = $scope.tableOptions.canDel;
- $scope.tableOptions.canDel = function()
- {
- return luticateAuthCache.hasEffectivePermission(permDel);
- }
- }
- $scope.tableOptions.canCheck = $scope.tableOptions.canDel;
-
- if ($scope.tableOptions.canEdit == null) {
- $scope.tableOptions.canEdit = function()
- {
- return false;
- }
- }
- if (typeof $scope.tableOptions.canEdit == 'string') {
- var permEdit = $scope.tableOptions.canEdit;
- $scope.tableOptions.canEdit = function()
- {
- return luticateAuthCache.hasEffectivePermission(permEdit);
- }
- }
- $scope.tableOptions.canClick = $scope.tableOptions.canEdit;
-
- if ($scope.tableOptions.canAdd == null) {
- $scope.tableOptions.canAdd = function()
- {
- return false;
- }
- }
- if (typeof $scope.tableOptions.canAdd == 'string') {
- var permAdd = $scope.tableOptions.canAdd;
- $scope.tableOptions.canAdd = function()
- {
- return luticateAuthCache.hasEffectivePermission(permAdd);
- }
- }
-
-
- $scope.deleteItems = function () {
- if ($scope.tableOptions.checkedItems.length == 0) {
- $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
- return;
- }
- var promiseDelItems = {
- id: "promiseDelItems",
- loaderGroups: [$scope.tableOptions.luBusy.group]
- };
- var item = $scope.tableOptions.checkedItems[0];
- $scope.tableOptions.getDelPromise(item, promiseDelItems)
- .then(function (data) {
- $scope.tableOptions.onItemDeleted(item);
- $scope.tableOptions.checkedItems.splice(0, 1);
- $scope.deleteItems();
- }, function (error) {
- luticateDialogErrorHelper.errorDialog(error)
- .result.then(function (data) {
- $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
- }, function (error) {
- });
- });
- };
- }
- };
- }
- ]);
-
- angular.module('luticateUtils').run(['$templateCache', function($templateCache)
- {
- $templateCache.put('/luticate/lutable.html',
- ' <lu-basic-table options="tableOptions"></lu-basic-table>' +
- '<div class="col-sm-12">' +
- ' <button class="btn btn-default" type="button" ng-click="deleteItems()"' +
- 'ng-disabled="tableOptions.checkedItems.length == 0" ng-show="tableOptions.canDel()">' +
- ' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete' +
- ' </button>' +
- ' <button class="btn btn-default" type="button" ng-click="tableOptions.addItem()" ng-show="tableOptions.canAdd()">' +
- ' <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
- ' </button>' +
- ' </div>');
- }]);
|