123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /**
- * Created by robin on 11/3/15.
- */
-
- angular.module('luticateUtils')
- .directive('luEditTable', ['dialogs', 'luticateDialogErrorHelper',
- function(dialogs, luticateDialogErrorHelper) {
- return {
- restrict: 'E',
- scope: {
- options: '&'
- },
- templateUrl: "/luticate/lutable.html",
- link: function ($scope, element, attrs) {
-
- $scope.tableOptions = $scope.options();
-
- 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)
- {
- }
- }
- var onItemClicked = $scope.tableOptions.onItemClicked;
- $scope.tableOptions.onItemClicked = function (item) {
- if (onItemClicked != null) {
- onItemClicked(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);
- });
- };
-
-
- $scope.tableOptions.canCheck = $scope.tableOptions.canDelete;
- $scope.tableOptions.canClick = $scope.tableOptions.canEdit;
-
-
- $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);
- $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) {
- });
- });
- };
-
- $scope.addItem = function () {
- var ctrl = $scope.tableOptions.getEditController();
- dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', null)
- .result.then(function (data) {
- $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
- $scope.tableOptions.onItemAdded(data);
- });
- };
- }
- };
- }
- ]);
-
- 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.canDelete()">' +
- ' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete' +
- ' </button>' +
- ' <button class="btn btn-default" type="button" ng-click="addItem()" ng-show="tableOptions.canAdd()">' +
- ' <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
- ' </button>' +
- ' </div>');
- }]);
|