OSDN Git Service

Initial commit after detached from Eos base.
[eos/zephyr.git] / client / app / components / board / board.controller.js
1 'use strict';
2
3 angular.module('zephyrApp')
4 .controller('BoardController', function ($scope, $modal, Restangular, $state) {
5     $scope.commandDirectives = new Array()
6     $scope.openCommandModal = function() {
7         var modalInstance = $modal.open({
8             templateUrl: '/client/app/components/commandModal/commandModal.html',
9             controller: 'CommandModalController',
10             backdrop: true,
11             size: 'lg'
12         })
13         modalInstance.result.then(function(command) {
14             (function addCommandDirective() {
15                 var obj = {
16                     name: command,
17                     isCompleted: false
18                 }
19                 $scope.commandDirectives.push(obj)
20             })()
21         })
22     }
23     $scope.removeCommandDirective= function(index) {
24         $scope.commandDirectives.splice(index, 1)
25     }
26     $scope.save = function() {
27         $modal.open({
28             templateUrl: '/client/app/components/saveFileModal/saveFileModal.html',
29             controller: 'SaveFileModalController',
30             backdrop: true,
31             scope: $scope
32         })
33     }
34     $scope.$on('updateParams', function(event, index, params) {
35         $scope.commandDirectives[index].params = params
36         $scope.commandDirectives[index].isCompleted = true
37     })
38
39     var note = $state.params.id
40     if(note !== 'new') {
41         $scope.noteName = note
42         var baseNoteInfo = Restangular.all('/api/noteInfo/'+note)
43         baseNoteInfo.getList().then(function(commands) {
44             $scope.commands = commands 
45             commands.forEach(function(params) {
46                 var obj = {
47                     name: params.command,
48                     isCompleted: false,
49                 }
50                 $scope.commandDirectives.push(obj)
51             })
52         })
53         $scope.$on('requestParams', function(event, i) {
54             $scope.$broadcast('sendParams'+i, $scope.commands[i])
55         })
56     } else {
57         $scope.noteName = 'new note' 
58     }
59 });