'use strict'; /** * controller for angular-ckeditor */ app.controller("CkeditorCtrl", ["$scope", "toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", function ($scope, toaster, ngTableParams, $filter, apiPoint, $localStorage, $http, $state) { $scope.myModel = { "Heading": "", "description": "", "switchsetting": true }; /* * edit announcement details * created by Surendiran * */ $scope.editId = -1; $scope.setEditId = function (pid) { $scope.editId = pid; $scope.viewId = -1; }; /* * cancel edit div * created by Surendiran * */ $scope.cancel = function () { $scope.init(); $scope.editId = -1; }; // Editor options. $scope.options = { language: 'en', allowedContent: true, entities: false }; // Called when the editor is completely ready. $scope.onReady = function () { // ... // alert(); $scope.myModel.description console.log($scope.myModel.description); }; // $scope.submitForm = function() { // alert(JSON.stringify($scope.myModel.description)); // } $scope.announcementForm = { submit: function (form, myModel, loading) { var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$name; } if (form[field].$pristine) { form[field].$dirty = true; } } } angular.element('.ng-invalid[name=' + firstError + ']').focus(); // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); } else { $scope.ldloading1 = {}; $scope.ldloading1[loading.replace('-', '_')] = true; var addAnnouncement = { method: 'POST', url: apiPoint.url + 'addAnnouncementDetails/', headers: { 'Content-Type': 'application/json' }, data: { Heading: myModel.Heading, description: myModel.description, status: myModel.switchsetting, createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(addAnnouncement).then(function (response) { if (response.data.status == 200 && response.data.AnnouncementStatus) { $scope.ldloading1[loading.replace('-', '_')] = false; swal("", "Announcement added successfully.", "success"); $state.go($state.current, {}, { reload: true }); } else { $scope.ldloading1[loading.replace('-', '_')] = false; swal("", response.data.message, "error"); } }); } }, reset: function (form) { $scope.myModel = angular.copy($scope.master); form.$setPristine(true); $scope.myModel = { "Heading": "", "description": "", "switchsetting": true }; } }; /* * update the announcement details * created by Surendiran * */ $scope.updateAnnouncement = function (myModel, form, loading) { var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$stop_name; } if (form[field].$pristine) { form[field].$dirty = true; } } } angular.element('.ng-invalid[name=' + firstError + ']').focus(); } else { $scope.ldloading = {}; $scope.ldloading[loading.replace('-', '_')] = true; var update = { method: 'POST', url: apiPoint.url + 'updateAnnouncementDetails/', headers: { 'Content-Type': 'application/json' }, data: { Heading: myModel.Heading, description: myModel.description, status: myModel.IsActive, updateID: myModel.ID, createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(update).then(function (response) { if (response.data.status == 200 && response.data.AnnouncementStatus) { $scope.ldloading[loading.replace('-', '_')] = false; swal("","Updated successfully." , "success"); $scope.editId = -1; $scope.init(); } else { $scope.ldloading[loading.replace('-', '_')] = false; swal(" ", response.data.message, "error"); } }); } }; /* *get announcementForm details when page loading called from view file * * created by Surendiran * */ $scope.loader = ''; $scope.announcementInfo = ''; $scope.emptyData = ''; $scope.init = function () { var getAnnouncement = { method: 'POST', url: apiPoint.url + 'getAnnouncementDetails/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(getAnnouncement).then(function (response) { if (response.data.status == 200 && response.data.AnnouncementStatus) { $scope.emptyData = true; $scope.loader = true; $scope.data = response.data.details; } else { $scope.emptyData = false; $scope.loader = true; $scope.announcementInfo = ''; } }); }; }]);