Procházet zdrojové kódy

More cleanup for show and tell

Lily Carpenter před 10 roky
rodič
revize
efb4e73f63

+ 52 - 52
twilio/app/assets/javascripts/messages.js

@@ -1,56 +1,56 @@
1 1
 (function () {
2
-    var app = angular.module('messages', ['restangular', 'templates']);
3
-
4
-    app.controller('MessagesController', function($scope, Restangular){
5
-        $scope.baseMessages = Restangular.all('messages');
6
-
7
-        $scope.baseMessages.refresh = function(){
8
-            $scope.baseMessages.getList().then(function(messages){
9
-                $scope.messages = messages;
10
-            })
11
-        };
12
-
13
-        $scope.baseMessages.remove = function(message){
14
-            message.remove();
2
+  var app = angular.module('messages', ['restangular', 'templates']);
3
+
4
+  app.controller('MessagesController', function($scope, Restangular){
5
+    $scope.baseMessages = Restangular.all('messages');
6
+
7
+    $scope.baseMessages.refresh = function(){
8
+      $scope.baseMessages.getList().then(function(messages){
9
+        $scope.messages = messages;
10
+      });
11
+    };
12
+
13
+    $scope.baseMessages.remove = function(message){
14
+      message.remove();
15
+      $scope.baseMessages.refresh();
16
+    };
17
+
18
+    $scope.baseMessages.refresh();
19
+
20
+  });
21
+
22
+  app.directive('messageForms', function(){
23
+    return {
24
+      restrict: "E",
25
+      templateUrl: 'message-forms.html'
26
+    };
27
+  });
28
+
29
+  app.controller('MessageController', function($scope, $timeout){
30
+    var timeout = null;
31
+    var debounceUpdate = function(new_message, old_message){
32
+      if(!new_message.id){
33
+        if($scope['message__form'].$valid){
34
+          if(timeout){
35
+            $timeout.cancel(timeout);
36
+          }
37
+          timeout = $timeout(function(){
38
+            $scope.baseMessages.post(new_message);
15 39
             $scope.baseMessages.refresh();
16
-        };
17
-
18
-        $scope.baseMessages.refresh();
19
-
20
-    });
21
-
22
-    app.directive('messageForms', function(){
23
-        return {
24
-            restrict: "E",
25
-            templateUrl: 'message-forms.html'
40
+          }, 1000);
26 41
         }
27
-    });
28
-
29
-    app.controller('MessageController', function($scope, $timeout){
30
-        var timeout = null;
31
-        var debounceUpdate = function(new_message, old_message){
32
-            if(!new_message.id){
33
-                if($scope['message__form'].$valid){
34
-                    if(timeout){
35
-                        $timeout.cancel(timeout);
36
-                    }
37
-                    timeout = $timeout(function(){
38
-                        $scope.baseMessages.post(new_message);
39
-                        $scope.baseMessages.refresh();
40
-                    }, 1000);
41
-                }
42
-
43
-                return;
44
-            }
45
-
46
-            if(new_message == old_message || $scope['message_' + new_message.id + '_form'].$invalid){
47
-                return;
48
-            }
49
-            if(timeout) {
50
-                $timeout.cancel(timeout);
51
-            }
52
-            timeout = $timeout(new_message.save, 1000);
53
-        };
54
-        $scope.$watchCollection('message', debounceUpdate);
55
-    });
42
+
43
+        return;
44
+      }
45
+
46
+      if(new_message == old_message || $scope['message_' + new_message.id + '_form'].$invalid){
47
+        return;
48
+      }
49
+      if(timeout) {
50
+        $timeout.cancel(timeout);
51
+      }
52
+      timeout = $timeout(new_message.save, 1000);
53
+    };
54
+    $scope.$watchCollection('message', debounceUpdate);
55
+  });
56 56
 })();

+ 39 - 0
twilio/app/assets/javascripts/templates/message-form.html

@@ -0,0 +1,39 @@
1
+<div class='message panel panel-default col-md-4' ng-controller='MessageController'>
2
+  <form novalidate name="message_{{message.id}}_form">
3
+    <div class='panel-heading text-center'><input placeholder="title" name="title" class="form-control" type="text" ng-model="message.title" required /></div>
4
+    <div class='panel-body'>
5
+      <span ng-show='message_{{message.id}}_form.title.$dirty && message_{{message.id}}_form.title.$invalid'>Invalid title</span>
6
+      <span ng-show='message_{{message.id}}_form.body.$dirty && message_{{message.id}}_form.body.$invalid'>Invalid body</span>
7
+      <span ng-show='message_{{message.id}}_form.secret.$dirty &&  message_{{message.id}}_form.secret.$invalid'>Invalid secret</span>
8
+      <div class='form-group'>
9
+        <label>Message Body <textarea placeholder="body" name="body" class="form-control" type="text" ng-model="message.body" required /></label>
10
+      </div>
11
+      <div class='form-group'>
12
+        <label>Message Secret <input placeholder="secret" name="secret" class="form-control" type="number" ng-model="message.secret" required /></label>
13
+      </div>
14
+      <div class='form-group' ng-show='message.created_at'>
15
+        <label>Created</label>
16
+        {{message.created_at | date:"short"}}
17
+      </div>
18
+      <div class='form-group' ng-show='message.updated_at'>
19
+        <label>Last Updated</label>
20
+        {{message.updated_at | date:"short"}}
21
+      </div>
22
+      <div class='form-group'>
23
+        <label>Disabled? <input class="form-control" type="checkbox" ng-model="message.disabled" /></label>
24
+      </div>
25
+      <div class='form-group'>
26
+        <button class="btn btn-default" ng-click="baseMessages.remove(message)" ng-show="message.id">Delete</button>
27
+      </div>
28
+      <div class='panel panel-default' ng-show='message.call_logs'>
29
+        <div class='panel-heading'>Call Logs</div>
30
+        <div class='panel-body'>
31
+          <div class='panel panel-default call_log' ng-repeat='log in message.call_logs'>
32
+            <div class='panel-heading'>{{log.number}}</div>
33
+            <div class='panel-body'>{{log.created_at | date:"short"}}</div>
34
+          </div>
35
+        </div>
36
+      </div>
37
+    </div>
38
+  </form>
39
+</div>

+ 0 - 27
twilio/app/assets/javascripts/templates/message-form.html.haml

@@ -1,27 +0,0 @@
1
-.message.panel.panel-default.col-md-4{"ng-controller" => "MessageController"}
2
-  %form{"novalidate" => true, "name"=>"message_{{message.id}}_form"}
3
-    .panel-heading.text-center <input placeholder="title" name="title" class="form-control" type="text" ng-model="message.title" required />
4
-    .panel-body
5
-      %span{"ng-show" => "message_{{message.id}}_form.title.$dirty && message_{{message.id}}_form.title.$invalid"} Invalid title
6
-      %span{"ng-show" => "message_{{message.id}}_form.body.$dirty && message_{{message.id}}_form.body.$invalid"} Invalid body
7
-      %span{"ng-show" => "message_{{message.id}}_form.secret.$dirty && message_{{message.id}}_form.secret.$invalid"} Invalid secret
8
-      .form-group
9
-        %label Message Body <textarea placeholder="body" name="body" class="form-control" type="text" ng-model="message.body" required />
10
-      .form-group
11
-        %label Message Secret <input placeholder="secret" name="secret" class="form-control" type="number" ng-model="message.secret" required />
12
-      .form-group{"ng-show" => "message.created_at"}
13
-        %label Created
14
-        {{message.created_at | date:"short"}}
15
-      .form-group{"ng-show" => "message.updated_at"}
16
-        %label Last Updated
17
-        {{message.updated_at | date:"short"}}
18
-      .form-group
19
-        %label Disabled? <input class="form-control" type="checkbox" ng-model="message.disabled" />
20
-      .form-group
21
-        <button class="btn btn-default" ng-click="baseMessages.remove(message)" ng-show="message.id">Delete</button>
22
-      .panel.panel-default{"ng-show" => "message.call_logs"}
23
-        .panel-heading Call Logs
24
-        .panel-body
25
-          .panel.panel-default.call_log{"ng-repeat" => "log in message.call_logs"}
26
-            .panel-heading {{log.number}}
27
-            .panel-body {{log.created_at | date:"short"}}

+ 3 - 0
twilio/app/assets/javascripts/templates/message-forms.html

@@ -0,0 +1,3 @@
1
+<div ng-repeat='message in messages'>
2
+  <ng-include src="'message-form.html'"></ng-include>
3
+</div>

+ 0 - 2
twilio/app/assets/javascripts/templates/message-forms.html.haml

@@ -1,2 +0,0 @@
1
-%div{"ng-repeat" => "message in messages"}
2
-  %ng-include{"src"=>"'message-form.html'"}