您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

luedittable.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * Created by robin on 11/3/15.
  3. */
  4. angular.module('luticateUtils')
  5. .directive('luEditTable', ['dialogs', 'luticateDialogErrorHelper', 'luticateAuthCache',
  6. function(dialogs, luticateDialogErrorHelper, luticateAuthCache) {
  7. return {
  8. restrict: 'E',
  9. scope: {
  10. options: '&'
  11. },
  12. templateUrl: "/luticate/lutable.html",
  13. link: function ($scope, element, attrs) {
  14. $scope.tableOptions = $scope.options();
  15. if ($scope.tableOptions.onItemDeleted == null) {
  16. $scope.tableOptions.onItemDeleted = function(item)
  17. {
  18. }
  19. }
  20. if ($scope.tableOptions.onItemEdited == null) {
  21. $scope.tableOptions.onItemEdited = function(item)
  22. {
  23. }
  24. }
  25. if ($scope.tableOptions.onItemAdded == null) {
  26. $scope.tableOptions.onItemAdded = function(item)
  27. {
  28. }
  29. }
  30. var onItemClicked = $scope.tableOptions.onItemClicked;
  31. $scope.tableOptions.onItemClicked = function (item) {
  32. if (onItemClicked != null) {
  33. onItemClicked(item);
  34. }
  35. var ctrl = $scope.tableOptions.getEditController();
  36. dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', item)
  37. .result.then(function (data) {
  38. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  39. $scope.tableOptions.onItemEdited(data);
  40. });
  41. };
  42. if ($scope.tableOptions.canDel == null) {
  43. $scope.tableOptions.canDel = function()
  44. {
  45. return false;
  46. }
  47. }
  48. if (typeof $scope.tableOptions.canDel == 'string') {
  49. var permDel = $scope.tableOptions.canDel;
  50. $scope.tableOptions.canDel = function()
  51. {
  52. return luticateAuthCache.hasEffectivePermission(permDel);
  53. }
  54. }
  55. $scope.tableOptions.canCheck = $scope.tableOptions.canDel;
  56. if ($scope.tableOptions.canEdit == null) {
  57. $scope.tableOptions.canEdit = function()
  58. {
  59. return false;
  60. }
  61. }
  62. if (typeof $scope.tableOptions.canEdit == 'string') {
  63. var permEdit = $scope.tableOptions.canEdit;
  64. $scope.tableOptions.canEdit = function()
  65. {
  66. return luticateAuthCache.hasEffectivePermission(permEdit);
  67. }
  68. }
  69. $scope.tableOptions.canClick = $scope.tableOptions.canEdit;
  70. if ($scope.tableOptions.canAdd == null) {
  71. $scope.tableOptions.canAdd = function()
  72. {
  73. return false;
  74. }
  75. }
  76. if (typeof $scope.tableOptions.canAdd == 'string') {
  77. var permAdd = $scope.tableOptions.canAdd;
  78. $scope.tableOptions.canAdd = function()
  79. {
  80. return luticateAuthCache.hasEffectivePermission(permAdd);
  81. }
  82. }
  83. $scope.deleteItems = function () {
  84. if ($scope.tableOptions.checkedItems.length == 0) {
  85. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  86. return;
  87. }
  88. var promiseDelItems = {
  89. id: "promiseDelItems",
  90. loaderGroups: [$scope.tableOptions.luBusy.group]
  91. };
  92. var item = $scope.tableOptions.checkedItems[0];
  93. $scope.tableOptions.getDelPromise(item, promiseDelItems)
  94. .then(function (data) {
  95. $scope.tableOptions.onItemDeleted(item);
  96. $scope.tableOptions.checkedItems.splice(0, 1);
  97. $scope.deleteItems();
  98. }, function (error) {
  99. luticateDialogErrorHelper.errorDialog(error)
  100. .result.then(function (data) {
  101. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  102. }, function (error) {
  103. });
  104. });
  105. };
  106. $scope.addItem = function () {
  107. var ctrl = $scope.tableOptions.getEditController();
  108. dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', null)
  109. .result.then(function (data) {
  110. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  111. $scope.tableOptions.onItemAdded(data);
  112. });
  113. };
  114. }
  115. };
  116. }
  117. ]);
  118. angular.module('luticateUtils').run(['$templateCache', function($templateCache)
  119. {
  120. $templateCache.put('/luticate/lutable.html',
  121. ' <lu-basic-table options="tableOptions"></lu-basic-table>' +
  122. '<div class="col-sm-12">' +
  123. ' <button class="btn btn-default" type="button" ng-click="deleteItems()"' +
  124. 'ng-disabled="tableOptions.checkedItems.length == 0" ng-show="tableOptions.canDel()">' +
  125. ' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete' +
  126. ' </button>' +
  127. ' <button class="btn btn-default" type="button" ng-click="addItem()" ng-show="tableOptions.canAdd()">' +
  128. ' <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
  129. ' </button>' +
  130. ' </div>');
  131. }]);