PageRenderTime 45ms CodeModel.GetById 37ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/AktiveCortex/samples/aktivecortex-sample-bank/src/main/webapp/resources/js/models/models.js

https://bitbucket.org/aktivecortex/aktivecortex
JavaScript | 196 lines | 128 code | 50 blank | 18 comment | 7 complexity | 0be9c449b340362952ea9913e00416d3 MD5 | raw file
Possible License(s): Apache-2.0
  1//******************************************
  2//CUSTOMER
  3//******************************************
  4
  5window.Customer = Backbone.Model.extend({
  6	urlRoot: "bank/customers",
  7	initialize: function () {},
  8	defaults: {
  9    	id: null,
 10        name: ""        
 11    }
 12});
 13
 14window.CustomerCollection = Backbone.Collection.extend({
 15    model: Customer,
 16    url: "bank/customers"    
 17});
 18
 19
 20
 21
 22
 23//******************************************
 24//ACCOUNT
 25//******************************************
 26
 27window.Account = Backbone.Model.extend({
 28
 29    urlRoot: "bank/accounts",
 30
 31    initialize: function () {
 32        this.validators = {};
 33
 34        this.validators.accountNumber = function (value) {
 35            return value.length > 0 ? {isValid: true} : {isValid: false, message: "You must enter a account number"};
 36        };
 37        
 38        this.validators.accountNumber = function (value) {
 39            return value.length <= 12  ? {isValid: true} : {isValid: false, message: "Account number must be max 12 char lenght"};
 40        }; 
 41        
 42        this.validators.accountNumber = function (value) {
 43        	return $.isNumeric(value)  ? {isValid: true} : {isValid: false, message: "Account number must be numeric"};
 44        }; 
 45        
 46        this.validators.currency = function (value) {
 47        	return $.trim(value) != '' ? {isValid: true} : {isValid: false, message: "Please select a Currency"};
 48        };        
 49
 50    },
 51
 52    validateItem: function (key) {
 53        return (this.validators[key]) ? this.validators[key](this.get(key)) : {isValid: true};
 54    },
 55
 56    // TODO: Implement Backbone's standard validate() method instead.
 57    validateAll: function () {
 58
 59        var messages = {};
 60
 61        for (var key in this.validators) {
 62            if(this.validators.hasOwnProperty(key)) {
 63                var check = this.validators[key](this.get(key));
 64                if (check.isValid === false) {
 65                    messages[key] = check.message;
 66                }
 67            }
 68        }
 69
 70        return _.size(messages) > 0 ? {isValid: false, messages: messages} : {isValid: true};
 71    },
 72
 73    defaults: {
 74    	id: null,
 75        accountNumber: "",
 76        customerId: "",
 77        iban: "",
 78        currency: "",
 79        balance: 0,
 80        accountBal: 0,
 81        accountDate: new Date()        
 82    },
 83    
 84    parse:function (response) {
 85    	//response.accountDate=new Date(response.accountDate);
 86        return response;
 87    }
 88});
 89
 90window.AccountCollection = Backbone.Collection.extend({
 91    model: Account
 92});
 93
 94
 95
 96
 97
 98
 99//******************************************
100//MOVEMENT
101//******************************************
102
103window.Movement = Backbone.Model.extend({
104	urlRoot: function(){
105		return "bank/accounts/"+this.get("accountId")+"/movements";
106	},
107	
108		
109	initialize: function () {
110        this.validators = {};
111
112        this.validators.description = function (value) {
113            return value.length > 0 ? {isValid: true} : {isValid: false, message: "You must enter a valid description"};
114        };
115
116    },
117
118    validateItem: function (key) {
119        return (this.validators[key]) ? this.validators[key](this.get(key)) : {isValid: true};
120    },
121
122    // TODO: Implement Backbone's standard validate() method instead.
123    validateAll: function () {
124
125        var messages = {};
126
127        for (var key in this.validators) {
128            if(this.validators.hasOwnProperty(key)) {
129                var check = this.validators[key](this.get(key));
130                if (check.isValid === false) {
131                    messages[key] = check.message;
132                }
133            }
134        }
135
136        return _.size(messages) > 0 ? {isValid: false, messages: messages} : {isValid: true};
137    },
138	
139	
140	defaults: {
141		movementId:null,
142	    accountId:null,
143	    accountDate:new Date(),
144	    direction:0,
145	    amount:"",
146	    currency:"",
147	    recipient:"",
148	    dispDate:new Date(),
149	    description:"",
150	    type:"",
151	    state:"",
152	    sign:"",
153	    cross:false,
154	    minAccountBal:"",
155	    minAccountDate:"",
156	    maxAccountBal:"",
157	    maxAccountDate:""
158    },
159    parse:function (response) {
160        //console.log(response); 
161        response.id=response.movementId;
162        //response.accountDate=new Date(response.accountDate);
163        //response.dispDate=new Date(response.dispDate);
164        response.sign=(response.direction==0) ? '-' : "+";
165        return response;
166    }
167});
168
169window.MovementCollection = Backbone.Collection.extend({
170    model: Movement
171});
172
173
174
175
176
177//******************************************
178//TASK
179//******************************************
180
181window.Task = Backbone.Model.extend({
182	urlRoot: "asynch/processes",
183	initialize: function () {},
184	defaults: {
185    	taskId: 	null  ,
186    	read:		false ,
187    	result:		""    ,
188    	important:	false
189    }
190});
191
192window.TaskCollection = Backbone.Collection.extend({
193    model: Task,
194    url: "asynch/processes"
195});
196