github.com/sym3tri/etcd@v0.2.1-0.20140422215517-a563d82f95d6/mod/dashboard/app/page/browser/create-node-ctrl.js (about)

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