split javascript out in separate file
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 11 Nov 2010 17:45:24 +0000 (18:45 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 11 Nov 2010 17:45:24 +0000 (18:45 +0100)
public/app/conference/registration.html
public/app/conference/registration.js [new file with mode: 0644]

index f727541..31a688b 100644 (file)
@@ -1,95 +1,11 @@
-<script>
-
-if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
-
-function Registration($resource){
-       this.master = {
-               person: {
-                       name: '', surname: '', inst: '', email: ''
-               },
-               type: 'participant',
-               work: {
-                       title: '',
-                       abstract: '',
-                       authors:[ { name:'', surname:'', inst:'', email:'' } ]
-               },
-               symposium: { organizers: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1 }
-       };
-       this.Registration = $resource( '/data/conference/Registration/:id', { id:'' } );
-       this.Symposium = $resource( '/data/conference/Symposium/:id', { id:'' } );
-       this.reset();
-       this.$watch('$location.hashPath', this.hash_change);
-}
-Registration.$inject=['$resource'];
-
-Registration.prototype = {
-       hash_change: function() {
-               var id = this.$location.hashPath;
-console.debug( 'hash_change', id, this.registration.$id );
-               if ( id != this.registration.$id ) {
-                       if (id) {
-                               var self = this;
-                               this.registration = this.Registration.get({ id: id }, function(registration) {
-                                       self.last_saved = angular.copy(registration);
-                                       if ( registration.type == 'symposium' ) {
-                                               var s_id = registration.symposium.$id || registration.$id;
-                                               // first registration doesn't have symposium.$id, but we used same $id
-console.debug( 'load symposium ', s_id );
-                                               self.symposium = self.Symposium.get({ id: s_id });
-                                       }
-                               });
-                       }
-                       else this.reset();
-               }
-       },
-       reset: function() {
-               console.debug( this.Registration );
-               var last = this.registration;
-               if ( last && last.type == 'symposium' ) {
-                       if ( last.$id ) last.symposium.work_nr++; // only if saved
-               }
-               this.registration = new this.Registration( this.master );
-               if ( last ) {
-                       this.registration.type      = last.type;
-                       this.registration.person    = last.person;
-
-                       if ( last.type == 'symposium' )
-                       this.registration.symposium = last.symposium;
-               }
-               this.last_saved = angular.copy( this.registration ); // FIXME was: {};
-console.debug( 'reset', this.registration, this.$location.hashPath, last );
-       },
-       save: function(){
-               var self = this;
-               this.registration.$save(function(registration){
-                       self.$location.hashPath = registration.$id;
-
-                       // save symposium to separate resource
-                       if ( registration.type == 'symposium' ) {
-                               if ( ! self.symposium ) { 
-                                       self.registration.symposium.$id = registration.$id; // reuse $id of first work for symposium
-                                       self.symposium = new self.Symposium( registration.symposium );
-                                       self.symposium.works = [];
-                               }
-                               registration.work.$id = registration.$id; // preserve $id
-                               self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work;
-console.debug('save_symposium', self.symposium );
-                               self.symposium.$save();
-                       }
-
-                       self.last_saved = angular.copy(registration);
-               });
-       }
-};
-
-angular.validator.max_length = function(input, len) {
-       var ok = input.length <= len;
-console.debug( 'max_length', ok, input.length, len );
-       return ok ? '' : 'must be shorter than '+len+' characters';
-}
-
-</script>
+<!DOCTYPE HTML>
+<html xmlns:ng="http://angularjs.org">
+<head>
+<meta charset="utf-8">
+<script src="angular.js" ng:autobind></script>
 
+<script src="registration.js"></script>
+<title>Conference registration</title>
 
 <style type="text/css">
 
@@ -301,6 +217,9 @@ hr {
 </style>
 
 
+</head>
+<body>
+
 
 <h1>Registration and Proposal Submission</h1>
 
@@ -543,3 +462,6 @@ symposium = {{symposium}}
 $id={{$id}}
 registration.$id={{registration.$id}}
 </pre>
+
+</body>
+</html>
diff --git a/public/app/conference/registration.js b/public/app/conference/registration.js
new file mode 100644 (file)
index 0000000..ceda744
--- /dev/null
@@ -0,0 +1,89 @@
+
+if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
+
+function Registration($resource){
+       this.master = {
+               person: {
+                       name: '', surname: '', inst: '', email: ''
+               },
+               type: 'participant',
+               work: {
+                       title: '',
+                       abstract: '',
+                       authors:[ { name:'', surname:'', inst:'', email:'' } ]
+               },
+               symposium: { organizers: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1 }
+       };
+       this.Registration = $resource( '/data/conference/Registration/:id', { id:'' } );
+       this.Symposium = $resource( '/data/conference/Symposium/:id', { id:'' } );
+       this.reset();
+       this.$watch('$location.hashPath', this.hash_change);
+}
+Registration.$inject=['$resource'];
+
+Registration.prototype = {
+       hash_change: function() {
+               var id = this.$location.hashPath;
+console.debug( 'hash_change', id, this.registration.$id );
+               if ( id != this.registration.$id ) {
+                       if (id) {
+                               var self = this;
+                               this.registration = this.Registration.get({ id: id }, function(registration) {
+                                       self.last_saved = angular.copy(registration);
+                                       if ( registration.type == 'symposium' ) {
+                                               var s_id = registration.symposium.$id || registration.$id;
+                                               // first registration doesn't have symposium.$id, but we used same $id
+console.debug( 'load symposium ', s_id );
+                                               self.symposium = self.Symposium.get({ id: s_id });
+                                       }
+                               });
+                       }
+                       else this.reset();
+               }
+       },
+       reset: function() {
+               console.debug( this.Registration );
+               var last = this.registration;
+               if ( last && last.type == 'symposium' ) {
+                       if ( last.$id ) last.symposium.work_nr++; // only if saved
+               }
+               this.registration = new this.Registration( this.master );
+               if ( last ) {
+                       this.registration.type      = last.type;
+                       this.registration.person    = last.person;
+
+                       if ( last.type == 'symposium' )
+                       this.registration.symposium = last.symposium;
+               }
+               this.last_saved = angular.copy( this.registration ); // FIXME was: {};
+console.debug( 'reset', this.registration, this.$location.hashPath, last );
+       },
+       save: function(){
+               var self = this;
+               this.registration.$save(function(registration){
+                       self.$location.hashPath = registration.$id;
+
+                       // save symposium to separate resource
+                       if ( registration.type == 'symposium' ) {
+                               if ( ! self.symposium ) { 
+                                       self.registration.symposium.$id = registration.$id; // reuse $id of first work for symposium
+                                       self.symposium = new self.Symposium( registration.symposium );
+                                       self.symposium.works = [];
+                               }
+                               registration.work.$id = registration.$id; // preserve $id
+                               self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work;
+console.debug('save_symposium', self.symposium );
+                               self.symposium.$save();
+                       }
+
+                       self.last_saved = angular.copy(registration);
+               });
+       }
+};
+
+angular.validator.max_length = function(input, len) {
+       var ok = input.length <= len;
+console.debug( 'max_length', ok, input.length, len );
+       return ok ? '' : 'must be shorter than '+len+' characters';
+}
+