Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- appModule.controller("tenant.views.propertymanagement.tabs.commentForm", [
- "$scope", "$uibModal", "$window", "abp.services.app.propertyStatusContact", "abp.services.app.status",
- "abp.services.app.comment", function ($scope, $uibModal, $window, propertyStatusContactService, statusService, commentService) {
- var vm = this;
- vm.saving = false;
- vm.property = {
- id: null
- };
- vm.statuses = [];
- vm.propertyStatusContacts = [];
- vm.comments = [];
- vm.comment = {
- id: null,
- date: new Date(),
- statusId: null,
- propertyStatusContactId: null,
- note: "",
- toNote: ""
- };
- vm.resultNote = {};
- vm.opened = {};
- //to get All Statuses
- vm.getAllStatuses = function () {
- statusService.getAllStatusesAsync().success(function (result) {
- vm.statuses = result.items;
- });
- };
- vm.getAllStatuses();
- //to get All Property Status Contacts
- vm.getAllPropertyStatusContacts = function () {
- propertyStatusContactService.getAllPropertyStatusContactsAsync().success(function (result) {
- vm.propertyStatusContacts = result.items;
- });
- };
- vm.getAllPropertyStatusContacts();
- //to check validity of the grid data entry
- vm.checkValidity = function (data) {
- if (!data) return app.localize("RequiredField");
- return null;
- };
- //to open a calendar control
- vm.open = function ($event, elementOpened) {
- $event.preventDefault();
- $event.stopPropagation();
- vm.opened[elementOpened] = !vm.opened[elementOpened];
- };
- //add comment
- vm.addComment = function () {
- vm.comments.push(vm.comment = {
- id: null,
- date: new Date(),
- note: "",
- toNote: ""
- });
- };
- //cancel comment
- vm.cancelComment = function (form, index, data) {
- form.$cancel();
- if (!angular.isUndefined(data.oldNote)) {
- data.note = data.oldNote;
- }
- vm.resultNote.note = undefined;
- if (data.id == null) vm.comments.splice(index, 1);//to delete empty row
- };
- //to save comment
- vm.saveComment = function (data, comment) {
- vm.property.id = $scope.propertyFormCtrl.property.id;
- if (vm.property.id != null && comment.id == null) { //create
- if (!angular.isUndefined(vm.resultNote.note) && vm.resultNote.note != '' && vm.resultNote.commentId == null) {
- data.note = vm.resultNote.note; //set the note from pop up
- } else {
- abp.notify.error(app.localize("CsNoteFieldIsRequired"));
- return;
- }
- createOrEditComment(data, null);
- } else if (vm.property.id != null && comment.id != null) { //edit
- if (vm.resultNote.commentId == comment.id) { //to pick the correct note on edit scenario
- data.note = vm.resultNote.note; //set the note from pop up
- comment.note = vm.resultNote.note;
- } else {
- data.note = comment.note;
- }
- createOrEditComment(data, comment.id);
- } else {
- abp.notify.error(app.localize("CreatePropertyFirst"));
- vm.comments = [];
- }
- };
- //to save comment
- function createOrEditComment(data, commentId) {
- vm.comment.id = commentId;
- vm.comment.date = data.date;
- vm.comment.statusName = data.statusName;
- vm.comment.propertyStatusContactName = data.propertyStatusContactName;
- vm.comment.note = data.note;
- vm.comment.commentId = vm.comment.id;
- vm.comment.propertyId = vm.property.id;
- vm.comment.isEmailSent = data.isEmailSent;
- vm.comment.toNote = data.toNote;
- commentService.createOrEditCommentAsync({ comment: vm.comment }).success(function (result) {
- vm.comment.id = result;
- if (!vm.comment.isEmailSent) abp.notify.info(app.localize("SavedSuccessfully"));
- vm.resultNote.note = undefined;
- }).finally(function () {
- });
- }
- //to send email
- vm.composeEmail = function (data) {
- $window.location.href = vm.email(data);
- data.isEmailSent = true;
- if (vm.property.id != null && data.id != null) { //edit
- createOrEditComment(data, data.id);
- }
- };
- //to create task
- vm.task = function (data) {
- $window.location.href = vm.email(data);
- };
- //to return email details
- vm.email = function (data) {
- var email = "mailto:?subject=" + $scope.propertyFormCtrl.property.address.streetNumber + ", " + $scope.propertyFormCtrl.property.address.streetName + " " +
- $scope.propertyFormCtrl.cityName + " " + $scope.propertyFormCtrl.stateName + " " + "IPL# " + $scope.propertyFormCtrl.property.id + "&body=" + data.note;
- return email;
- };
- //note pop up
- vm.note = function (comment, form) {
- vm.resultNote.form = form;
- if (angular.isUndefined(vm.resultNote.note)) vm.resultNote.note = comment.note;
- vm.resultNote.commentId = comment.id;
- vm.openNoteModal(vm.resultNote, comment);
- };
- //note pop up
- vm.openNoteModal = function (resultNote, comment) {
- $uibModal.open({
- templateUrl: "~/App/tenant/views/propertymanagement/templates/noteModal.cshtml",
- controller: "tenant.views.propertymanagement.tabs.templates.noteModal as vm",
- backdrop: "static",
- resolve: {
- resultNote: function () {
- return resultNote;
- }
- }
- }).result.then(function (result) {
- vm.resultNote = result;
- var oldNote = comment.note;
- comment.oldNote = oldNote;
- comment.note = result.note;
- });
- };
- // initialize method
- vm.init = function () {
- vm.property.id = $scope.propertyFormCtrl.property.id;
- commentService.getCommentsForEditAsync({
- id: vm.property.id
- }).success(function (result) {
- vm.comments = [];
- _.each(result.comments, function (c) { //to convert 'string date' to 'js date object'
- c.date = new Date(c.date);
- vm.comments.push(c);
- });
- });
- };
- vm.init();//this must be the last method call on this js file
- }
- ]);
- })();
Add Comment
Please, Sign In to add comment