Guest User

Untitled

a guest
Sep 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. var fake = {};
  2. fake.dl = function (fn, r) { setTimeout(function () { fn(r); }, 200); };
  3.  
  4. app.sds = (function () {
  5.  
  6. // on error
  7. onE = function (efn, e) {
  8. e = e || "";
  9. if (console && console.log) { console.log("error " + e); }
  10. if (efn) { efn(e); }
  11. };
  12.  
  13. function postit(commandName, data, fn, donotRefresh){
  14. $.ajax({
  15. url: "/c/"+app.currentPortfolio.portfolioId+commandName,
  16. type: "POST",
  17. data: JSON.stringify(data),
  18. contentType: "application/json",
  19. success: function(){
  20. // refresh the main model
  21. alert('success');
  22. // if(!donotRefresh){
  23. // self.views.getPortfolioView(fn);
  24. // }else{
  25. // fn();
  26. // }
  27. },
  28. error: function (res) {
  29. alert('fail');
  30. // app.logger.log(res);
  31. }
  32. });
  33. }
  34.  
  35.  
  36. var self = {
  37.  
  38. saveQuickStartWizard: function (qprop, success, error) {
  39. postit("/wizards/quickStart", qprop, function(res){
  40. success(res);
  41. });
  42. },
  43.  
  44. // not done
  45. //////////////////////////////////////////////////
  46.  
  47.  
  48. createMessage: function (messageData, success, error) {
  49. postit("/messaging/createMessage", messageData, function (res) {
  50. app.sds.messages = undefined;
  51. success(res);
  52. });
  53. },
  54.  
  55. addMessageComment: function (commentData, success, error) {
  56. postit("/messaging/addMessageComment", commentData, function(res) {
  57. app.sds.messages = undefined;
  58. success(res);
  59. });
  60. },
  61.  
  62. addShare: function (shareData, success, error) {
  63. postit("/portfolio/addShare", shareData, function(res) {
  64. success(res);
  65. });
  66. },
  67.  
  68. updatePortfolio: function (portfolioData, success, error) {
  69. postit("/portfolio/update", portfolioData, function(res) {
  70. success(res);
  71. });
  72. },
  73.  
  74. saveManualIncome: function(incCmd, success, error){
  75. postit("/income/recordManualsIncome", incCmd, function(res){
  76. success(res);
  77. }, true /*skip refresh*/);
  78. },
  79.  
  80. saveBillIncome: function(incomeFromBillsModel, success, error){
  81. postit("/income/recordBillsIncome", incomeFromBillsModel, function(res){
  82. success(res);
  83. }, true /*skip refresh*/);
  84. },
  85.  
  86. createExpense: function (expense, success, error) {
  87. postit("/expense/record", expense, function(res){
  88. success(res);
  89. }, true /*skip refresh*/);
  90. },
  91.  
  92. createTenant: function (tenant, success, error) {
  93. postit("/tenant/create", tenant, function(res){
  94. success(res);
  95. });
  96. },
  97.  
  98. createUnit: function (unit, success, error) {
  99. postit("/unit/create", unit, function(res){
  100. success(res);
  101. });
  102. },
  103.  
  104. saveUnit: function(unit, success, error){
  105. // TODO: need to hook sds#saveUnit to backend
  106. success();
  107. },
  108.  
  109. createProperty: function (prop, success, error){
  110. postit("/property/create", prop, function(res){
  111. success(res);
  112. });
  113. },
  114.  
  115. saveProperty: function(prop, success, error){
  116. // TODO: need to hook sds#saveProperty to backend
  117. success();
  118. },
  119.  
  120. saveTenant: function (tenant, success, error) {
  121. // TODO: need to hook sds#saveTenant to backend
  122. fake.dl(success, null, error);
  123. },
  124.  
  125. createRentalBill: function(rentalBill, success, error){
  126. // TODO: need to hook sds#createRentalBill to backend
  127. fake.dl(success, null, error);
  128. },
  129.  
  130. saveRentalBill : function (rentalBill, success, error) { fake.dl(success, null, error); },
  131. deactivateBill : function (id, success, error) { fake.dl(success, null, error); },
  132. //
  133. editTransaction: function (transaction, success, error) {
  134. // expect back a transaction view item
  135. var newTransactionView = transaction;
  136. fake.dl(function () { success(newTransactionView); }, null, error);
  137. },
  138.  
  139. createPortfolio: function (portfolioData, success, error) {
  140. postit("/portfolio/create", portfolioData, function(res) {
  141. success(res);
  142. });
  143. }
  144. };
  145. return self;
  146. } ());
Add Comment
Please, Sign In to add comment