Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.57 KB | None | 0 0
  1. (function () {
  2. appModule.controller("tenant.views.propertymanagement.tabs.commentForm", [
  3. "$scope", "$uibModal", "$window", "abp.services.app.propertyStatusContact", "abp.services.app.status",
  4. "abp.services.app.comment", function ($scope, $uibModal, $window, propertyStatusContactService, statusService, commentService) {
  5.  
  6. var vm = this;
  7. vm.saving = false;
  8. vm.property = {
  9. id: null
  10. };
  11. vm.statuses = [];
  12. vm.propertyStatusContacts = [];
  13. vm.comments = [];
  14. vm.comment = {
  15. id: null,
  16. date: new Date(),
  17. statusId: null,
  18. propertyStatusContactId: null,
  19. note: "",
  20. toNote: ""
  21. };
  22.  
  23. vm.resultNote = {};
  24. vm.opened = {};
  25.  
  26. //to get All Statuses
  27. vm.getAllStatuses = function () {
  28. statusService.getAllStatusesAsync().success(function (result) {
  29. vm.statuses = result.items;
  30. });
  31. };
  32.  
  33. vm.getAllStatuses();
  34.  
  35. //to get All Property Status Contacts
  36. vm.getAllPropertyStatusContacts = function () {
  37. propertyStatusContactService.getAllPropertyStatusContactsAsync().success(function (result) {
  38. vm.propertyStatusContacts = result.items;
  39. });
  40. };
  41.  
  42. vm.getAllPropertyStatusContacts();
  43.  
  44. //to check validity of the grid data entry
  45. vm.checkValidity = function (data) {
  46. if (!data) return app.localize("RequiredField");
  47. return null;
  48. };
  49.  
  50. //to open a calendar control
  51. vm.open = function ($event, elementOpened) {
  52. $event.preventDefault();
  53. $event.stopPropagation();
  54. vm.opened[elementOpened] = !vm.opened[elementOpened];
  55. };
  56.  
  57. //add comment
  58. vm.addComment = function () {
  59. vm.comments.push(vm.comment = {
  60. id: null,
  61. date: new Date(),
  62. note: "",
  63. toNote: ""
  64. });
  65. };
  66.  
  67. //cancel comment
  68. vm.cancelComment = function (form, index, data) {
  69. form.$cancel();
  70. if (!angular.isUndefined(data.oldNote)) {
  71. data.note = data.oldNote;
  72. }
  73. vm.resultNote.note = undefined;
  74. if (data.id == null) vm.comments.splice(index, 1);//to delete empty row
  75. };
  76.  
  77. //to save comment
  78. vm.saveComment = function (data, comment) {
  79. vm.property.id = $scope.propertyFormCtrl.property.id;
  80. if (vm.property.id != null && comment.id == null) { //create
  81. if (!angular.isUndefined(vm.resultNote.note) && vm.resultNote.note != '' && vm.resultNote.commentId == null) {
  82. data.note = vm.resultNote.note; //set the note from pop up
  83. } else {
  84. abp.notify.error(app.localize("CsNoteFieldIsRequired"));
  85. return;
  86. }
  87. createOrEditComment(data, null);
  88. } else if (vm.property.id != null && comment.id != null) { //edit
  89. if (vm.resultNote.commentId == comment.id) { //to pick the correct note on edit scenario
  90. data.note = vm.resultNote.note; //set the note from pop up
  91. comment.note = vm.resultNote.note;
  92. } else {
  93. data.note = comment.note;
  94. }
  95. createOrEditComment(data, comment.id);
  96. } else {
  97. abp.notify.error(app.localize("CreatePropertyFirst"));
  98. vm.comments = [];
  99. }
  100. };
  101.  
  102. //to save comment
  103. function createOrEditComment(data, commentId) {
  104. vm.comment.id = commentId;
  105. vm.comment.date = data.date;
  106. vm.comment.statusName = data.statusName;
  107. vm.comment.propertyStatusContactName = data.propertyStatusContactName;
  108. vm.comment.note = data.note;
  109. vm.comment.commentId = vm.comment.id;
  110. vm.comment.propertyId = vm.property.id;
  111. vm.comment.isEmailSent = data.isEmailSent;
  112. vm.comment.toNote = data.toNote;
  113.  
  114. commentService.createOrEditCommentAsync({ comment: vm.comment }).success(function (result) {
  115. vm.comment.id = result;
  116. if (!vm.comment.isEmailSent) abp.notify.info(app.localize("SavedSuccessfully"));
  117. vm.resultNote.note = undefined;
  118. }).finally(function () {
  119. });
  120. }
  121.  
  122. //to send email
  123. vm.composeEmail = function (data) {
  124. $window.location.href = vm.email(data);
  125. data.isEmailSent = true;
  126. if (vm.property.id != null && data.id != null) { //edit
  127. createOrEditComment(data, data.id);
  128. }
  129. };
  130.  
  131. //to create task
  132. vm.task = function (data) {
  133. $window.location.href = vm.email(data);
  134. };
  135.  
  136. //to return email details
  137. vm.email = function (data) {
  138. var email = "mailto:?subject=" + $scope.propertyFormCtrl.property.address.streetNumber + ", " + $scope.propertyFormCtrl.property.address.streetName + " " +
  139. $scope.propertyFormCtrl.cityName + " " + $scope.propertyFormCtrl.stateName + " " + "IPL# " + $scope.propertyFormCtrl.property.id + "&body=" + data.note;
  140. return email;
  141. };
  142.  
  143. //note pop up
  144. vm.note = function (comment, form) {
  145. vm.resultNote.form = form;
  146. if (angular.isUndefined(vm.resultNote.note)) vm.resultNote.note = comment.note;
  147. vm.resultNote.commentId = comment.id;
  148. vm.openNoteModal(vm.resultNote, comment);
  149. };
  150.  
  151. //note pop up
  152. vm.openNoteModal = function (resultNote, comment) {
  153. $uibModal.open({
  154. templateUrl: "~/App/tenant/views/propertymanagement/templates/noteModal.cshtml",
  155. controller: "tenant.views.propertymanagement.tabs.templates.noteModal as vm",
  156. backdrop: "static",
  157. resolve: {
  158. resultNote: function () {
  159. return resultNote;
  160. }
  161. }
  162. }).result.then(function (result) {
  163. vm.resultNote = result;
  164. var oldNote = comment.note;
  165. comment.oldNote = oldNote;
  166. comment.note = result.note;
  167. });
  168. };
  169.  
  170.  
  171. // initialize method
  172. vm.init = function () {
  173. vm.property.id = $scope.propertyFormCtrl.property.id;
  174.  
  175. commentService.getCommentsForEditAsync({
  176. id: vm.property.id
  177. }).success(function (result) {
  178. vm.comments = [];
  179. _.each(result.comments, function (c) { //to convert 'string date' to 'js date object'
  180. c.date = new Date(c.date);
  181. vm.comments.push(c);
  182. });
  183. });
  184. };
  185.  
  186. vm.init();//this must be the last method call on this js file
  187. }
  188. ]);
  189. })();
Add Comment
Please, Sign In to add comment