node-cog.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. angular.module('etcd.ui')
  3. .directive('edNodeCog', function($modal, $rootScope, etcdApiSvc, toastSvc,
  4. ETCD_EVENT) {
  5. return {
  6. templateUrl: '/ui/node-cog.html',
  7. restrict: 'E',
  8. replace: true,
  9. scope: {
  10. 'node': '='
  11. },
  12. controller: function($scope){
  13. function getDeleteMsg() {
  14. if ($scope.node.dir) {
  15. return 'Are you sure you want to delete the directory "' +
  16. $scope.node.key + '" and all of its keys?';
  17. }
  18. return 'Are you sure you ant to delete "' + $scope.node.key + '"';
  19. }
  20. // Options for both values and directories.
  21. $scope.cogDropdownOptions = [
  22. {
  23. label: 'View Details...',
  24. callback: function() {
  25. $modal.open({
  26. templateUrl: '/page/browser/node-info.html',
  27. controller: 'NodeInfoCtrl',
  28. resolve: {
  29. node: d3.functor($scope.node)
  30. }
  31. });
  32. },
  33. weight: 100
  34. },
  35. {
  36. label: 'Delete Node...',
  37. callback: function() {
  38. $modal.open({
  39. templateUrl: '/coreos.ui/confirm-modal/confirm-modal.html',
  40. controller: 'ConfirmModalCtrl',
  41. resolve: {
  42. title: d3.functor('Delete Node'),
  43. message: getDeleteMsg,
  44. btnText: d3.functor('Delete'),
  45. errorFormatter: d3.functor('etcdApi'),
  46. executeFn: _.identity.bind(null, function() {
  47. return etcdApiSvc.delete($scope.node)
  48. .then(function() {
  49. $rootScope.$broadcast(ETCD_EVENT.NODE_DELETED, $scope.node);
  50. });
  51. })
  52. }
  53. });
  54. },
  55. weight: 300
  56. }
  57. ];
  58. // Options for directories only.
  59. if ($scope.node.dir) {
  60. $scope.cogDropdownOptions.push({
  61. label: 'Modify TTL...',
  62. callback: function() {
  63. $modal.open({
  64. templateUrl: '/page/browser/edit-ttl.html',
  65. controller: 'EditTtlCtrl',
  66. resolve: {
  67. node: d3.functor($scope.node),
  68. }
  69. });
  70. },
  71. weight: 200
  72. });
  73. } else {
  74. // options for values only.
  75. $scope.cogDropdownOptions.push({
  76. label: 'Modify Node...',
  77. callback: function() {
  78. $modal.open({
  79. templateUrl: '/page/browser/edit-node.html',
  80. controller: 'EditNodeCtrl',
  81. resolve: {
  82. node: d3.functor($scope.node),
  83. }
  84. });
  85. },
  86. weight: 200
  87. });
  88. }
  89. }
  90. };
  91. });