Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Created by robin on 11/3/15.
  3. */
  4. angular.module('luticateUtils')
  5. .directive('luEditTable', ['dialogs', 'luticateDialogErrorHelper',
  6. function(dialogs, luticateDialogErrorHelper) {
  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. $scope.tableOptions.canCheck = $scope.tableOptions.canDelete;
  43. $scope.tableOptions.canClick = $scope.tableOptions.canEdit;
  44. $scope.deleteItems = function () {
  45. if ($scope.tableOptions.checkedItems.length == 0) {
  46. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  47. return;
  48. }
  49. var promiseDelItems = {
  50. id: "promiseDelItems",
  51. loadGroups: [$scope.tableOptions.luBusy.group]
  52. };
  53. var item = $scope.tableOptions.checkedItems[0];
  54. $scope.tableOptions.getDelPromise(item, promiseDelItems)
  55. .then(function (data) {
  56. $scope.tableOptions.onItemDeleted(item, $scope);
  57. $scope.tableOptions.checkedItems.splice(0, 1);
  58. $scope.deleteItems();
  59. }, function (error) {
  60. luticateDialogErrorHelper.errorDialog(error)
  61. .result.then(function (data) {
  62. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  63. }, function (error) {
  64. });
  65. });
  66. };
  67. $scope.addItem = function () {
  68. var ctrl = $scope.tableOptions.getEditController();
  69. dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', null)
  70. .result.then(function (data) {
  71. $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
  72. $scope.tableOptions.onItemAdded(data);
  73. });
  74. };
  75. }
  76. };
  77. }
  78. ]);
  79. angular.module('luticateUtils').run(['$templateCache', function($templateCache)
  80. {
  81. $templateCache.put('/luticate/lutable.html',
  82. ' <lu-basic-table options="tableOptions"></lu-basic-table>' +
  83. '<div class="col-sm-12">' +
  84. ' <button class="btn btn-default" type="button" ng-click="deleteItems()"' +
  85. 'ng-disabled="tableOptions.checkedItems.length == 0" ng-show="tableOptions.canDelete()">' +
  86. ' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete' +
  87. ' </button>' +
  88. ' <button class="btn btn-default" type="button" ng-click="addItem()" ng-show="tableOptions.canAdd()">' +
  89. ' <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
  90. ' </button>' +
  91. ' </div>');
  92. }]);