edit-node-ctrl.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. angular.module('etcd.page')
  3. .controller('EditNodeCtrl', function($scope, $rootScope, $modalInstance, _,
  4. ETCD_EVENT, etcdApiSvc, pathSvc, node) {
  5. $scope.node = node;
  6. $scope.displayKey = pathSvc.truncate(node.key, 50) + '/'
  7. $scope.save = function(node) {
  8. $scope.requestPromise = etcdApiSvc.save(node)
  9. .then(function() {
  10. $rootScope.$broadcast(ETCD_EVENT.NODE_CHANGED, node);
  11. $modalInstance.close(node);
  12. });
  13. };
  14. $scope.cancel = function() {
  15. $modalInstance.dismiss('cancel');
  16. };
  17. });
  18. /**
  19. * Controller for the form. Must be different than the modal controller.
  20. */
  21. angular.module('etcd.page').controller('EditNodeFormCtrl', function($scope, pathSvc) {
  22. $scope.fields = {
  23. value: $scope.node.value || '',
  24. ttl: $scope.node.ttl || ''
  25. };
  26. $scope.submit = function() {
  27. var editNode = {
  28. key: $scope.node.key,
  29. value: $scope.fields.value,
  30. ttl: $scope.fields.ttl ? parseInt($scope.fields.ttl, 10) : null
  31. };
  32. $scope.save(editNode);
  33. };
  34. });