Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ErrorConnectionCtrl($scope, $rootScope, $location, WebServices, pendingRequests,storage,Idle){
- $scope.Reloading = function(){
- pendingRequests.cancelAll();
- WebServices.Account.cekToken().then(function(result){
- result = result.data;
- if(result.status == "Not Found" || result.status == "Error"){
- storage.set('userProfile','');
- storage.set('userToken','');
- storage.set('fileList','');
- storage.set('changedIndex',-1);
- Idle.unwatch();
- $location.path('/login').replace();
- }else{
- Idle.watch();
- storage.set('idle',storage.get('ngIdle.expiry').time);
- $location.path('/listcase').replace();
- }
- },function(){
- Materialize.toast('Please check the connection.',2000);
- });
- }
- }
- function LoginCtrl($scope, $rootScope, $routeParams,$http,WebServices,storage,$location, Idle) {
- $scope.$on('$routeChangeSuccess', function () {
- $('#sidenav-overlay').remove();
- $scope.doLogin = function(){
- WebServices.Account.Login($scope.LoginInput).then(function(result){
- result = result.data;
- if(result.status == "Success"){
- storage.set("loginInput",$scope.LoginInput.email);
- storage.set("userToken",result.Token);
- storage.set("userProfile",result.result[0]);
- var dataUser = storage.get('userProfile');
- var userGuid=dataUser.id;
- var userDepartmentGuid=dataUser.departmentUser.guid;
- var roleValues = dataUser.position;
- var groupPhases = dataUser.notifGroupPhase;
- /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
- window.plugins.parselogin.updateParseObject(param,function(){
- },function(){
- });*/
- Idle.watch();
- storage.set('idle',storage.get('ngIdle.expiry').time);
- $location.path('/listcase').replace();
- }else{
- Materialize.toast(result.errMsg, 2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- });
- }
- function BlockedCtrl($scope, $rootScope, $routeParams,$http,WebServices,storage,$location, Idle, $timeout) {
- $scope.LoginInput = {
- email : storage.get('userProfile').primaryEmail,
- passwd : '',
- userguid : storage.get('userProfile').id
- };
- $scope.signOut = function(){
- WebServices.Account.Logout().then(function(result){
- storage.set('userProfile','');
- storage.set('userToken','');
- storage.set('hasExecuted','');
- storage.set('fileList','');
- storage.set('currentDetail','');
- storage.set('changedIndex',-1);
- var userGuid="";
- var userDepartmentGuid="";
- var roleValues = "";
- var groupPhases = [];
- /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
- window.plugins.parselogin.updateParseObject(param,function(){
- },function(){
- });*/
- Idle.unwatch();
- $location.path('/login').replace();
- },function(){
- Materialize.toast('Error connection.',2000);
- });
- }
- $scope.username = angular.isUndefined(storage.get("loginInput")) || storage.get("loginInput") == '' ? '' : storage.get('userProfile').primaryEmail;
- $scope.$on('$routeChangeSuccess', function () {
- $('#sidenav-overlay').remove();
- $scope.doLogin = function(){
- WebServices.Account.CheckUserSessionV2($scope.LoginInput).then(function(result){
- result = result.data;
- if(result.status == "Success"){
- storage.set('userProfile',result.result);
- var dataUser = storage.get('userProfile');
- var userGuid=dataUser.id;
- var userDepartmentGuid=dataUser.departmentUser.guid;
- var roleValues = dataUser.position;
- var groupPhases = dataUser.notifGroupPhase;
- /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
- window.plugins.parselogin.updateParseObject(param,function(){
- },function(){
- });*/
- Idle.watch();
- storage.set('idle',storage.get('ngIdle.expiry').time);
- if(result.totalUnreadNotif > 0){
- $location.path('/notificationlist').replace();
- }else{
- var redirectUrl = storage.get('redirectUrl');
- if(!angular.isUndefined(redirectUrl)){
- storage.set('redirectUrl','');
- $location.path(redirectUrl).replace();
- }
- else $location.path('/listcase').replace();
- }
- }else{
- /*storage.set('userProfile','');
- storage.set('userToken','');
- storage.set('hasExecuted','');
- storage.set('fileList','');
- storage.set('changedIndex',-1);
- storage.set('redirectUrl',$location.url());
- Idle.unwatch();
- var userGuid="";
- var userDepartmentGuid="";
- var roleValues = "";
- var groupPhases = [];
- var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
- window.plugins.parselogin.updateParseObject(param,function(){
- },function(){
- });
- $location.path("/login").replace();*/
- Material.toast("Invalid password",2000);
- Idle.unwatch();
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- });
- }
- function MyProfileCtrl($scope, $rootScope, WebServices,storage, retrieveProfile, $location, Idle){
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.$on('$routeChangeSuccess', function () {
- storage.set('userProfile',retrieveProfile.data.result);
- $('#sidenav-overlay').remove();
- $scope.user = storage.get('userProfile');
- $scope.cancelChangePassword = function(){
- $scope.editpasswordmode=false;
- $scope.password = "";
- $scope.newpassword = "";
- $scope.oldpassword = "";
- }
- $scope.saveChangePassword = function(){
- $scope.editpasswordmode = false;
- WebServices.Account.ChangePassword({
- form : {
- email : $scope.user.primaryEmail,
- oldPasswd : $scope.oldpassword,
- newPasswd : $scope.newpassword
- }
- }).then(function(result){
- var result = result.data;
- if(result.status === "Success"){
- $scope.oldpassword = "";
- $scope.password = "";
- $scope.newpassword = "";
- Materialize.toast("Your password has been succesfully changed!", 2000);
- WebServices.Account.Logout().then(function(result){
- storage.set('userProfile','');
- storage.set('userToken','');
- storage.set('hasExecuted','');
- storage.set('fileList','');
- storage.set('currentDetail','');
- storage.set('changedIndex',-1);
- var userGuid="";
- var userDepartmentGuid="";
- var roleValues = "";
- var groupPhases = [];
- /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
- window.plugins.parselogin.updateParseObject(param,function(){
- },function(){
- });*/
- Idle.unwatch();
- $location.path('/login').replace();
- },function(){
- Materialize.toast('Error connection.',2000);
- });
- }else{
- Materialize.toast("Fail to change password.", 2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- });
- }
- function ListCaseCtrl($scope, $rootScope, $routeParams, WebServices, Incident,storage, $location,pendingRequests, $filter, $timeout, Idle){
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.$on('$routeChangeSuccess', function () {
- $('.button-collapse').sideNav();
- $('#sidenav-overlay').remove();
- $('ul.tabs').tabs();
- $scope.openInputCaseForm = function(){
- storage.set('dataInputCase','');
- $location.path('/inputcase').replace();
- }
- $scope.order = function(predicate) {
- $timeout(function(){
- $scope.$apply(function(){
- $scope.predicate = predicate;
- var value = $scope.currentActive;
- var sort = predicate == "-priorityVal" ? "Sorting case by priority" : "Sorting case by created on";
- window.plugins.toast.show(sort, 'short', 'bottom',
- function(a){
- },
- function(b){
- });
- $scope.reLoadListByOrder();
- /*
- switch(value){
- case 'all' :
- //$scope.incidentList = $filter('orderBy')($scope.incidentList, $scope.predicate);
- break;
- case 'mycase' :
- //$scope.mycaseList = $filter('orderBy')($scope.mycaseList, $scope.predicate)
- break;
- case 'outstanding' :
- //$scope.outstandingList = $filter('orderBy')($scope.outstandingList, $scope.predicate)
- break;
- }*/
- });
- })
- };
- $scope.currentActive = 'all';
- $scope.busyLoading = false;
- $scope.notFoundCase = false;
- $scope.totalAllCaseList = 0;
- $scope.totalMyCaseList = 0;
- $scope.totalOutstandingList = 0;
- $scope.checkIfOutdated = function(value){
- var a = moment();
- var b = moment(value);
- if(a.diff(b) > 0) return true;
- else return false;
- }
- $scope.checkNewVersion = function(){
- Materialize.toast("SQA is checking update..",2000);
- var oldVersion = storage.get('sqaVersion');
- WebServices.SQA.checkingNewVersion(oldVersion).then(function(result){
- var result = result.data;
- Materialize.toast(result.message,2000);
- if(result.status == "Update"){
- //calling download java
- storage.set('sqaVersion',result.result)
- }
- },function(){
- Materialize.toast('Fail to check new version, please check the connection.',2000);
- });
- }
- $scope.sameDepartment = function(value){
- var userDepartment = storage.get('userProfile').departmentUser.guid;
- if(value != userDepartment) return true;
- else return false;
- }
- $scope.signOut = function(){
- WebServices.Account.Logout().then(function(result){
- storage.set('userProfile','');
- storage.set('userToken','');
- storage.set('hasExecuted','');
- storage.set('fileList','');
- storage.set('currentDetail','');
- storage.set('changedIndex',-1);
- /*var userGuid="";
- var userDepartmentGuid="";
- var roleValues = "";
- var groupPhases = [];
- var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
- window.plugins.parselogin.updateParseObject(param,function(){
- },function(){
- });*/
- Idle.unwatch();
- $location.path('/login').replace();
- },function(){
- Materialize.toast('Error connection.',2000);
- });
- }
- $scope.isInfiniteScrollDisabled = false;
- $scope.currentPage = 0;
- $scope.incidentList = [];
- $scope.fromNow = function(value){
- var today = moment().format("DD/MM/YYYY");
- if(today == value)return "Today";
- else return moment(value,"DD/MM/YYYY").fromNow();
- }
- $scope.getTimePart = function(value){
- return moment(value).format("DD/MM/YYYY HH:mm");
- }
- $scope.loadDetail = function(value){
- var currentDetail = [];
- currentDetail.push(value);
- WebServices.Incident.GetDetailListV2({
- guid : value.caseid,
- ownerid : storage.get('userProfile').id
- }).then(function(result){
- var result = result.data;
- if(result.status == "Success"){
- $scope.incidentList = [];
- $scope.tempIncidentList = [];
- $scope.outstandingList = [];
- $scope.mycaseList = [];
- $scope.currentPage = 0;
- $scope.totalAllCaseList = 0;
- $scope.totalMyCaseList = 0;
- $scope.totalOutstandingList = 0;
- $scope.isInfiniteScrollDisabled = false;
- $scope.predicate = '-priorityVal';
- storage.set('currentDetail',result.result);
- storage.set('redirectUrl','/listcase');
- $location.path('/detailcase').replace();
- }else{
- Materialize.toast('Detail Case not found',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- $scope.reLoadListByOrder = function(){
- $scope.incidentList = [];
- $scope.outstandingList = [];
- $scope.mycaseList = [];
- $scope.tempIncidentList = [];
- $scope.currentPage = 0;
- $scope.totalAllCaseList = 0;
- $scope.totalMyCaseList = 0;
- $scope.totalOutstandingList = 0;
- $scope.isInfiniteScrollDisabled = false;
- $scope.loadCase();
- }
- $scope.reLoadList = function(){
- $scope.incidentList = [];
- $scope.outstandingList = [];
- $scope.mycaseList = [];
- $scope.tempIncidentList = [];
- $scope.currentPage = 0;
- $scope.totalAllCaseList = 0;
- $scope.totalMyCaseList = 0;
- $scope.totalOutstandingList = 0;
- $scope.isInfiniteScrollDisabled = false;
- $scope.predicate = '-priorityVal';
- $scope.loadCase();
- }
- var userData = storage.get('userProfile');
- $scope.loadListType = function(value){
- $scope.currentActive = value;
- pendingRequests.cancelAll();
- $scope.reLoadList();
- }
- $scope.loadCase = function(){
- var value = $scope.currentActive;
- WebServices.Incident.GetAllCase({
- startpos : $scope.tempIncidentList.length == 0 ? 0 : $scope.currentPage,
- ownerCase : storage.get('userProfile').id,
- typeSort : $scope.predicate == "-priorityVal" ? 2 : 1,
- },value).then(function(result){
- if(result.status== "Success"){
- switch(value){
- case 'all' :
- if($scope.tempIncidentList.length == 0){
- $scope.tempIncidentList = result.result;
- //$scope.incidentList = result.result;
- }else{
- angular.forEach(result.result, function(item) {
- item.createdOn = new Date(item.createdOn);
- $scope.tempIncidentList.push(item);
- //$scope.incidentList.push(item);
- });
- }
- if($scope.currentPage == 0){
- $scope.totalAllCaseList = result.totalcase;
- }
- $scope.incidentList = $scope.tempIncidentList;//$filter('orderBy')($scope.tempIncidentList, $scope.predicate);
- break;
- case 'mycase' :
- /*if($scope.mycaseList.length == 0){
- $scope.mycaseList = result.result;
- }else{
- angular.forEach(result.result, function(item) {
- item.createdOn = new Date(item.createdOn);
- $scope.mycaseList.push(item);
- });
- }
- if($scope.currentPage == 0){
- $scope.totalMyCaseList = result.totalcase;
- $scope.mycaseList = $filter('orderBy')($scope.mycaseList, $scope.predicate);
- }
- */
- if($scope.tempIncidentList.length == 0){
- $scope.tempIncidentList = result.result;
- //$scope.incidentList = result.result;
- }else{
- angular.forEach(result.result, function(item) {
- item.createdOn = new Date(item.createdOn);
- $scope.tempIncidentList.push(item);
- //$scope.incidentList.push(item);
- });
- }
- if($scope.currentPage == 0){
- $scope.totalMyCaseList = result.totalcase;
- }
- $scope.mycaseList = $scope.tempIncidentList;//$filter('orderBy')($scope.tempIncidentList, $scope.predicate);
- break;
- case 'outstanding' :
- /*if($scope.outstandingList.length == 0){
- $scope.outstandingList = result.result;
- }else{
- angular.forEach(result.result, function(item) {
- item.createdOn = new Date(item.createdOn);
- $scope.outstandingList.push(item);
- });
- }
- if($scope.currentPage == 0){
- $scope.totalOutstandingList = result.totalcase;
- $scope.outstandingList = $filter('orderBy')($scope.outstandingList, $scope.predicate);
- }*/
- if($scope.tempIncidentList.length == 0){
- $scope.tempIncidentList = result.result;
- //$scope.incidentList = result.result;
- }else{
- angular.forEach(result.result, function(item) {
- item.createdOn = new Date(item.createdOn);
- $scope.tempIncidentList.push(item);
- //$scope.incidentList.push(item);
- });
- }
- if($scope.currentPage == 0){
- $scope.totalOutstandingList = result.totalcase;
- }
- $scope.outstandingList = $scope.tempIncidentList;//$filter('orderBy')($scope.tempIncidentList, $scope.predicate);
- break;
- }
- }else{
- $scope.isInfiniteScrollDisabled = true;
- }
- },function(){
- //Materialize.toast("Error connection.", 2000);
- });
- }
- $scope.reLoadList();
- $scope.addMoreToList = function(){
- $scope.currentPage++;
- $scope.loadCase();
- }
- });
- }
- function NotificationCtrl($scope,$rootScope, $routeParams,WebServices, User, storage, $location, pendingRequests, Idle, $window){
- pendingRequests.cancelAll();
- $scope.$on('$routeChangeSuccess', function () {
- $('#sidenav-overlay').remove();
- $scope.doClearAllNotification = function(){
- $('#deleteconfirmation').openModal();
- }
- $scope.doBack = function(){
- var redirectUrl = storage.get('redirectUrl');
- if(!angular.isUndefined(redirectUrl) && redirectUrl != ''){
- storage.set('redirectUrl','');
- console.log(redirectUrl);
- if(redirectUrl == '/') redirectUrl = '/listcase';
- $location.path(redirectUrl).replace();
- }
- else $location.path('/listcase').replace();
- }
- $scope.countChecked = function(){
- return _.filter($scope.checkeditem,function(item){return item.checkeditem == true;}).length;
- }
- $scope.setAllNotifChecked = function(toggle){
- for(var i = 0; i<$scope.checkeditem.length ; i++){
- $scope.checkeditem[i].checkeditem = toggle;
- }
- }
- $scope.clearAllNotification = function(){
- $('#deleteconfirmation').closeModal();
- Materialize.toast('Deleting notification..',1000);
- $scope.checkeditem = _.filter($scope.checkeditem,function(item){return item.checkeditem == true;});
- WebServices.Account.deleteAllNotification($scope.checkeditem).then(function(){
- Materialize.toast('Succesfully delete notification(s)',2000);
- $scope.reLoadList();
- });
- }
- $scope.loadDetail = function(value){
- WebServices.Incident.GetDetailListV2({
- guid : value,
- ownerid : storage.get('userProfile').id
- }).then(function(result){
- var result = result.data;
- if(result.status == "Success"){
- storage.set('currentDetail',result.result);
- storage.set('redirectUrl','/notificationlist');
- $location.path('/detailcase').replace();
- }else{
- Materialize.toast('Fail to get detail case',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- $scope.totalAllNotification = 0;
- $scope.notificationList = [];
- $scope.currentPage = 0;
- $scope.totalAllNotification = 0;
- $scope.isInfiniteScrollDisabled = false;
- $scope.loadNotification = function(){
- pendingRequests.cancelAll();
- WebServices.Account.GetAllNotification({
- startpos : $scope.currentPage,
- ownerCase : storage.get('userProfile').id
- }).then(function(result){
- result = result.data;
- if(result.status== "Success"){
- if($scope.notificationList.length == 0){
- $scope.notificationList = result.result;
- angular.forEach($scope.notificationList, function(item) {
- $scope.checkeditem.push({checkeditem : false, notifid : item.notifid});
- });
- }else{
- angular.forEach(result.result, function(item) {
- $scope.notificationList.push(item);
- $scope.checkeditem.push({checkeditem : false, notifid : item.notifid});
- });
- }
- if($scope.currentPage == 0){
- $scope.totalAllNotification = result.totalcase;
- }
- }else{
- $scope.isInfiniteScrollDisabled = true;
- }
- })
- }
- $scope.addMoreNotification = function(){
- $scope.currentPage++;
- $scope.loadNotification();
- }
- $scope.reLoadList = function(){
- /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaNotif",function(result){
- }, function(){
- });*/
- $rootScope.prefs.remove(function(){},function(){},'sqaNotif');
- $scope.notificationList = [];
- $scope.checkeditem = [];
- $scope.currentPage = 0;
- $scope.totalAllNotification = 0;
- $scope.isInfiniteScrollDisabled = false;
- $scope.loadNotification();
- }
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.getTimePart = function(value){
- return moment(value).format("DD/MM/YYYY HH:mm");
- }
- $scope.reLoadList();
- });
- }
- function SearchCaseCtrl($rootScope, $scope, $routeParams, WebServices, storage, $location, pendingRequests,Idle){
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.$on('$routeChangeSuccess', function () {
- $('#sidenav-overlay').remove();
- $scope.openModal = function(){
- $('#modal1').openModal();
- }
- $scope.fromNow = function(value){
- var today = moment().format("DD/MM/YYYY");
- if(today == value)return "Today";
- else return moment(value,"DD/MM/YYYY").fromNow();
- }
- $scope.loadDetail = function(value){
- var currentDetail = [];
- currentDetail.push(value);
- WebServices.Incident.GetDetailListV2({
- guid : value.caseid,
- ownerid : storage.get('userProfile').id
- }).then(function(result){
- var result = result.data;
- if(result.status == "Success"){
- storage.set('currentDetail',result.result);
- $location.path('/detailcase');
- }else{
- Materialize.toast('Fail to get detail case',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- $scope.getTimePart = function(value){
- return moment(value).format("dd/MM/yyyy HH:mm");
- }
- $scope.currentPage = 0;
- $scope.SearchForm = {
- searchBy : "CaseNumber",
- title : "",
- startPos : $scope.currentPage
- };
- $scope.filterCase = {
- ownerCase : storage.get('userProfile').id,
- divisi : storage.get('userProfile').departmentUser.divisiGuid,
- }
- $scope.searchResult = [];
- $scope.oldTitle = "";
- $scope.oldFilterBy = "";
- $scope.$watch('SearchForm.searchBy',function(){
- if($scope.SearchForm.title != ""){
- $scope.doSearch($scope.SearchForm);
- }
- })
- $scope.doSearch = function(SearchForm){
- pendingRequests.cancelAll();
- if(SearchForm.title === ""){
- Materialize.toast('Search Text must be filled.', 2000);
- }else{
- if($scope.oldTitle === SearchForm.title && $scope.oldFilterBy === SearchForm.searchBy){
- if($scope.incidentList.length > 0) $scope.currentPage=$scope.currentPage+1;
- else $scope.currentPage = 0;
- $scope.SearchForm.startPos = $scope.currentPage;
- }else{
- $scope.oldTitle = SearchForm.title;
- $scope.oldFilterBy = SearchForm.searchBy;
- $scope.currentPage = 0;
- $scope.SearchForm.startPos = $scope.currentPage;
- $scope.incidentList = [];
- }
- var request = {search : SearchForm, filterCase : $scope.filterCase};
- WebServices.Incident.SearchCase(request).then(function(result){
- var result = result.data;
- if(result.status == "Success"){
- if($scope.incidentList.length == 0){
- $scope.incidentList = result.result;
- }else{
- angular.forEach(result.result, function(item) {
- $scope.incidentList.push(item);
- });
- }
- }
- if($scope.incidentList.length == 0){
- //Materialize.toast("No cases found", 2000);
- $scope.notFoundFlag = true;
- $scope.isInfiniteScrollDisabled = true;
- }else{
- $scope.notFoundFlag = false;
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- }
- $scope.addMoreSearchResult = function(){
- $scope.currentPage++;
- $scope.doSearch($scope.SearchForm);
- }
- });
- }
- function SignUpCtrl($scope, $rootScope, WebServices,$location,pendingRequests){
- $scope.SignUpInput = {
- username : '',
- password : '',
- repassword : ''
- }
- $scope.user = {};
- $scope.checkEmailResponse = function(value, dataUser){
- $scope.checkEmailMessage = value;
- if(dataUser){
- $scope.user = dataUser;
- }
- }
- $scope.checkSignUpResponse = function(value){
- $scope.checkSignUpCodeMessage = value;
- }
- $scope.doSignUp = function(){
- pendingRequests.cancelAll();
- WebServices.Account.SignUp({
- _signUp : {
- id : $scope.user.id,
- UserName : $scope.user.username,
- email : $scope.user.email,
- passwd : $scope.SignUpInput.passwd
- }
- }).then(function(result){
- var result = result.data;
- if(result.status == "Success"){
- Materialize.toast("Password set succesfully.", 2000);
- $location.path('/login').replace();
- }else{
- Materialize.toast(result.errMsg, 2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- }
- function ForgotPasswordCtrl($rootScope, $scope, WebServices, $location,pendingRequests){
- $scope.doSendRequest = function(){
- WebServices.Account.ForgotPassword({email:$scope.ForgotPasswordInput.email}).then(function(result){
- pendingRequests.cancelAll();
- var result = result.data;
- if(result.status == "Success"){
- Materialize.toast("Your password has been succesfully reset. Please check your email.", 2000);
- $location.path('/login').replace();
- }else{
- Materialize.toast(result.errMsg, 2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- }
- function ManageCaseCtrl($rootScope, $scope,$routeParams, WebServices,storage, $location, $timeout, $q, cfpLoadingBar, initialDataForm,initialDataInputCase , pendingRequests, Idle){
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.$on('$routeChangeSuccess', function () {
- $scope.currLocation = $location.url();
- $scope.caseSameTitle = "";
- $scope.fileList = [];
- storage.set('fileList',$scope.fileList);
- $scope.changedIndex = -1;
- storage.set('changedIndex',$scope.changedIndex);
- $scope.doRetryUpload = false;
- $scope.hasUpdateCase = false;
- $scope.hasUploadAllImages = false;
- $scope.inProgress = false;//allProgress
- $scope.startProgressImage = false;
- $scope.stopProgressImage = true;
- $scope.indexImageFailed = [];
- $scope.currentIndexImages = 0;
- $scope.totalFailedImages = 0;
- $scope.doneDescription = "";
- $scope.urgentFlag = false;
- $scope.undoFlag = false;
- $('#sidenav-overlay').remove();
- $scope.doLoading = function(bool){
- if(bool){
- $('#loadingmodal').openModal();
- $scope.loading = true;
- }else{
- $('#loadingmodal').closeModal();
- $scope.loading = false;
- }
- }
- $scope.$watch('inProgress',function(){
- if($scope.inProgress)$scope.doLoading(true);
- else $scope.doLoading(false);
- });
- $scope.$watch('hasUpdateCase',function(){
- if($scope.hasUpdateCase && $scope.hasUploadAllImages){
- $scope.inProgress = false;
- Materialize.toast("Saving case finished.", 2000);
- $location.path('/listcase').replace();
- }
- });
- $scope.checkLevel = function(){
- var test = $scope.InputCase.damageLevel;
- if(test.Text == 'Urgent')return true;
- else return false;
- }
- $scope.$watch('hasUploadAllImages',function(){
- if($scope.hasUpdateCase && $scope.hasUploadAllImages){
- $scope.inProgress = false;
- Materialize.toast("Saving case finished", 2000);
- $location.path('/listcase').replace();
- }
- });
- $scope.stopProgressImg = function(){
- $scope.startProgressImage = false;
- $scope.stopProgressImage = true;
- $scope.inProgress = false;
- if($scope.hasUploadAllImages == false){
- angular.forEach($scope.indexImageFailed, function(value) {
- $scope.fileList[value].failFlag = true;
- });
- Materialize.toast("Some image failed to upload",2000);
- $('#opsimodal').openModal();
- }else{
- Materialize.toast("Finish uploading image", 2000);
- $location.path('/listcase').replace();
- }
- }
- $scope.startProgressImg = function(){
- $scope.inProgress = true;
- $scope.startProgressImage = true;
- $scope.stopProgressImage = false;
- }
- var win = function(){
- var max = $scope.doRetryUpload ? $scope.totalFailedImages : storage.get('fileList').length;
- if($scope.doRetryUpload){
- $scope.fileList[$scope.indexImageFailed[$scope.currentIndexImages]].failFlag = false;
- $scope.indexImageFailed.splice($scope.currentIndexImages,0);
- }
- if(($scope.currentIndexImages+1) < max){
- $scope.currentIndexImages++;
- fileUpload($scope.savedcase.Id);
- }else{
- if($scope.indexImageFailed.length == 0){
- $scope.$apply(function(){
- $scope.hasUploadAllImages = true;
- $scope.stopProgressImg();
- });
- }else{
- $scope.$apply(function(){
- $scope.hasUploadAllImages = false;
- $scope.stopProgressImg();
- $scope.doRetryUpload = false;
- $scope.totalFailedImages = $scope.indexImageFailed.length;
- });
- }
- }
- };
- var fail = function(){
- var value = -1;
- if(!$scope.doRetryUpload){
- value = $scope.currentIndexImages;
- if(! _.contains($scope.indexImageFailed, value))$scope.indexImageFailed.push(value);
- }
- var max = $scope.doRetryUpload ? $scope.totalFailedImages : storage.get('fileList').length;
- if(($scope.currentIndexImages+1) < max){
- $scope.$apply(function(){
- $scope.currentIndexImages++;
- fileUpload($scope.savedcase.Id);//agar tetap lanjut proses
- });
- }else{
- $scope.$apply(function(){
- $scope.hasUploadAllImages = false;
- $scope.doRetryUpload = false;
- $scope.totalFailedImages = $scope.indexImageFailed.length;
- $scope.stopProgressImg();
- });
- }
- }
- var fileUpload = function (entityId){
- var files = storage.get('fileList');
- var options = new FileUploadOptions();
- var index = -1;
- if($scope.doRetryUpload){
- index = $scope.indexImageFailed[$scope.currentIndexImages];
- }else{
- index = $scope.currentIndexImages;
- }
- options.fileKey = "file";
- console.log(files[index]);
- console.log(files[index].path);
- options.fileName = files[index].path.substr(files[index].path.lastIndexOf('/')+1);
- options.mimeType = "image/jpeg";
- options.chunkedMode = false;
- var ft = new FileTransfer();
- ft.upload(files[index].path, encodeURI(WebServices.baseUrl +"api/attachment/uploadImage?entityId="+entityId+"&token="+storage.get('userToken')) , win, fail, options);
- }
- $scope.doRetry = function(){
- $('#modal1').closeModal();
- $('#opsimodal').closeModal();
- $scope.doRetryUpload = true;
- $scope.currentIndexImages = 0;
- $scope.startProgressImg();
- fileUpload($scope.savedcase.Id);
- }
- $scope.cancelSaveDone = function(){
- $('#opsimodal').closeModal();
- }
- $scope.cancelSave = function(){
- $('#modal1').closeModal();
- $('#opsimodal').closeModal();
- $scope.inProgress = true;
- WebServices.Incident.deleteCase({
- caseId : $scope.savedcase.Id
- }).then(function(result){
- $scope.hasUpdateCase = false;
- $scope.hasUploadAllImages = false;
- $scope.inProgress = false;//allProgress
- $scope.startProgressImage = false;
- $scope.stopProgressImage = true;
- $scope.indexImageFailed = [];
- $scope.currentIndexImages = 0;
- $scope.totalFailedImages = 0;
- });
- }
- $scope.errorDamageLevel = false;
- var isNullOrEmpty = function(value){
- if(value == null || value === "" || value === "undefined") return true;
- else return false;
- }
- $scope.$watch('InputCase.damageLevel',function(){
- if(isNullOrEmpty($scope.InputCase.damageLevel)){
- $scope.errorborderbottom = {'border-bottom':'1px solid red'};
- }else{
- $scope.errorborderbottom = {};
- }
- });
- $scope.cancelSaveTitle = function(){
- $scope.inProgress = false;
- $('#loadingmodal').closeModal();
- $('#caseconfirmationmodal').closeModal();
- }
- $scope.continueSaveCaseWithoutCheckTitle = function(){
- $scope.formValue = angular.copy($scope.InputCase);
- var paramCheckExistTitle = {
- title : $scope.formValue.floor.floorname + " " + $scope.formValue.location.area + " " + $scope.formValue.item.itemName + " "+ $scope.formValue.damageType.damageTypeName,
- id : ""
- };
- $scope.formValue.title = paramCheckExistTitle.title;
- $scope.formValue.damageLevel = parseInt($scope.formValue.damageLevel.Value);
- $('#loadingmodal').openModal();
- $('#caseconfirmationmodal').closeModal();
- var param = { cases : $scope.formValue};
- Materialize.toast("Saving in progress...",2000);
- WebServices.Incident.SaveCase(param).then(function(result){
- $scope.savedcase = result.data.result;
- if($scope.fileList.length > 0){
- $scope.startProgressImg();
- fileUpload($scope.savedcase.Id);
- }else{
- $scope.inProgress = false;
- Materialize.toast("Saving case finished.", 2000);
- storage.set('dataInputCase',"");
- $location.path('/listcase').replace();
- }
- },function(){
- $scope.inProgress = false;
- Materialize.toast('Please check the connection.',2000);
- });
- }
- $scope.seePreview = function(){
- WebServices.Incident.GetDetailListV2({
- guid : $scope.caseSameTitle,
- ownerid : storage.get('userProfile').id,
- }).then(function(result){
- var result = result.data;
- if(result.status == "Success"){
- storage.set('currentDetail',result.result);
- storage.set('redirectUrl','/inputcase');
- $location.path('/previewcase').replace();
- }else{
- Materialize.toast('Fail to get preview case',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- $scope.saveCase = function(){
- pendingRequests.cancelAll();
- $scope.currLocation = $location.url();
- $scope.dataInputCase = {
- InputCase : angular.copy($scope.InputCase),
- optionsetBuilding : angular.copy($scope.optionsetBuilding),
- optionsetType : angular.copy($scope.optionsetType),
- optionsetPriority : angular.copy($scope.optionsetPriority),
- optionsetFloor : angular.copy($scope.optionsetFloor),
- optionsetItem : angular.copy($scope.optionsetItem),
- optionsetCategory : angular.copy($scope.optionsetCategory),
- optionsetArea : angular.copy($scope.optionsetArea),
- optionsetItemDetail :angular.copy($scope.optionsetItemDetail),
- fileList : angular.copy($scope.fileList)
- }
- storage.set('dataInputCase',$scope.dataInputCase);
- if($scope.currLocation == "/inputcase"){
- if($scope.fileList.length == 0) $scope.hasUploadAllImages = true;
- if(!$scope.inProgress){
- $scope.formValue = angular.copy($scope.InputCase);
- if(isNullOrEmpty($scope.formValue.damageLevel) || isNullOrEmpty($scope.formValue.damageType) || isNullOrEmpty($scope.formValue.floor) || isNullOrEmpty($scope.formValue.item) || isNullOrEmpty($scope.formValue.itemDetail) || isNullOrEmpty($scope.formValue.location)){
- Materialize.toast("Please check the field.", 2000);
- angular.forEach($scope.inputcase.$error.required, function(field) {
- field.$dirty = true;
- });
- }else{
- $scope.inProgress = true;
- Materialize.toast("Saving in progress...",2000);
- var paramCheckExistTitle = {
- title : $scope.formValue.floor.floorname + " " + $scope.formValue.location.area + " " + $scope.formValue.item.itemName + " "+ $scope.formValue.damageType.damageTypeName,
- id : ""
- };
- WebServices.Incident.checkExistTitle(paramCheckExistTitle).then(function(result){
- var result = result.data;
- if(result.result === false){
- $scope.formValue.title = paramCheckExistTitle.title;
- $scope.formValue.damageLevel = parseInt($scope.formValue.damageLevel.Value);
- var param = { cases : $scope.formValue};
- WebServices.Incident.SaveCase(param).then(function(result){
- $scope.savedcase = result.data.result;
- if($scope.fileList.length > 0){
- $scope.startProgressImg();
- fileUpload($scope.savedcase.Id);
- }else{
- $scope.inProgress = false;
- Materialize.toast("Saving case finished.", 2000);
- storage.set('dataInputCase',"");
- $location.path('/listcase').replace();
- }
- },function(){
- $scope.inProgress = false;
- Materialize.toast('Please check the connection.',2000);
- });
- }else{
- $scope.caseSameTitle = result.caseid;
- $('#caseconfirmationmodal').openModal();
- $('#loadingmodal').closeModal();
- }
- },function(){
- $scope.inProgress = false;
- Materialize.toast('Please check the connection.',2000);
- });
- }
- }else{
- Materialize.toast("Saving already in progress...",2000);
- }
- }else{
- if($scope.fileList.length == 0) $scope.hasUploadAllImages = true;
- if(!angular.isUndefined($scope.doneDescription) && $scope.doneDescription != ""){
- $scope.descriptionEmptyFlag = false;
- $scope.inProgress = true;
- WebServices.Incident.updateStatusReason({
- entityid : storage.get('currentDetail').caseid,
- nameStatus : "Done",
- valStatus : 4,
- userid : storage.get('userProfile').id,
- desc : $scope.doneDescription
- }).then(function(result){
- $scope.hasUpdateCase = true;
- $scope.savedcase = {Id : storage.get('currentDetail').caseid};
- if($scope.fileList.length > 0){
- $scope.startProgressImg();
- fileUpload($scope.savedcase.Id);
- }else{
- $scope.inProgress = false;
- Materialize.toast("Case has been set to done",2000);
- $location.path('/listcase').replace();
- }
- });
- }else{
- $scope.descriptionEmptyFlag = true;
- Materialize.toast("Please fill the description !",2000);
- }
- }
- }
- $scope.textCategory = "Please select Item Detail First";
- $scope.textType = "Loading Problem Type";
- $scope.textItem = "Please select Problem Type First";
- $scope.textFloor = "Please select Building First";
- $scope.textArea = "Please select Floor first";
- $scope.textDamageLevel = "Select Damage Level";
- $scope.textItemDetail = "Please select Item First";
- $scope.loadFloor = function(guid){
- WebServices.Incident.LoadFloor({buildingGuid : guid}).then(function(result){
- json = result.data;
- $scope.optionsetFloor = [];
- if(json.status == "Success"){
- if(json.result.length == 0){
- $scope.textFloor = "Floor is not available";
- }else{
- $scope.optionsetFloor = [];
- $scope.optionsetFloor = json.result;
- $scope.textFloor = "Select Floor";
- }
- }else{
- $scope.textFloor = "Floor is not available";
- }
- });
- }
- $scope.loadItem = function(guid){
- WebServices.Incident.LoadItem({problemTypeGuid : guid}).then(function(result){
- json = result.data;
- $scope.optionsetItem = [];
- $scope.optionsetItemDetail = [];
- $scope.optionsetCategory = [];
- $scope.InputCase.damageType = "";
- $scope.InputCase.itemDetail = "";
- $scope.InputCase.damageLevel = "";
- if(json.status == "Success"){
- if(json.result.length == 0){
- $scope.textItem = "Item is not available";
- }else{
- $scope.optionsetItem = [];
- $scope.optionsetItem = json.result;
- $scope.textItem = "Select Item";
- }
- }else{
- $scope.textItem = "Item is not available";
- }
- });
- }
- $scope.loadDamageType = function(guid){
- WebServices.Incident.LoadDamageType({itemGuid:guid}).then(function(result){
- json = result.data;
- $scope.optionsetCategory = [];
- $scope.InputCase.damageLevel = "";
- if(json.status == "Success"){
- if(json.result.length == 0){
- $scope.textCategory = "Damage Type is not available";
- }else{
- $scope.optionsetCategory = [];
- $scope.optionsetCategory = json.result;
- $scope.textCategory = "Select Damage Type";
- }
- }else{
- $scope.textCategory = "Damage Type is not available";
- }
- });
- }
- $scope.setDamageLevel = function(){
- $scope.InputCase.urgencydescription = "";
- $scope.chosen = $scope.InputCase.damageType.priorityLevel;
- $scope.InputCase.damageLevel = $scope.optionsetPriority[$scope.getPriorityIndex($scope.chosen)];
- if($scope.InputCase.damageLevel.Text != 'Urgent'){
- $timeout(function(){
- $scope.undoFlag = false;
- $scope.$apply();
- });
- }else{
- $timeout(function(){
- $scope.undoFlag = true;
- $scope.$apply();
- });
- }
- }
- $scope.openUrgency = function(){
- $('#urgencymodal').openModal();
- $scope.InputCase.urgencydescription = "";
- $scope.urgencyFlag=false;
- }
- $scope.setUrgentLevel = function(){
- if($scope.InputCase.urgencydescription != ''){
- $scope.descriptionEmptyFlag = false;
- $scope.chosen = $scope.InputCase.damageType.priorityLevel;
- $scope.InputCase.damageLevel = $scope.optionsetPriority[3];
- $scope.urgentFlag = true;
- $scope.undoFlag = true;
- $('#urgencymodal').closeModal();
- }else{
- $scope.descriptionEmptyFlag = true;
- Materialize.toast("You must fill the reason why urgent.",2000);
- }
- }
- $scope.getCategoryIndex = function(category){
- var returnIndex = -1;
- for(var i=0;i<$scope.optionsetCategory.length; i++){
- var item= $scope.optionsetCategory[i];
- if(item.Text == category){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.getProblemTypeIndex = function(type){
- var returnIndex = -1;
- for(var i=0;i<$scope.optionsetType.length; i++){
- var item= $scope.optionsetType[i];
- if(item.name == type){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.getItemIndex = function(value){
- var returnIndex = -1;
- for(var i=0;i<$scope.optionsetItem.length; i++){
- var item = $scope.optionsetItem[i];
- if(item.itemName == value){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.getAreaIndex = function(area){
- var returnIndex = -1;
- for(var i=0;i<$scope.optionsetArea.length; i++){
- var item= $scope.optionsetArea[i];
- if(item.area == area){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.getPriorityIndex = function(priority){
- var returnIndex = -1;
- for(var i=0;i<$scope.optionsetPriority.length; i++){
- var item = $scope.optionsetPriority[i];
- if(item.Value == priority){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.getFloorIndex = function(floor){
- var returnIndex = -1;
- for(var i=0;i<$scope.optionsetFloor.length; i++){
- var item= $scope.optionsetFloor[i];
- if(item.floorname == floor){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.loadItemDetail = function(guid){
- $scope.textItemDetail = "Loading Item Detail";
- $scope.optionsetItemDetail = [];
- WebServices.Incident.LoadItemDetail({
- itemId:guid,
- }).then(function(result){
- var json = result.data;
- if(json.status == "Success"){
- if(json.result.length == 0){
- $scope.textItemDetail = "Item Detail is not Available";
- }else{
- $scope.textItemDetail = "Select Item Detail";
- $scope.optionsetItemDetail = [];
- $scope.optionsetItemDetail = json.result;
- }
- }else{
- $scope.textItemDetail = "Item Detail is not Available";
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- $scope.loadArea = function(objForm){
- if(objForm.floor == "undefined" || objForm.building == "undefined"){
- $scope.textArea = "Please make sure you already chosen Floor and Building.";
- }else{
- var floorChosen = objForm.floor.guid;
- var buildingChosen = objForm.building.guid;
- $scope.textArea = "Loading Area";
- $scope.optionsetArea = [];
- WebServices.Incident.GetArea({
- floorGuid:floorChosen,
- buildingGuid : buildingChosen
- }).then(function(result){
- var json = result.data;
- if(json.status == "Success"){
- if(json.result.length == 0){
- $scope.textArea = "Location Not Available";
- }else{
- $scope.textArea = "Select Location";
- $scope.optionsetArea = [];
- $scope.optionsetArea = json.result;
- }
- }else{
- $scope.textArea = "Location Not Available";
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- }
- $scope.getBuildingIndex = function(building){
- var returnIndex = -1;
- for(var i=0; i<$scope.optionsetBuilding.length ; i++){
- var item = $scope.optionsetBuilding[i];
- if(item.buildingname == building){
- returnIndex = i;
- break;
- }
- }
- return returnIndex;
- }
- $scope.InputCase = {
- building : "",
- floor : "",
- location : "",
- problemType : "",
- item : "",
- damageType : "",
- damageLevel : "",
- ownercase : storage.get('userProfile').id,
- locationDetail : "",
- itemDetail : "",
- damageDetail : "",
- title : "",
- urgencydescription : "",
- };
- $scope.clearForm = function(){
- storage.set('dataInputCase',"");
- $location.path('/listcase').replace();
- }
- $scope.fillForm = function(){
- var index = 0;
- var dataInputCase = initialDataInputCase.InputCase;
- angular.forEach($scope.optionsetBuilding, function(building){
- if(building.guid == dataInputCase.building.guid){
- $scope.InputCase.building = $scope.optionsetBuilding[index];
- }
- index++;
- });
- index = 0;
- angular.forEach($scope.optionsetType, function(type){
- if(type.guid == dataInputCase.problemType.guid){
- $scope.InputCase.problemType = $scope.optionsetType[index];
- }
- index++;
- });
- index = 0;
- angular.forEach($scope.optionsetFloor, function(floor){
- if(floor.guid == dataInputCase.floor.guid){
- $scope.InputCase.floor = $scope.optionsetFloor[index];
- }
- index++;
- });
- index = 0;
- angular.forEach($scope.optionsetArea, function(location){
- if(location.id == dataInputCase.location.id){
- $scope.InputCase.location = $scope.optionsetArea[index];
- }
- index++;
- });
- index = 0;
- angular.forEach($scope.optionsetItem, function(item){
- if(item.id == dataInputCase.item.id){
- $scope.InputCase.item = $scope.optionsetItem[index];
- }
- index++;
- });
- index = 0;
- angular.forEach($scope.optionsetItemDetail, function(itemDetail){
- if(itemDetail.id == dataInputCase.itemDetail.id){
- $scope.InputCase.itemDetail = $scope.optionsetItemDetail[index];
- }
- index++;
- });
- index = 0;
- angular.forEach($scope.optionsetCategory, function(damageType){
- if(damageType.damageGuid == dataInputCase.damageType.damageGuid){
- $scope.InputCase.damageType = $scope.optionsetCategory[index];
- }
- index++;
- });
- $scope.InputCase.damageLevel = dataInputCase.damageLevel;
- }
- if($scope.currLocation == "/inputcase"){
- if(initialDataInputCase == ""){
- $scope.optionsetType = initialDataForm.problemTypes;
- $scope.optionsetBuilding = initialDataForm.buildings;
- $scope.InputCase.building = $scope.optionsetBuilding[0];
- $scope.InputCase.problemType = $scope.optionsetType[0];
- $scope.loadFloor($scope.InputCase.building.guid);
- $scope.loadItem($scope.InputCase.problemType.guid);
- $scope.optionsetPriority = initialDataForm.damageLevels;
- $scope.textType = "Select Problem Type";
- $scope.textBuilding = "Select Building";
- }else{
- $scope.optionsetType = initialDataInputCase.optionsetType;
- $scope.optionsetBuilding = initialDataInputCase.optionsetBuilding;
- $scope.optionsetFloor = initialDataInputCase.optionsetFloor;
- $scope.optionsetItem = initialDataInputCase.optionsetItem;
- $scope.optionsetPriority = initialDataInputCase.optionsetPriority;
- $scope.optionsetCategory = initialDataInputCase.optionsetCategory;
- $scope.optionsetArea = initialDataInputCase.optionsetArea;
- $scope.optionsetItemDetail = initialDataInputCase.optionsetItemDetail;
- $scope.fillForm();
- $scope.fileList = initialDataInputCase.fileList;
- $scope.textType = "Select Problem Type";
- $scope.textBuilding = "Select Building";
- }
- }
- $scope.filterCount = function(){
- var filtered = _.filter($scope.fileList,function(item){
- return item.displayed === true;
- });
- return filtered.length;
- }
- $scope.resetUpload = function(){
- $scope.fileList = [];
- storage.set('fileList',$scope.fileList);
- }
- $scope.changeFile = function(index){
- $scope.changedIndex = index;
- storage.set('changedIndex',$scope.changedIndex);
- storage.set('hasExecuted',false);
- $('#modal1').openModal();
- }
- $scope.deleteFile = function(index){
- var item = $scope.fileList[index];
- if(item.id == '')$scope.fileList.splice(index,1);
- else {
- $scope.fileList[index].displayed = false;
- $scope.fileList[index].isChanged = false;
- }
- storage.set('fileList',$scope.fileList);
- }
- $scope.openModal = function(){
- $scope.changedIndex = -1;
- storage.set('changedIndex',$scope.changedIndex);
- storage.set('hasExecuted',false);
- $('#modal1').openModal();
- }
- pictureSource=navigator.camera.PictureSourceType;
- destinationType=navigator.camera.DestinationType;
- function successCallback(localFileUri){
- $scope.$apply(function(){
- $scope.pathImage = localFileUri;
- console.log($scope.pathImage);
- var hasExecuted = storage.get('hasExecuted');
- if(hasExecuted == false && $scope.pathImage != ''){
- $scope.changedIndex = parseInt(storage.get('changedIndex'));
- if($scope.changedIndex == -1) {
- $scope.fileList.push({
- isChanged : false,
- path : $scope.pathImage,
- id : '',
- displayed : true,
- failFlag : false
- });
- }else{
- $scope.fileList[$scope.changedIndex].isChanged = true;
- $scope.fileList[$scope.changedIndex].path = $scope.pathImage;
- $scope.fileList[$scope.changedIndex].displayed = true;
- }
- $rootScope.prefs.remove(function(result){
- $scope.pathImage = '';
- storage.set('fileList',$scope.fileList);
- storage.set('hasExecuted',true);
- $scope.$apply(function(){
- $scope.fileList = storage.get('fileList');
- })
- },function(){},'sqaImageTempPath');
- /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
- $scope.pathImage = '';
- storage.set('fileList',$scope.fileList);
- storage.set('hasExecuted',true);
- $scope.$apply(function(){
- $scope.fileList = storage.get('fileList');
- })
- }, function(){
- });*/
- }
- });
- }
- function errorCallback(message){
- alert('Failed because: ' + message);
- }
- function onPhotoDataSuccess(value){
- window.FilePath.resolveNativePath(value, successCallback, errorCallback);
- }
- function onPhotoURISuccess(value){
- window.FilePath.resolveNativePath(value, successCallback, errorCallback);
- }
- function onFail(message){
- alert('Failed because: ' + message);
- }
- $scope.openGallery = function(){
- $('#modal1').closeModal();
- /*window.plugins.webintent.startActivity({
- action : window.plugins.webintent.ACTION_PICK,
- type : 'image/*'
- },
- function(){
- //image picker sukses
- },
- function(e){
- }
- );*/
- navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
- destinationType: destinationType.NATIVE_URI,
- sourceType: pictureSource.PHOTOLIBRARY
- });
- }
- $scope.openCamera = function(){
- $('#modal1').closeModal();
- navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
- destinationType: destinationType.NATIVE_URI
- }
- );
- /*window.plugins.webintent.startActivity({
- action : window.plugins.webintent.ACTION_CAMERA,
- type : 'image/*'
- },
- function(){
- //camera sukses
- },
- function(e){
- }
- );*/
- }
- document.addEventListener("resume", onDeviceResumeManageCaseCtrl, false);
- function fileExists(fileEntry){
- fileEntry.file(function(file) {
- var hasExecuted = storage.get('hasExecuted');
- if(hasExecuted == false && $scope.pathImage != ''){
- $scope.changedIndex = parseInt(storage.get('changedIndex'));
- if($scope.changedIndex == -1) {
- $scope.fileList.push({
- isChanged : false,
- path : $scope.pathImage,
- id : '',
- displayed : true,
- failFlag : false
- });
- }else{
- $scope.fileList[$scope.changedIndex].isChanged = true;
- $scope.fileList[$scope.changedIndex].path = $scope.pathImage;
- $scope.fileList[$scope.changedIndex].displayed = true;
- }
- /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
- $scope.pathImage = '';
- storage.set('fileList',$scope.fileList);
- storage.set('hasExecuted',true);
- $scope.$apply(function(){
- $scope.fileList = storage.get('fileList');
- })
- }, function(){
- });*/
- }
- });
- }
- function fileDoesNotExist(){
- /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
- }, function(){
- });*/
- }
- function checkIfFileExists(path){
- var hasExecuted = storage.get('hasExecuted');
- if(!hasExecuted){
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
- fileSystem.root.getFile($.url(path).attr("path"), { create: false }, fileExists, fileDoesNotExist);
- }, getFSFail);
- }
- }
- function getFSFail(evt) {
- /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
- }, function(){
- });*/
- }
- storage.set('hasExecuted',false);
- });
- }
- function PreviewCaseCtrl($rootScope, $scope, $routeParams, $location, storage, Idle){
- $scope.doBack = function(){
- $location.path('/inputcase').replace();
- }
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.$on('$routeChangeSuccess', function () {
- $('#sidenav-overlay').remove();
- });
- $scope.hasLoadSlider = false;
- $scope.slider = {};
- $scope.currentDetail = storage.get('currentDetail');
- $scope.currentDetail = storage.get('currentDetail');
- if($scope.currentDetail.images){
- if($scope.currentDetail.images.length > 0){
- $scope.slider = $('.bxslider').bxSlider({
- infiniteLoop: false,
- //touchEnabled: true,
- hideControlOnEnd: true
- });
- }
- }
- $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
- if(!$scope.hasLoadSlider){
- /*$scope.slider = $('.bxslider').bxSlider({
- infiniteLoop: false,
- //touchEnabled: true,
- //hideControlOnEnd: true
- });*/
- $scope.slider.reloadSlider();
- $scope.hasLoadSlider = true;
- }else{
- $scope.slider.reloadSlider();
- }
- $('.popuplink').magnificPopup({
- type: 'image',
- gallery: {
- enabled: true,
- navigateByImgClick: true,
- preload: [0,1] // Will preload 0 - before current, and 1 after the current image
- },
- });
- });
- }
- function DetailCaseCtrl($rootScope, $scope, $routeParams, $location, WebServices, storage, loadListAssign, loadExtendReasons, Idle){
- $scope.doBack = function(){
- var redirectUrl = storage.get('redirectUrl');
- if(angular.isUndefined(redirectUrl))$location.path('/listcase').replace();
- else $location.path(redirectUrl).replace();
- }
- $scope.$on('IdleTimeout', function() {
- Idle.unwatch();
- storage.set('redirectUrl',$location.url());
- $location.path('/blocked').replace();
- });
- $scope.$on('Keepalive', function() {
- storage.set('idle',storage.get('ngIdle.expiry').time);
- });
- $scope.$on('$routeChangeSuccess', function () {
- $('#sidenav-overlay').remove();
- $scope.userProfile = storage.get('userProfile');
- $scope.statusCase = 0;
- $scope.statusName = '';
- $scope.description = '';
- $scope.PersonToAssign = '';
- $scope.loading = false;
- function suggest_state(term) {
- var q = term.toLowerCase().trim();
- var results = [];
- // Find first 10 states that start with `term`.
- for (var i = 0; i < $scope.listPeopleToAssign.length && results.length < 10; i++) {
- var look = $scope.listPeopleToAssign[i];
- if (look.fullName.toLowerCase().indexOf(q) === 0)results.push({
- label: look.fullName,
- value: look.fullName,
- obj : look
- });
- }
- return results;
- }
- $scope.autocomplete_options = {
- suggest: suggest_state,
- on_select: function (selected) {
- $scope.PersonToAssign = selected.obj;
- }
- };
- $('.modal-trigger').leanModal({
- dismissible: false, // Modal can be dismissed by clicking outside of the modal
- });
- if(!angular.isUndefined(loadExtendReasons.data)){
- $scope.listExtendReason = loadExtendReasons.data.result;
- }else{
- $scope.listExtendReason = [];
- }
- $scope.listPeopleToAssign = loadListAssign;
- $scope.openUpdateCasePage = function(object){
- $location.path('/updatecase').replace();
- }
- $scope.sameHandleByPerson = function(){
- var userId = storage.get('userProfile').id;
- if($scope.currentDetail.handledBy == userId) return true;
- else return false;
- }
- $scope.checkUserAccess = function(){
- var result = false;
- var userDepartmentGuid = storage.get('userProfile').departmentUser.guid;
- var userDivisiGuid = storage.get('userProfile').departmentUser.divisiGuid;
- var position = storage.get('userProfile').positionname.toLowerCase();
- switch(position){
- case 'super user' :
- case 'gm':
- case 'head':
- if($scope.currentDetail.department){
- if($scope.currentDetail.department.divisiGuid == userDivisiGuid) result = true;
- else return false;
- }else return false;
- break;
- case 'manager':
- case 'supervisor':
- case 'executor':
- if($scope.currentDetail.department){
- if($scope.currentDetail.department.guid == userDepartmentGuid) result = true;
- }
- else return false;
- break;
- case 'auditor' : result = true;break;
- case 'reporter' : result = false;break;
- }
- return result;
- }
- $scope.PersonToAssign = '';
- $scope.doAssign = function(){
- if($scope.PersonToAssign == ''){
- $scope.descriptionEmptyFlag = true;
- Materialize.toast('Please type name person to assign first.',2000);
- }else{
- $('#modal1').closeModal();
- $scope.doLoading(true);
- WebServices.Incident.doAssign({
- param : {
- fromId : storage.get('userProfile').id,
- toId : $scope.PersonToAssign.id,
- caseId : $scope.currentDetail.caseid
- }
- }).then(function(result){
- result = result.data;
- if(result.status == "Success"){
- Materialize.toast("Case assigned succesfully.", 2000);
- WebServices.Incident.GetDetailListV2({
- guid : $scope.currentDetail.caseid,
- ownerid : storage.get('userProfile').id
- }).then(function(result){
- $scope.doLoading(false);
- $scope.description = '';
- var result = result.data;
- if(result.status == "Success"){
- storage.set('currentDetail',result.result);
- $scope.currentDetail = storage.get('currentDetail');
- }else{
- Materialize.toast('Fail to Update case',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }else{
- Materialize.toast(result.errMsg,2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- }
- function isValidDate(str) {//2015-07-30 00:30
- var d = moment(str,'YYYY-MM-DD hh:mm');
- if(d == null || !d.isValid()) return false;
- else return true;
- }
- $scope.doExtend = function(){
- var error = 0;
- if($scope.description == ''){
- error++;
- $scope.descriptionEmptyFlag = true;
- }
- else $scope.descriptionEmptyFlag = false;
- if(!isValidDate($scope.extendDate)){
- error++;
- $scope.validDateFlag = true;
- }
- else $scope.validDateFlag = false;
- if($scope.ExtendReasons == '' || angular.isUndefined($scope.ExtendReasons)){
- error++;
- $scope.extendNotSelectedFlag = true;
- }else{
- $scope.extendNotSelectedFlag = false;
- }
- if(error > 0){
- Materialize.toast('Please check the field.',2000);
- }else{
- $('#modal4').closeModal();
- $scope.doLoading(true);
- var d = moment($scope.extendDate,'YYYY-MM-DD hh:mm');
- WebServices.Incident.doExtend({
- param : {
- date : d.toISOString(),
- description : $scope.description,
- caseid : $scope.currentDetail.caseid,
- whoExtend : storage.get('userProfile').id,
- extendReason : $scope.ExtendReasons
- }
- }).then(function(result){
- result = result.data;
- if(result.status == "Success"){
- Materialize.toast("Case has been succesfully extended. Updating case.. ", 2000);
- WebServices.Incident.GetDetailListV2({
- guid : $scope.currentDetail.caseid,
- ownerid : storage.get('userProfile').id
- }).then(function(result){
- $scope.doLoading(false);
- $scope.description = '';
- var result = result.data;
- if(result.status == "Success"){
- storage.set('currentDetail',result.result);
- $scope.currentDetail = storage.get('currentDetail');
- }else{
- Materialize.toast('Fail to update case',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }else{
- Materialize.toast(result.errMsg,2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- }
- }
- $scope.hasLoadSlider = false;
- $scope.slider = {};
- $(".dropdown-button").dropdown();
- $scope.currentDetail = storage.get('currentDetail');
- if($scope.currentDetail.images){
- if($scope.currentDetail.images.length > 0){
- $scope.slider = $('.bxslider').bxSlider({
- infiniteLoop: false,
- //touchEnabled: true,
- hideControlOnEnd: true
- });
- }
- }
- $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
- if(!$scope.hasLoadSlider){
- /*$scope.slider = $('.bxslider').bxSlider({
- infiniteLoop: false,
- //touchEnabled: true,
- //hideControlOnEnd: true
- });*/
- $scope.slider.reloadSlider();
- $scope.hasLoadSlider = true;
- }else{
- $scope.slider.reloadSlider();
- }
- $('.popuplink').magnificPopup({
- type: 'image',
- gallery: {
- enabled: true,
- navigateByImgClick: true,
- preload: [0,1] // Will preload 0 - before current, and 1 after the current image
- },
- });
- });
- $scope.openModal = function(){
- $('#modal1').openModal();
- }
- $scope.checkIsAssigned = function(){
- return ($scope.currentDetail.isAssigned == null || $scope.currentDetail.isAssigned == '' || $scope.currentDetail.isAssigned == false)
- }
- $scope.checkIsExtended = function(){
- return ($scope.currentDetail.isExtended == null || $scope.currentDetail.isExtended == '' || $scope.currentDetail.isExtended == false)
- }
- $scope.closeModal = function(){
- $('#modal1').closeModal();
- }
- $scope.doLoading = function(bool){
- if(bool){
- $('#loadingmodal').openModal();
- $scope.loading = true;
- }else{
- $('#loadingmodal').closeModal();
- $scope.loading = false;
- }
- }
- $scope.doUpdateStatus = function(){
- if($scope.description != "" ){
- $('#modal3').closeModal();
- $scope.doLoading(true);
- WebServices.Incident.updateStatusReason({
- entityid : $scope.currentDetail.caseid,
- nameStatus : $scope.statusName,
- valStatus : $scope.statusCase,
- userid : storage.get('userProfile').id,
- desc : $scope.description
- }).then(function(result){
- WebServices.Incident.GetDetailListV2({
- guid : $scope.currentDetail.caseid,
- ownerid : storage.get('userProfile').id
- }).then(function(result){
- $scope.doLoading(false);
- $scope.description = '';
- var result = result.data;
- if(result.status == "Success"){
- storage.set('currentDetail',result.result);
- $scope.currentDetail = storage.get('currentDetail');
- }else{
- Materialize.toast('Fail to update Case',2000);
- }
- },function(){
- Materialize.toast("Error connection.", 2000);
- });
- });
- }else{
- $scope.descriptionEmptyFlag = true;
- Materialize.toast("Please fill the description !",2000);
- }
- }
- $('*[name=datetimepicker]').appendDtpicker({
- "futureOnly": true,
- "minTime":"00:00",
- "maxTime":"23:30",
- "timelistScroll": false,
- "calendarMouseScroll": false,
- "autodateOnStart": false
- });
- $scope.openModalByID = function(id){
- $('#'+id).openModal();
- }
- $scope.getTimePart = function(value){
- var momentValue = moment(value).format("DD/MM/YYYY HH:mm");
- if(momentValue == "Invalid date"){
- return " - ";
- }else{
- return momentValue;
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement