PageRenderTime 66ms CodeModel.GetById 30ms RepoModel.GetById 0ms 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. window.Customer = Backbone.Model.extend({
  5. urlRoot: "bank/customers",
  6. initialize: function () {},
  7. defaults: {
  8. id: null,
  9. name: ""
  10. }
  11. });
  12. window.CustomerCollection = Backbone.Collection.extend({
  13. model: Customer,
  14. url: "bank/customers"
  15. });
  16. //******************************************
  17. //ACCOUNT
  18. //******************************************
  19. window.Account = Backbone.Model.extend({
  20. urlRoot: "bank/accounts",
  21. initialize: function () {
  22. this.validators = {};
  23. this.validators.accountNumber = function (value) {
  24. return value.length > 0 ? {isValid: true} : {isValid: false, message: "You must enter a account number"};
  25. };
  26. this.validators.accountNumber = function (value) {
  27. return value.length <= 12 ? {isValid: true} : {isValid: false, message: "Account number must be max 12 char lenght"};
  28. };
  29. this.validators.accountNumber = function (value) {
  30. return $.isNumeric(value) ? {isValid: true} : {isValid: false, message: "Account number must be numeric"};
  31. };
  32. this.validators.currency = function (value) {
  33. return $.trim(value) != '' ? {isValid: true} : {isValid: false, message: "Please select a Currency"};
  34. };
  35. },
  36. validateItem: function (key) {
  37. return (this.validators[key]) ? this.validators[key](this.get(key)) : {isValid: true};
  38. },
  39. // TODO: Implement Backbone's standard validate() method instead.
  40. validateAll: function () {
  41. var messages = {};
  42. for (var key in this.validators) {
  43. if(this.validators.hasOwnProperty(key)) {
  44. var check = this.validators[key](this.get(key));
  45. if (check.isValid === false) {
  46. messages[key] = check.message;
  47. }
  48. }
  49. }
  50. return _.size(messages) > 0 ? {isValid: false, messages: messages} : {isValid: true};
  51. },
  52. defaults: {
  53. id: null,
  54. accountNumber: "",
  55. customerId: "",
  56. iban: "",
  57. currency: "",
  58. balance: 0,
  59. accountBal: 0,
  60. accountDate: new Date()
  61. },
  62. parse:function (response) {
  63. //response.accountDate=new Date(response.accountDate);
  64. return response;
  65. }
  66. });
  67. window.AccountCollection = Backbone.Collection.extend({
  68. model: Account
  69. });
  70. //******************************************
  71. //MOVEMENT
  72. //******************************************
  73. window.Movement = Backbone.Model.extend({
  74. urlRoot: function(){
  75. return "bank/accounts/"+this.get("accountId")+"/movements";
  76. },
  77. initialize: function () {
  78. this.validators = {};
  79. this.validators.description = function (value) {
  80. return value.length > 0 ? {isValid: true} : {isValid: false, message: "You must enter a valid description"};
  81. };
  82. },
  83. validateItem: function (key) {
  84. return (this.validators[key]) ? this.validators[key](this.get(key)) : {isValid: true};
  85. },
  86. // TODO: Implement Backbone's standard validate() method instead.
  87. validateAll: function () {
  88. var messages = {};
  89. for (var key in this.validators) {
  90. if(this.validators.hasOwnProperty(key)) {
  91. var check = this.validators[key](this.get(key));
  92. if (check.isValid === false) {
  93. messages[key] = check.message;
  94. }
  95. }
  96. }
  97. return _.size(messages) > 0 ? {isValid: false, messages: messages} : {isValid: true};
  98. },
  99. defaults: {
  100. movementId:null,
  101. accountId:null,
  102. accountDate:new Date(),
  103. direction:0,
  104. amount:"",
  105. currency:"",
  106. recipient:"",
  107. dispDate:new Date(),
  108. description:"",
  109. type:"",
  110. state:"",
  111. sign:"",
  112. cross:false,
  113. minAccountBal:"",
  114. minAccountDate:"",
  115. maxAccountBal:"",
  116. maxAccountDate:""
  117. },
  118. parse:function (response) {
  119. //console.log(response);
  120. response.id=response.movementId;
  121. //response.accountDate=new Date(response.accountDate);
  122. //response.dispDate=new Date(response.dispDate);
  123. response.sign=(response.direction==0) ? '-' : "+";
  124. return response;
  125. }
  126. });
  127. window.MovementCollection = Backbone.Collection.extend({
  128. model: Movement
  129. });
  130. //******************************************
  131. //TASK
  132. //******************************************
  133. window.Task = Backbone.Model.extend({
  134. urlRoot: "asynch/processes",
  135. initialize: function () {},
  136. defaults: {
  137. taskId: null ,
  138. read: false ,
  139. result: "" ,
  140. important: false
  141. }
  142. });
  143. window.TaskCollection = Backbone.Collection.extend({
  144. model: Task,
  145. url: "asynch/processes"
  146. });