create-node-ctrl.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. angular.module('etcd.page')
  3. .controller('CreateNodeCtrl', function($scope, $rootScope, $modalInstance, _,
  4. ETCD_EVENT, etcdApiSvc, pathSvc, key) {
  5. $scope.key = key;
  6. if (key === '/') {
  7. $scope.keyInputPrefix = '/';
  8. } else {
  9. $scope.keyInputPrefix = pathSvc.truncate(key, 20) + '/';
  10. }
  11. $scope.save = function(node) {
  12. $scope.requestPromise = etcdApiSvc.create(node)
  13. .then(function() {
  14. $rootScope.$broadcast(ETCD_EVENT.NODE_CHANGED, node);
  15. $modalInstance.close(node);
  16. });
  17. };
  18. $scope.cancel = function() {
  19. $modalInstance.dismiss('cancel');
  20. };
  21. });
  22. /**
  23. * Controller for the form. Must be different than the modal controller.
  24. */
  25. angular.module('etcd.page').controller('CreateNodeFormCtrl', function($scope, pathSvc) {
  26. $scope.fields = {
  27. key: '',
  28. value: '',
  29. type: 'key',
  30. ttl: null
  31. };
  32. $scope.submit = function() {
  33. var newNode = {};
  34. newNode.key = pathSvc.clean($scope.key + '/' + $scope.fields.key);
  35. newNode.dir = $scope.fields.type === 'dir';
  36. newNode.ttl = $scope.fields.ttl ? parseInt($scope.fields.ttl, 10) : null;
  37. if (!newNode.dir) {
  38. newNode.value = $scope.fields.value;
  39. }
  40. $scope.save(newNode);
  41. };
  42. });