Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 65.27 KB | None | 0 0
  1. function ErrorConnectionCtrl($scope, $rootScope, $location, WebServices, pendingRequests,storage,Idle){
  2. $scope.Reloading = function(){
  3. pendingRequests.cancelAll();
  4. WebServices.Account.cekToken().then(function(result){
  5. result = result.data;
  6. if(result.status == "Not Found" || result.status == "Error"){
  7. storage.set('userProfile','');
  8. storage.set('userToken','');
  9. storage.set('fileList','');
  10. storage.set('changedIndex',-1);
  11. Idle.unwatch();
  12. $location.path('/login').replace();
  13. }else{
  14. Idle.watch();
  15. storage.set('idle',storage.get('ngIdle.expiry').time);
  16. $location.path('/listcase').replace();
  17. }
  18. },function(){
  19. Materialize.toast('Please check the connection.',2000);
  20. });
  21. }
  22. }
  23.  
  24. function LoginCtrl($scope, $rootScope, $routeParams,$http,WebServices,storage,$location, Idle) {
  25. $scope.$on('$routeChangeSuccess', function () {
  26. $('#sidenav-overlay').remove();
  27. $scope.doLogin = function(){
  28. WebServices.Account.Login($scope.LoginInput).then(function(result){
  29. result = result.data;
  30. if(result.status == "Success"){
  31. storage.set("loginInput",$scope.LoginInput.email);
  32. storage.set("userToken",result.Token);
  33. storage.set("userProfile",result.result[0]);
  34.  
  35. var dataUser = storage.get('userProfile');
  36. var userGuid=dataUser.id;
  37. var userDepartmentGuid=dataUser.departmentUser.guid;
  38. var roleValues = dataUser.position;
  39. var groupPhases = dataUser.notifGroupPhase;
  40.  
  41. /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
  42.  
  43. window.plugins.parselogin.updateParseObject(param,function(){
  44.  
  45. },function(){
  46.  
  47. });*/
  48. Idle.watch();
  49. storage.set('idle',storage.get('ngIdle.expiry').time);
  50. $location.path('/listcase').replace();
  51. }else{
  52. Materialize.toast(result.errMsg, 2000);
  53. }
  54. },function(){
  55. Materialize.toast("Error connection.", 2000);
  56. });
  57. }
  58. });
  59. }
  60.  
  61. function BlockedCtrl($scope, $rootScope, $routeParams,$http,WebServices,storage,$location, Idle, $timeout) {
  62. $scope.LoginInput = {
  63. email : storage.get('userProfile').primaryEmail,
  64. passwd : '',
  65. userguid : storage.get('userProfile').id
  66. };
  67.  
  68. $scope.signOut = function(){
  69. WebServices.Account.Logout().then(function(result){
  70. storage.set('userProfile','');
  71. storage.set('userToken','');
  72. storage.set('hasExecuted','');
  73. storage.set('fileList','');
  74. storage.set('currentDetail','');
  75. storage.set('changedIndex',-1);
  76. var userGuid="";
  77. var userDepartmentGuid="";
  78. var roleValues = "";
  79. var groupPhases = [];
  80.  
  81. /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
  82.  
  83. window.plugins.parselogin.updateParseObject(param,function(){
  84.  
  85. },function(){
  86.  
  87. });*/
  88. Idle.unwatch();
  89. $location.path('/login').replace();
  90. },function(){
  91. Materialize.toast('Error connection.',2000);
  92. });
  93. }
  94.  
  95. $scope.username = angular.isUndefined(storage.get("loginInput")) || storage.get("loginInput") == '' ? '' : storage.get('userProfile').primaryEmail;
  96.  
  97. $scope.$on('$routeChangeSuccess', function () {
  98. $('#sidenav-overlay').remove();
  99. $scope.doLogin = function(){
  100. WebServices.Account.CheckUserSessionV2($scope.LoginInput).then(function(result){
  101. result = result.data;
  102. if(result.status == "Success"){
  103. storage.set('userProfile',result.result);
  104.  
  105. var dataUser = storage.get('userProfile');
  106. var userGuid=dataUser.id;
  107. var userDepartmentGuid=dataUser.departmentUser.guid;
  108. var roleValues = dataUser.position;
  109. var groupPhases = dataUser.notifGroupPhase;
  110.  
  111. /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
  112.  
  113. window.plugins.parselogin.updateParseObject(param,function(){
  114.  
  115. },function(){
  116.  
  117. });*/
  118. Idle.watch();
  119. storage.set('idle',storage.get('ngIdle.expiry').time);
  120. if(result.totalUnreadNotif > 0){
  121. $location.path('/notificationlist').replace();
  122. }else{
  123. var redirectUrl = storage.get('redirectUrl');
  124. if(!angular.isUndefined(redirectUrl)){
  125. storage.set('redirectUrl','');
  126. $location.path(redirectUrl).replace();
  127. }
  128. else $location.path('/listcase').replace();
  129. }
  130. }else{
  131. /*storage.set('userProfile','');
  132. storage.set('userToken','');
  133. storage.set('hasExecuted','');
  134. storage.set('fileList','');
  135. storage.set('changedIndex',-1);
  136. storage.set('redirectUrl',$location.url());
  137. Idle.unwatch();
  138. var userGuid="";
  139. var userDepartmentGuid="";
  140. var roleValues = "";
  141. var groupPhases = [];
  142.  
  143. var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
  144.  
  145. window.plugins.parselogin.updateParseObject(param,function(){
  146.  
  147. },function(){
  148.  
  149. });
  150. $location.path("/login").replace();*/
  151. Material.toast("Invalid password",2000);
  152. Idle.unwatch();
  153. }
  154. },function(){
  155. Materialize.toast("Error connection.", 2000);
  156. });
  157. }
  158. });
  159. }
  160.  
  161. function MyProfileCtrl($scope, $rootScope, WebServices,storage, retrieveProfile, $location, Idle){
  162. $scope.$on('IdleTimeout', function() {
  163. Idle.unwatch();
  164. storage.set('redirectUrl',$location.url());
  165. $location.path('/blocked').replace();
  166. });
  167.  
  168. $scope.$on('Keepalive', function() {
  169. storage.set('idle',storage.get('ngIdle.expiry').time);
  170. });
  171.  
  172. $scope.$on('$routeChangeSuccess', function () {
  173. storage.set('userProfile',retrieveProfile.data.result);
  174. $('#sidenav-overlay').remove();
  175. $scope.user = storage.get('userProfile');
  176. $scope.cancelChangePassword = function(){
  177. $scope.editpasswordmode=false;
  178. $scope.password = "";
  179. $scope.newpassword = "";
  180. $scope.oldpassword = "";
  181. }
  182. $scope.saveChangePassword = function(){
  183. $scope.editpasswordmode = false;
  184. WebServices.Account.ChangePassword({
  185. form : {
  186. email : $scope.user.primaryEmail,
  187. oldPasswd : $scope.oldpassword,
  188. newPasswd : $scope.newpassword
  189. }
  190. }).then(function(result){
  191. var result = result.data;
  192. if(result.status === "Success"){
  193. $scope.oldpassword = "";
  194. $scope.password = "";
  195. $scope.newpassword = "";
  196. Materialize.toast("Your password has been succesfully changed!", 2000);
  197. WebServices.Account.Logout().then(function(result){
  198. storage.set('userProfile','');
  199. storage.set('userToken','');
  200. storage.set('hasExecuted','');
  201. storage.set('fileList','');
  202. storage.set('currentDetail','');
  203. storage.set('changedIndex',-1);
  204. var userGuid="";
  205. var userDepartmentGuid="";
  206. var roleValues = "";
  207. var groupPhases = [];
  208.  
  209. /*var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
  210.  
  211. window.plugins.parselogin.updateParseObject(param,function(){
  212.  
  213. },function(){
  214.  
  215. });*/
  216. Idle.unwatch();
  217. $location.path('/login').replace();
  218. },function(){
  219. Materialize.toast('Error connection.',2000);
  220. });
  221. }else{
  222. Materialize.toast("Fail to change password.", 2000);
  223. }
  224. },function(){
  225. Materialize.toast("Error connection.", 2000);
  226. });
  227. }
  228. });
  229. }
  230.  
  231. function ListCaseCtrl($scope, $rootScope, $routeParams, WebServices, Incident,storage, $location,pendingRequests, $filter, $timeout, Idle){
  232. $scope.$on('IdleTimeout', function() {
  233. Idle.unwatch();
  234. storage.set('redirectUrl',$location.url());
  235. $location.path('/blocked').replace();
  236. });
  237.  
  238. $scope.$on('Keepalive', function() {
  239. storage.set('idle',storage.get('ngIdle.expiry').time);
  240. });
  241.  
  242. $scope.$on('$routeChangeSuccess', function () {
  243. $('.button-collapse').sideNav();
  244. $('#sidenav-overlay').remove();
  245. $('ul.tabs').tabs();
  246.  
  247. $scope.openInputCaseForm = function(){
  248. storage.set('dataInputCase','');
  249. $location.path('/inputcase').replace();
  250. }
  251.  
  252. $scope.order = function(predicate) {
  253. $timeout(function(){
  254. $scope.$apply(function(){
  255. $scope.predicate = predicate;
  256. var value = $scope.currentActive;
  257. var sort = predicate == "-priorityVal" ? "Sorting case by priority" : "Sorting case by created on";
  258. window.plugins.toast.show(sort, 'short', 'bottom',
  259. function(a){
  260.  
  261. },
  262. function(b){
  263.  
  264. });
  265. $scope.reLoadListByOrder();
  266. /*
  267. switch(value){
  268. case 'all' :
  269. //$scope.incidentList = $filter('orderBy')($scope.incidentList, $scope.predicate);
  270. break;
  271. case 'mycase' :
  272. //$scope.mycaseList = $filter('orderBy')($scope.mycaseList, $scope.predicate)
  273. break;
  274. case 'outstanding' :
  275. //$scope.outstandingList = $filter('orderBy')($scope.outstandingList, $scope.predicate)
  276. break;
  277. }*/
  278. });
  279. })
  280. };
  281.  
  282. $scope.currentActive = 'all';
  283. $scope.busyLoading = false;
  284. $scope.notFoundCase = false;
  285.  
  286. $scope.totalAllCaseList = 0;
  287. $scope.totalMyCaseList = 0;
  288. $scope.totalOutstandingList = 0;
  289.  
  290. $scope.checkIfOutdated = function(value){
  291. var a = moment();
  292. var b = moment(value);
  293. if(a.diff(b) > 0) return true;
  294. else return false;
  295. }
  296.  
  297. $scope.checkNewVersion = function(){
  298. Materialize.toast("SQA is checking update..",2000);
  299. var oldVersion = storage.get('sqaVersion');
  300. WebServices.SQA.checkingNewVersion(oldVersion).then(function(result){
  301. var result = result.data;
  302. Materialize.toast(result.message,2000);
  303. if(result.status == "Update"){
  304. //calling download java
  305. storage.set('sqaVersion',result.result)
  306. }
  307. },function(){
  308. Materialize.toast('Fail to check new version, please check the connection.',2000);
  309. });
  310. }
  311.  
  312. $scope.sameDepartment = function(value){
  313. var userDepartment = storage.get('userProfile').departmentUser.guid;
  314. if(value != userDepartment) return true;
  315. else return false;
  316. }
  317.  
  318. $scope.signOut = function(){
  319. WebServices.Account.Logout().then(function(result){
  320. storage.set('userProfile','');
  321. storage.set('userToken','');
  322. storage.set('hasExecuted','');
  323. storage.set('fileList','');
  324. storage.set('currentDetail','');
  325. storage.set('changedIndex',-1);
  326. /*var userGuid="";
  327. var userDepartmentGuid="";
  328. var roleValues = "";
  329. var groupPhases = [];
  330.  
  331. var param = [userGuid,userDepartmentGuid,roleValues,groupPhases];
  332.  
  333. window.plugins.parselogin.updateParseObject(param,function(){
  334.  
  335. },function(){
  336.  
  337. });*/
  338.  
  339. Idle.unwatch();
  340. $location.path('/login').replace();
  341. },function(){
  342. Materialize.toast('Error connection.',2000);
  343. });
  344. }
  345.  
  346. $scope.isInfiniteScrollDisabled = false;
  347. $scope.currentPage = 0;
  348.  
  349. $scope.incidentList = [];
  350.  
  351. $scope.fromNow = function(value){
  352. var today = moment().format("DD/MM/YYYY");
  353. if(today == value)return "Today";
  354. else return moment(value,"DD/MM/YYYY").fromNow();
  355. }
  356.  
  357. $scope.getTimePart = function(value){
  358. return moment(value).format("DD/MM/YYYY HH:mm");
  359. }
  360.  
  361. $scope.loadDetail = function(value){
  362.  
  363. var currentDetail = [];
  364.  
  365. currentDetail.push(value);
  366.  
  367. WebServices.Incident.GetDetailListV2({
  368. guid : value.caseid,
  369. ownerid : storage.get('userProfile').id
  370. }).then(function(result){
  371. var result = result.data;
  372. if(result.status == "Success"){
  373. $scope.incidentList = [];
  374. $scope.tempIncidentList = [];
  375. $scope.outstandingList = [];
  376. $scope.mycaseList = [];
  377. $scope.currentPage = 0;
  378. $scope.totalAllCaseList = 0;
  379. $scope.totalMyCaseList = 0;
  380. $scope.totalOutstandingList = 0;
  381. $scope.isInfiniteScrollDisabled = false;
  382. $scope.predicate = '-priorityVal';
  383. storage.set('currentDetail',result.result);
  384. storage.set('redirectUrl','/listcase');
  385. $location.path('/detailcase').replace();
  386. }else{
  387. Materialize.toast('Detail Case not found',2000);
  388. }
  389. },function(){
  390. Materialize.toast("Error connection.", 2000);
  391. });
  392. }
  393.  
  394. $scope.reLoadListByOrder = function(){
  395. $scope.incidentList = [];
  396. $scope.outstandingList = [];
  397. $scope.mycaseList = [];
  398. $scope.tempIncidentList = [];
  399. $scope.currentPage = 0;
  400. $scope.totalAllCaseList = 0;
  401. $scope.totalMyCaseList = 0;
  402. $scope.totalOutstandingList = 0;
  403. $scope.isInfiniteScrollDisabled = false;
  404. $scope.loadCase();
  405. }
  406.  
  407. $scope.reLoadList = function(){
  408. $scope.incidentList = [];
  409. $scope.outstandingList = [];
  410. $scope.mycaseList = [];
  411. $scope.tempIncidentList = [];
  412. $scope.currentPage = 0;
  413. $scope.totalAllCaseList = 0;
  414. $scope.totalMyCaseList = 0;
  415. $scope.totalOutstandingList = 0;
  416. $scope.isInfiniteScrollDisabled = false;
  417. $scope.predicate = '-priorityVal';
  418. $scope.loadCase();
  419. }
  420.  
  421. var userData = storage.get('userProfile');
  422.  
  423. $scope.loadListType = function(value){
  424. $scope.currentActive = value;
  425. pendingRequests.cancelAll();
  426. $scope.reLoadList();
  427. }
  428.  
  429. $scope.loadCase = function(){
  430. var value = $scope.currentActive;
  431. WebServices.Incident.GetAllCase({
  432. startpos : $scope.tempIncidentList.length == 0 ? 0 : $scope.currentPage,
  433. ownerCase : storage.get('userProfile').id,
  434. typeSort : $scope.predicate == "-priorityVal" ? 2 : 1,
  435. },value).then(function(result){
  436. if(result.status== "Success"){
  437. switch(value){
  438. case 'all' :
  439. if($scope.tempIncidentList.length == 0){
  440. $scope.tempIncidentList = result.result;
  441. //$scope.incidentList = result.result;
  442. }else{
  443. angular.forEach(result.result, function(item) {
  444. item.createdOn = new Date(item.createdOn);
  445. $scope.tempIncidentList.push(item);
  446. //$scope.incidentList.push(item);
  447. });
  448. }
  449.  
  450. if($scope.currentPage == 0){
  451. $scope.totalAllCaseList = result.totalcase;
  452. }
  453. $scope.incidentList = $scope.tempIncidentList;//$filter('orderBy')($scope.tempIncidentList, $scope.predicate);
  454. break;
  455. case 'mycase' :
  456. /*if($scope.mycaseList.length == 0){
  457. $scope.mycaseList = result.result;
  458. }else{
  459. angular.forEach(result.result, function(item) {
  460. item.createdOn = new Date(item.createdOn);
  461. $scope.mycaseList.push(item);
  462. });
  463. }
  464.  
  465. if($scope.currentPage == 0){
  466. $scope.totalMyCaseList = result.totalcase;
  467. $scope.mycaseList = $filter('orderBy')($scope.mycaseList, $scope.predicate);
  468. }
  469. */
  470. if($scope.tempIncidentList.length == 0){
  471. $scope.tempIncidentList = result.result;
  472. //$scope.incidentList = result.result;
  473. }else{
  474. angular.forEach(result.result, function(item) {
  475. item.createdOn = new Date(item.createdOn);
  476. $scope.tempIncidentList.push(item);
  477. //$scope.incidentList.push(item);
  478. });
  479. }
  480.  
  481. if($scope.currentPage == 0){
  482. $scope.totalMyCaseList = result.totalcase;
  483. }
  484. $scope.mycaseList = $scope.tempIncidentList;//$filter('orderBy')($scope.tempIncidentList, $scope.predicate);
  485. break;
  486. case 'outstanding' :
  487. /*if($scope.outstandingList.length == 0){
  488. $scope.outstandingList = result.result;
  489. }else{
  490. angular.forEach(result.result, function(item) {
  491. item.createdOn = new Date(item.createdOn);
  492. $scope.outstandingList.push(item);
  493. });
  494. }
  495.  
  496. if($scope.currentPage == 0){
  497. $scope.totalOutstandingList = result.totalcase;
  498. $scope.outstandingList = $filter('orderBy')($scope.outstandingList, $scope.predicate);
  499. }*/
  500.  
  501. if($scope.tempIncidentList.length == 0){
  502. $scope.tempIncidentList = result.result;
  503. //$scope.incidentList = result.result;
  504. }else{
  505. angular.forEach(result.result, function(item) {
  506. item.createdOn = new Date(item.createdOn);
  507. $scope.tempIncidentList.push(item);
  508. //$scope.incidentList.push(item);
  509. });
  510. }
  511.  
  512. if($scope.currentPage == 0){
  513. $scope.totalOutstandingList = result.totalcase;
  514. }
  515. $scope.outstandingList = $scope.tempIncidentList;//$filter('orderBy')($scope.tempIncidentList, $scope.predicate);
  516.  
  517. break;
  518. }
  519. }else{
  520. $scope.isInfiniteScrollDisabled = true;
  521. }
  522. },function(){
  523. //Materialize.toast("Error connection.", 2000);
  524. });
  525. }
  526.  
  527. $scope.reLoadList();
  528.  
  529. $scope.addMoreToList = function(){
  530. $scope.currentPage++;
  531. $scope.loadCase();
  532. }
  533. });
  534. }
  535.  
  536. function NotificationCtrl($scope,$rootScope, $routeParams,WebServices, User, storage, $location, pendingRequests, Idle, $window){
  537. pendingRequests.cancelAll();
  538. $scope.$on('$routeChangeSuccess', function () {
  539. $('#sidenav-overlay').remove();
  540.  
  541. $scope.doClearAllNotification = function(){
  542. $('#deleteconfirmation').openModal();
  543. }
  544.  
  545. $scope.doBack = function(){
  546. var redirectUrl = storage.get('redirectUrl');
  547. if(!angular.isUndefined(redirectUrl) && redirectUrl != ''){
  548. storage.set('redirectUrl','');
  549. console.log(redirectUrl);
  550. if(redirectUrl == '/') redirectUrl = '/listcase';
  551. $location.path(redirectUrl).replace();
  552. }
  553. else $location.path('/listcase').replace();
  554. }
  555.  
  556. $scope.countChecked = function(){
  557. return _.filter($scope.checkeditem,function(item){return item.checkeditem == true;}).length;
  558. }
  559.  
  560. $scope.setAllNotifChecked = function(toggle){
  561. for(var i = 0; i<$scope.checkeditem.length ; i++){
  562. $scope.checkeditem[i].checkeditem = toggle;
  563. }
  564. }
  565.  
  566. $scope.clearAllNotification = function(){
  567. $('#deleteconfirmation').closeModal();
  568. Materialize.toast('Deleting notification..',1000);
  569.  
  570. $scope.checkeditem = _.filter($scope.checkeditem,function(item){return item.checkeditem == true;});
  571.  
  572. WebServices.Account.deleteAllNotification($scope.checkeditem).then(function(){
  573. Materialize.toast('Succesfully delete notification(s)',2000);
  574. $scope.reLoadList();
  575. });
  576. }
  577.  
  578. $scope.loadDetail = function(value){
  579. WebServices.Incident.GetDetailListV2({
  580. guid : value,
  581. ownerid : storage.get('userProfile').id
  582. }).then(function(result){
  583. var result = result.data;
  584. if(result.status == "Success"){
  585. storage.set('currentDetail',result.result);
  586. storage.set('redirectUrl','/notificationlist');
  587. $location.path('/detailcase').replace();
  588. }else{
  589. Materialize.toast('Fail to get detail case',2000);
  590. }
  591. },function(){
  592. Materialize.toast("Error connection.", 2000);
  593. });
  594. }
  595.  
  596. $scope.totalAllNotification = 0;
  597. $scope.notificationList = [];
  598. $scope.currentPage = 0;
  599. $scope.totalAllNotification = 0;
  600. $scope.isInfiniteScrollDisabled = false;
  601.  
  602. $scope.loadNotification = function(){
  603. pendingRequests.cancelAll();
  604. WebServices.Account.GetAllNotification({
  605. startpos : $scope.currentPage,
  606. ownerCase : storage.get('userProfile').id
  607. }).then(function(result){
  608. result = result.data;
  609. if(result.status== "Success"){
  610. if($scope.notificationList.length == 0){
  611. $scope.notificationList = result.result;
  612.  
  613. angular.forEach($scope.notificationList, function(item) {
  614. $scope.checkeditem.push({checkeditem : false, notifid : item.notifid});
  615. });
  616.  
  617. }else{
  618. angular.forEach(result.result, function(item) {
  619. $scope.notificationList.push(item);
  620. $scope.checkeditem.push({checkeditem : false, notifid : item.notifid});
  621. });
  622. }
  623.  
  624. if($scope.currentPage == 0){
  625. $scope.totalAllNotification = result.totalcase;
  626. }
  627. }else{
  628. $scope.isInfiniteScrollDisabled = true;
  629. }
  630. })
  631. }
  632.  
  633. $scope.addMoreNotification = function(){
  634. $scope.currentPage++;
  635. $scope.loadNotification();
  636. }
  637.  
  638. $scope.reLoadList = function(){
  639. /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaNotif",function(result){
  640.  
  641. }, function(){
  642. });*/
  643. $rootScope.prefs.remove(function(){},function(){},'sqaNotif');
  644. $scope.notificationList = [];
  645. $scope.checkeditem = [];
  646. $scope.currentPage = 0;
  647. $scope.totalAllNotification = 0;
  648. $scope.isInfiniteScrollDisabled = false;
  649. $scope.loadNotification();
  650. }
  651.  
  652. $scope.$on('IdleTimeout', function() {
  653. Idle.unwatch();
  654. storage.set('redirectUrl',$location.url());
  655. $location.path('/blocked').replace();
  656. });
  657.  
  658. $scope.$on('Keepalive', function() {
  659. storage.set('idle',storage.get('ngIdle.expiry').time);
  660. });
  661.  
  662. $scope.getTimePart = function(value){
  663. return moment(value).format("DD/MM/YYYY HH:mm");
  664. }
  665.  
  666. $scope.reLoadList();
  667. });
  668. }
  669.  
  670. function SearchCaseCtrl($rootScope, $scope, $routeParams, WebServices, storage, $location, pendingRequests,Idle){
  671. $scope.$on('IdleTimeout', function() {
  672. Idle.unwatch();
  673. storage.set('redirectUrl',$location.url());
  674. $location.path('/blocked').replace();
  675. });
  676.  
  677. $scope.$on('Keepalive', function() {
  678. storage.set('idle',storage.get('ngIdle.expiry').time);
  679. });
  680.  
  681. $scope.$on('$routeChangeSuccess', function () {
  682. $('#sidenav-overlay').remove();
  683. $scope.openModal = function(){
  684. $('#modal1').openModal();
  685. }
  686.  
  687. $scope.fromNow = function(value){
  688. var today = moment().format("DD/MM/YYYY");
  689. if(today == value)return "Today";
  690. else return moment(value,"DD/MM/YYYY").fromNow();
  691. }
  692.  
  693. $scope.loadDetail = function(value){
  694. var currentDetail = [];
  695.  
  696. currentDetail.push(value);
  697.  
  698. WebServices.Incident.GetDetailListV2({
  699. guid : value.caseid,
  700. ownerid : storage.get('userProfile').id
  701. }).then(function(result){
  702. var result = result.data;
  703. if(result.status == "Success"){
  704. storage.set('currentDetail',result.result);
  705. $location.path('/detailcase');
  706. }else{
  707. Materialize.toast('Fail to get detail case',2000);
  708. }
  709. },function(){
  710. Materialize.toast("Error connection.", 2000);
  711. });
  712. }
  713.  
  714. $scope.getTimePart = function(value){
  715. return moment(value).format("dd/MM/yyyy HH:mm");
  716. }
  717.  
  718. $scope.currentPage = 0;
  719.  
  720. $scope.SearchForm = {
  721. searchBy : "CaseNumber",
  722. title : "",
  723. startPos : $scope.currentPage
  724. };
  725.  
  726. $scope.filterCase = {
  727. ownerCase : storage.get('userProfile').id,
  728. divisi : storage.get('userProfile').departmentUser.divisiGuid,
  729. }
  730.  
  731. $scope.searchResult = [];
  732.  
  733. $scope.oldTitle = "";
  734. $scope.oldFilterBy = "";
  735.  
  736. $scope.$watch('SearchForm.searchBy',function(){
  737. if($scope.SearchForm.title != ""){
  738. $scope.doSearch($scope.SearchForm);
  739. }
  740. })
  741.  
  742. $scope.doSearch = function(SearchForm){
  743. pendingRequests.cancelAll();
  744. if(SearchForm.title === ""){
  745. Materialize.toast('Search Text must be filled.', 2000);
  746. }else{
  747. if($scope.oldTitle === SearchForm.title && $scope.oldFilterBy === SearchForm.searchBy){
  748. if($scope.incidentList.length > 0) $scope.currentPage=$scope.currentPage+1;
  749. else $scope.currentPage = 0;
  750. $scope.SearchForm.startPos = $scope.currentPage;
  751. }else{
  752. $scope.oldTitle = SearchForm.title;
  753. $scope.oldFilterBy = SearchForm.searchBy;
  754. $scope.currentPage = 0;
  755. $scope.SearchForm.startPos = $scope.currentPage;
  756. $scope.incidentList = [];
  757. }
  758.  
  759. var request = {search : SearchForm, filterCase : $scope.filterCase};
  760. WebServices.Incident.SearchCase(request).then(function(result){
  761. var result = result.data;
  762. if(result.status == "Success"){
  763. if($scope.incidentList.length == 0){
  764. $scope.incidentList = result.result;
  765. }else{
  766. angular.forEach(result.result, function(item) {
  767. $scope.incidentList.push(item);
  768. });
  769. }
  770. }
  771.  
  772. if($scope.incidentList.length == 0){
  773. //Materialize.toast("No cases found", 2000);
  774. $scope.notFoundFlag = true;
  775. $scope.isInfiniteScrollDisabled = true;
  776. }else{
  777. $scope.notFoundFlag = false;
  778. }
  779. },function(){
  780. Materialize.toast("Error connection.", 2000);
  781. });
  782. }
  783. }
  784.  
  785. $scope.addMoreSearchResult = function(){
  786. $scope.currentPage++;
  787. $scope.doSearch($scope.SearchForm);
  788. }
  789. });
  790. }
  791.  
  792. function SignUpCtrl($scope, $rootScope, WebServices,$location,pendingRequests){
  793. $scope.SignUpInput = {
  794. username : '',
  795. password : '',
  796. repassword : ''
  797. }
  798.  
  799. $scope.user = {};
  800.  
  801. $scope.checkEmailResponse = function(value, dataUser){
  802. $scope.checkEmailMessage = value;
  803. if(dataUser){
  804. $scope.user = dataUser;
  805. }
  806. }
  807.  
  808. $scope.checkSignUpResponse = function(value){
  809. $scope.checkSignUpCodeMessage = value;
  810. }
  811.  
  812. $scope.doSignUp = function(){
  813. pendingRequests.cancelAll();
  814. WebServices.Account.SignUp({
  815. _signUp : {
  816. id : $scope.user.id,
  817. UserName : $scope.user.username,
  818. email : $scope.user.email,
  819. passwd : $scope.SignUpInput.passwd
  820. }
  821. }).then(function(result){
  822. var result = result.data;
  823. if(result.status == "Success"){
  824. Materialize.toast("Password set succesfully.", 2000);
  825. $location.path('/login').replace();
  826. }else{
  827. Materialize.toast(result.errMsg, 2000);
  828. }
  829. },function(){
  830. Materialize.toast("Error connection.", 2000);
  831. });
  832. }
  833. }
  834.  
  835. function ForgotPasswordCtrl($rootScope, $scope, WebServices, $location,pendingRequests){
  836. $scope.doSendRequest = function(){
  837. WebServices.Account.ForgotPassword({email:$scope.ForgotPasswordInput.email}).then(function(result){
  838. pendingRequests.cancelAll();
  839. var result = result.data;
  840. if(result.status == "Success"){
  841. Materialize.toast("Your password has been succesfully reset. Please check your email.", 2000);
  842. $location.path('/login').replace();
  843. }else{
  844. Materialize.toast(result.errMsg, 2000);
  845. }
  846. },function(){
  847. Materialize.toast("Error connection.", 2000);
  848. });
  849. }
  850. }
  851.  
  852. function ManageCaseCtrl($rootScope, $scope,$routeParams, WebServices,storage, $location, $timeout, $q, cfpLoadingBar, initialDataForm,initialDataInputCase , pendingRequests, Idle){
  853. $scope.$on('IdleTimeout', function() {
  854. Idle.unwatch();
  855. storage.set('redirectUrl',$location.url());
  856. $location.path('/blocked').replace();
  857. });
  858.  
  859. $scope.$on('Keepalive', function() {
  860. storage.set('idle',storage.get('ngIdle.expiry').time);
  861. });
  862.  
  863. $scope.$on('$routeChangeSuccess', function () {
  864.  
  865. $scope.currLocation = $location.url();
  866. $scope.caseSameTitle = "";
  867. $scope.fileList = [];
  868. storage.set('fileList',$scope.fileList);
  869. $scope.changedIndex = -1;
  870. storage.set('changedIndex',$scope.changedIndex);
  871.  
  872. $scope.doRetryUpload = false;
  873. $scope.hasUpdateCase = false;
  874. $scope.hasUploadAllImages = false;
  875. $scope.inProgress = false;//allProgress
  876. $scope.startProgressImage = false;
  877. $scope.stopProgressImage = true;
  878. $scope.indexImageFailed = [];
  879. $scope.currentIndexImages = 0;
  880. $scope.totalFailedImages = 0;
  881. $scope.doneDescription = "";
  882. $scope.urgentFlag = false;
  883. $scope.undoFlag = false;
  884.  
  885. $('#sidenav-overlay').remove();
  886.  
  887. $scope.doLoading = function(bool){
  888. if(bool){
  889. $('#loadingmodal').openModal();
  890. $scope.loading = true;
  891. }else{
  892. $('#loadingmodal').closeModal();
  893. $scope.loading = false;
  894. }
  895. }
  896.  
  897. $scope.$watch('inProgress',function(){
  898. if($scope.inProgress)$scope.doLoading(true);
  899. else $scope.doLoading(false);
  900. });
  901.  
  902. $scope.$watch('hasUpdateCase',function(){
  903. if($scope.hasUpdateCase && $scope.hasUploadAllImages){
  904. $scope.inProgress = false;
  905. Materialize.toast("Saving case finished.", 2000);
  906. $location.path('/listcase').replace();
  907. }
  908. });
  909.  
  910. $scope.checkLevel = function(){
  911. var test = $scope.InputCase.damageLevel;
  912.  
  913. if(test.Text == 'Urgent')return true;
  914. else return false;
  915. }
  916.  
  917. $scope.$watch('hasUploadAllImages',function(){
  918. if($scope.hasUpdateCase && $scope.hasUploadAllImages){
  919. $scope.inProgress = false;
  920. Materialize.toast("Saving case finished", 2000);
  921. $location.path('/listcase').replace();
  922. }
  923. });
  924.  
  925. $scope.stopProgressImg = function(){
  926. $scope.startProgressImage = false;
  927. $scope.stopProgressImage = true;
  928. $scope.inProgress = false;
  929. if($scope.hasUploadAllImages == false){
  930. angular.forEach($scope.indexImageFailed, function(value) {
  931. $scope.fileList[value].failFlag = true;
  932. });
  933. Materialize.toast("Some image failed to upload",2000);
  934. $('#opsimodal').openModal();
  935. }else{
  936. Materialize.toast("Finish uploading image", 2000);
  937. $location.path('/listcase').replace();
  938. }
  939. }
  940.  
  941. $scope.startProgressImg = function(){
  942. $scope.inProgress = true;
  943. $scope.startProgressImage = true;
  944. $scope.stopProgressImage = false;
  945. }
  946.  
  947. var win = function(){
  948. var max = $scope.doRetryUpload ? $scope.totalFailedImages : storage.get('fileList').length;
  949.  
  950. if($scope.doRetryUpload){
  951. $scope.fileList[$scope.indexImageFailed[$scope.currentIndexImages]].failFlag = false;
  952. $scope.indexImageFailed.splice($scope.currentIndexImages,0);
  953. }
  954.  
  955. if(($scope.currentIndexImages+1) < max){
  956. $scope.currentIndexImages++;
  957. fileUpload($scope.savedcase.Id);
  958. }else{
  959. if($scope.indexImageFailed.length == 0){
  960. $scope.$apply(function(){
  961. $scope.hasUploadAllImages = true;
  962. $scope.stopProgressImg();
  963. });
  964. }else{
  965. $scope.$apply(function(){
  966. $scope.hasUploadAllImages = false;
  967. $scope.stopProgressImg();
  968. $scope.doRetryUpload = false;
  969. $scope.totalFailedImages = $scope.indexImageFailed.length;
  970. });
  971. }
  972. }
  973. };
  974.  
  975. var fail = function(){
  976. var value = -1;
  977. if(!$scope.doRetryUpload){
  978. value = $scope.currentIndexImages;
  979. if(! _.contains($scope.indexImageFailed, value))$scope.indexImageFailed.push(value);
  980. }
  981.  
  982. var max = $scope.doRetryUpload ? $scope.totalFailedImages : storage.get('fileList').length;
  983.  
  984. if(($scope.currentIndexImages+1) < max){
  985. $scope.$apply(function(){
  986. $scope.currentIndexImages++;
  987. fileUpload($scope.savedcase.Id);//agar tetap lanjut proses
  988. });
  989. }else{
  990. $scope.$apply(function(){
  991. $scope.hasUploadAllImages = false;
  992. $scope.doRetryUpload = false;
  993. $scope.totalFailedImages = $scope.indexImageFailed.length;
  994. $scope.stopProgressImg();
  995. });
  996. }
  997. }
  998.  
  999. var fileUpload = function (entityId){
  1000. var files = storage.get('fileList');
  1001. var options = new FileUploadOptions();
  1002. var index = -1;
  1003. if($scope.doRetryUpload){
  1004. index = $scope.indexImageFailed[$scope.currentIndexImages];
  1005. }else{
  1006. index = $scope.currentIndexImages;
  1007. }
  1008.  
  1009. options.fileKey = "file";
  1010.  
  1011. console.log(files[index]);
  1012. console.log(files[index].path);
  1013.  
  1014. options.fileName = files[index].path.substr(files[index].path.lastIndexOf('/')+1);
  1015. options.mimeType = "image/jpeg";
  1016. options.chunkedMode = false;
  1017.  
  1018. var ft = new FileTransfer();
  1019. ft.upload(files[index].path, encodeURI(WebServices.baseUrl +"api/attachment/uploadImage?entityId="+entityId+"&token="+storage.get('userToken')) , win, fail, options);
  1020. }
  1021.  
  1022. $scope.doRetry = function(){
  1023. $('#modal1').closeModal();
  1024. $('#opsimodal').closeModal();
  1025. $scope.doRetryUpload = true;
  1026. $scope.currentIndexImages = 0;
  1027. $scope.startProgressImg();
  1028. fileUpload($scope.savedcase.Id);
  1029. }
  1030.  
  1031. $scope.cancelSaveDone = function(){
  1032. $('#opsimodal').closeModal();
  1033. }
  1034.  
  1035. $scope.cancelSave = function(){
  1036. $('#modal1').closeModal();
  1037. $('#opsimodal').closeModal();
  1038. $scope.inProgress = true;
  1039. WebServices.Incident.deleteCase({
  1040. caseId : $scope.savedcase.Id
  1041. }).then(function(result){
  1042. $scope.hasUpdateCase = false;
  1043. $scope.hasUploadAllImages = false;
  1044. $scope.inProgress = false;//allProgress
  1045. $scope.startProgressImage = false;
  1046. $scope.stopProgressImage = true;
  1047. $scope.indexImageFailed = [];
  1048. $scope.currentIndexImages = 0;
  1049. $scope.totalFailedImages = 0;
  1050. });
  1051. }
  1052.  
  1053. $scope.errorDamageLevel = false;
  1054.  
  1055. var isNullOrEmpty = function(value){
  1056. if(value == null || value === "" || value === "undefined") return true;
  1057. else return false;
  1058. }
  1059.  
  1060. $scope.$watch('InputCase.damageLevel',function(){
  1061. if(isNullOrEmpty($scope.InputCase.damageLevel)){
  1062. $scope.errorborderbottom = {'border-bottom':'1px solid red'};
  1063. }else{
  1064. $scope.errorborderbottom = {};
  1065. }
  1066. });
  1067.  
  1068. $scope.cancelSaveTitle = function(){
  1069. $scope.inProgress = false;
  1070. $('#loadingmodal').closeModal();
  1071. $('#caseconfirmationmodal').closeModal();
  1072. }
  1073.  
  1074. $scope.continueSaveCaseWithoutCheckTitle = function(){
  1075. $scope.formValue = angular.copy($scope.InputCase);
  1076.  
  1077. var paramCheckExistTitle = {
  1078. title : $scope.formValue.floor.floorname + " " + $scope.formValue.location.area + " " + $scope.formValue.item.itemName + " "+ $scope.formValue.damageType.damageTypeName,
  1079. id : ""
  1080. };
  1081.  
  1082. $scope.formValue.title = paramCheckExistTitle.title;
  1083. $scope.formValue.damageLevel = parseInt($scope.formValue.damageLevel.Value);
  1084.  
  1085. $('#loadingmodal').openModal();
  1086. $('#caseconfirmationmodal').closeModal();
  1087.  
  1088. var param = { cases : $scope.formValue};
  1089.  
  1090. Materialize.toast("Saving in progress...",2000);
  1091.  
  1092. WebServices.Incident.SaveCase(param).then(function(result){
  1093. $scope.savedcase = result.data.result;
  1094. if($scope.fileList.length > 0){
  1095. $scope.startProgressImg();
  1096. fileUpload($scope.savedcase.Id);
  1097. }else{
  1098. $scope.inProgress = false;
  1099. Materialize.toast("Saving case finished.", 2000);
  1100. storage.set('dataInputCase',"");
  1101. $location.path('/listcase').replace();
  1102. }
  1103. },function(){
  1104. $scope.inProgress = false;
  1105.  
  1106. Materialize.toast('Please check the connection.',2000);
  1107. });
  1108. }
  1109.  
  1110. $scope.seePreview = function(){
  1111. WebServices.Incident.GetDetailListV2({
  1112. guid : $scope.caseSameTitle,
  1113. ownerid : storage.get('userProfile').id,
  1114. }).then(function(result){
  1115. var result = result.data;
  1116. if(result.status == "Success"){
  1117. storage.set('currentDetail',result.result);
  1118. storage.set('redirectUrl','/inputcase');
  1119. $location.path('/previewcase').replace();
  1120. }else{
  1121. Materialize.toast('Fail to get preview case',2000);
  1122. }
  1123. },function(){
  1124. Materialize.toast("Error connection.", 2000);
  1125. });
  1126. }
  1127.  
  1128. $scope.saveCase = function(){
  1129. pendingRequests.cancelAll();
  1130. $scope.currLocation = $location.url();
  1131.  
  1132. $scope.dataInputCase = {
  1133. InputCase : angular.copy($scope.InputCase),
  1134. optionsetBuilding : angular.copy($scope.optionsetBuilding),
  1135. optionsetType : angular.copy($scope.optionsetType),
  1136. optionsetPriority : angular.copy($scope.optionsetPriority),
  1137. optionsetFloor : angular.copy($scope.optionsetFloor),
  1138. optionsetItem : angular.copy($scope.optionsetItem),
  1139. optionsetCategory : angular.copy($scope.optionsetCategory),
  1140. optionsetArea : angular.copy($scope.optionsetArea),
  1141. optionsetItemDetail :angular.copy($scope.optionsetItemDetail),
  1142. fileList : angular.copy($scope.fileList)
  1143. }
  1144.  
  1145. storage.set('dataInputCase',$scope.dataInputCase);
  1146.  
  1147. if($scope.currLocation == "/inputcase"){
  1148. if($scope.fileList.length == 0) $scope.hasUploadAllImages = true;
  1149. if(!$scope.inProgress){
  1150. $scope.formValue = angular.copy($scope.InputCase);
  1151. 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)){
  1152. Materialize.toast("Please check the field.", 2000);
  1153.  
  1154. angular.forEach($scope.inputcase.$error.required, function(field) {
  1155. field.$dirty = true;
  1156. });
  1157. }else{
  1158. $scope.inProgress = true;
  1159. Materialize.toast("Saving in progress...",2000);
  1160.  
  1161. var paramCheckExistTitle = {
  1162. title : $scope.formValue.floor.floorname + " " + $scope.formValue.location.area + " " + $scope.formValue.item.itemName + " "+ $scope.formValue.damageType.damageTypeName,
  1163. id : ""
  1164. };
  1165.  
  1166. WebServices.Incident.checkExistTitle(paramCheckExistTitle).then(function(result){
  1167. var result = result.data;
  1168.  
  1169. if(result.result === false){
  1170. $scope.formValue.title = paramCheckExistTitle.title;
  1171. $scope.formValue.damageLevel = parseInt($scope.formValue.damageLevel.Value);
  1172.  
  1173. var param = { cases : $scope.formValue};
  1174.  
  1175. WebServices.Incident.SaveCase(param).then(function(result){
  1176. $scope.savedcase = result.data.result;
  1177. if($scope.fileList.length > 0){
  1178. $scope.startProgressImg();
  1179. fileUpload($scope.savedcase.Id);
  1180. }else{
  1181. $scope.inProgress = false;
  1182. Materialize.toast("Saving case finished.", 2000);
  1183. storage.set('dataInputCase',"");
  1184. $location.path('/listcase').replace();
  1185. }
  1186. },function(){
  1187. $scope.inProgress = false;
  1188. Materialize.toast('Please check the connection.',2000);
  1189. });
  1190. }else{
  1191. $scope.caseSameTitle = result.caseid;
  1192. $('#caseconfirmationmodal').openModal();
  1193. $('#loadingmodal').closeModal();
  1194. }
  1195. },function(){
  1196. $scope.inProgress = false;
  1197. Materialize.toast('Please check the connection.',2000);
  1198. });
  1199. }
  1200. }else{
  1201. Materialize.toast("Saving already in progress...",2000);
  1202. }
  1203. }else{
  1204. if($scope.fileList.length == 0) $scope.hasUploadAllImages = true;
  1205. if(!angular.isUndefined($scope.doneDescription) && $scope.doneDescription != ""){
  1206. $scope.descriptionEmptyFlag = false;
  1207. $scope.inProgress = true;
  1208. WebServices.Incident.updateStatusReason({
  1209. entityid : storage.get('currentDetail').caseid,
  1210. nameStatus : "Done",
  1211. valStatus : 4,
  1212. userid : storage.get('userProfile').id,
  1213. desc : $scope.doneDescription
  1214. }).then(function(result){
  1215. $scope.hasUpdateCase = true;
  1216. $scope.savedcase = {Id : storage.get('currentDetail').caseid};
  1217. if($scope.fileList.length > 0){
  1218. $scope.startProgressImg();
  1219. fileUpload($scope.savedcase.Id);
  1220. }else{
  1221. $scope.inProgress = false;
  1222. Materialize.toast("Case has been set to done",2000);
  1223. $location.path('/listcase').replace();
  1224. }
  1225. });
  1226. }else{
  1227. $scope.descriptionEmptyFlag = true;
  1228. Materialize.toast("Please fill the description !",2000);
  1229. }
  1230. }
  1231. }
  1232.  
  1233. $scope.textCategory = "Please select Item Detail First";
  1234. $scope.textType = "Loading Problem Type";
  1235. $scope.textItem = "Please select Problem Type First";
  1236. $scope.textFloor = "Please select Building First";
  1237. $scope.textArea = "Please select Floor first";
  1238. $scope.textDamageLevel = "Select Damage Level";
  1239. $scope.textItemDetail = "Please select Item First";
  1240.  
  1241. $scope.loadFloor = function(guid){
  1242. WebServices.Incident.LoadFloor({buildingGuid : guid}).then(function(result){
  1243. json = result.data;
  1244. $scope.optionsetFloor = [];
  1245. if(json.status == "Success"){
  1246. if(json.result.length == 0){
  1247. $scope.textFloor = "Floor is not available";
  1248. }else{
  1249. $scope.optionsetFloor = [];
  1250. $scope.optionsetFloor = json.result;
  1251. $scope.textFloor = "Select Floor";
  1252. }
  1253. }else{
  1254. $scope.textFloor = "Floor is not available";
  1255. }
  1256. });
  1257. }
  1258.  
  1259. $scope.loadItem = function(guid){
  1260. WebServices.Incident.LoadItem({problemTypeGuid : guid}).then(function(result){
  1261. json = result.data;
  1262. $scope.optionsetItem = [];
  1263. $scope.optionsetItemDetail = [];
  1264. $scope.optionsetCategory = [];
  1265. $scope.InputCase.damageType = "";
  1266. $scope.InputCase.itemDetail = "";
  1267. $scope.InputCase.damageLevel = "";
  1268. if(json.status == "Success"){
  1269. if(json.result.length == 0){
  1270. $scope.textItem = "Item is not available";
  1271. }else{
  1272. $scope.optionsetItem = [];
  1273. $scope.optionsetItem = json.result;
  1274. $scope.textItem = "Select Item";
  1275. }
  1276. }else{
  1277. $scope.textItem = "Item is not available";
  1278. }
  1279. });
  1280. }
  1281.  
  1282. $scope.loadDamageType = function(guid){
  1283. WebServices.Incident.LoadDamageType({itemGuid:guid}).then(function(result){
  1284. json = result.data;
  1285. $scope.optionsetCategory = [];
  1286. $scope.InputCase.damageLevel = "";
  1287. if(json.status == "Success"){
  1288. if(json.result.length == 0){
  1289. $scope.textCategory = "Damage Type is not available";
  1290. }else{
  1291. $scope.optionsetCategory = [];
  1292. $scope.optionsetCategory = json.result;
  1293. $scope.textCategory = "Select Damage Type";
  1294. }
  1295. }else{
  1296. $scope.textCategory = "Damage Type is not available";
  1297. }
  1298. });
  1299. }
  1300.  
  1301. $scope.setDamageLevel = function(){
  1302. $scope.InputCase.urgencydescription = "";
  1303. $scope.chosen = $scope.InputCase.damageType.priorityLevel;
  1304. $scope.InputCase.damageLevel = $scope.optionsetPriority[$scope.getPriorityIndex($scope.chosen)];
  1305. if($scope.InputCase.damageLevel.Text != 'Urgent'){
  1306. $timeout(function(){
  1307. $scope.undoFlag = false;
  1308. $scope.$apply();
  1309. });
  1310. }else{
  1311. $timeout(function(){
  1312. $scope.undoFlag = true;
  1313. $scope.$apply();
  1314. });
  1315. }
  1316. }
  1317.  
  1318. $scope.openUrgency = function(){
  1319. $('#urgencymodal').openModal();
  1320. $scope.InputCase.urgencydescription = "";
  1321. $scope.urgencyFlag=false;
  1322. }
  1323.  
  1324. $scope.setUrgentLevel = function(){
  1325. if($scope.InputCase.urgencydescription != ''){
  1326. $scope.descriptionEmptyFlag = false;
  1327. $scope.chosen = $scope.InputCase.damageType.priorityLevel;
  1328. $scope.InputCase.damageLevel = $scope.optionsetPriority[3];
  1329. $scope.urgentFlag = true;
  1330. $scope.undoFlag = true;
  1331. $('#urgencymodal').closeModal();
  1332. }else{
  1333. $scope.descriptionEmptyFlag = true;
  1334. Materialize.toast("You must fill the reason why urgent.",2000);
  1335. }
  1336. }
  1337.  
  1338. $scope.getCategoryIndex = function(category){
  1339. var returnIndex = -1;
  1340.  
  1341. for(var i=0;i<$scope.optionsetCategory.length; i++){
  1342. var item= $scope.optionsetCategory[i];
  1343. if(item.Text == category){
  1344. returnIndex = i;
  1345. break;
  1346. }
  1347. }
  1348.  
  1349. return returnIndex;
  1350. }
  1351.  
  1352. $scope.getProblemTypeIndex = function(type){
  1353. var returnIndex = -1;
  1354.  
  1355. for(var i=0;i<$scope.optionsetType.length; i++){
  1356. var item= $scope.optionsetType[i];
  1357. if(item.name == type){
  1358. returnIndex = i;
  1359. break;
  1360. }
  1361. }
  1362.  
  1363. return returnIndex;
  1364. }
  1365.  
  1366. $scope.getItemIndex = function(value){
  1367. var returnIndex = -1;
  1368.  
  1369. for(var i=0;i<$scope.optionsetItem.length; i++){
  1370. var item = $scope.optionsetItem[i];
  1371. if(item.itemName == value){
  1372. returnIndex = i;
  1373. break;
  1374. }
  1375. }
  1376.  
  1377. return returnIndex;
  1378. }
  1379.  
  1380. $scope.getAreaIndex = function(area){
  1381. var returnIndex = -1;
  1382.  
  1383. for(var i=0;i<$scope.optionsetArea.length; i++){
  1384. var item= $scope.optionsetArea[i];
  1385. if(item.area == area){
  1386. returnIndex = i;
  1387. break;
  1388. }
  1389. }
  1390.  
  1391. return returnIndex;
  1392. }
  1393.  
  1394. $scope.getPriorityIndex = function(priority){
  1395. var returnIndex = -1;
  1396. for(var i=0;i<$scope.optionsetPriority.length; i++){
  1397. var item = $scope.optionsetPriority[i];
  1398. if(item.Value == priority){
  1399. returnIndex = i;
  1400. break;
  1401. }
  1402. }
  1403.  
  1404. return returnIndex;
  1405. }
  1406.  
  1407. $scope.getFloorIndex = function(floor){
  1408. var returnIndex = -1;
  1409.  
  1410. for(var i=0;i<$scope.optionsetFloor.length; i++){
  1411. var item= $scope.optionsetFloor[i];
  1412. if(item.floorname == floor){
  1413. returnIndex = i;
  1414. break;
  1415. }
  1416. }
  1417.  
  1418. return returnIndex;
  1419. }
  1420.  
  1421. $scope.loadItemDetail = function(guid){
  1422. $scope.textItemDetail = "Loading Item Detail";
  1423. $scope.optionsetItemDetail = [];
  1424.  
  1425. WebServices.Incident.LoadItemDetail({
  1426. itemId:guid,
  1427. }).then(function(result){
  1428. var json = result.data;
  1429. if(json.status == "Success"){
  1430. if(json.result.length == 0){
  1431. $scope.textItemDetail = "Item Detail is not Available";
  1432. }else{
  1433. $scope.textItemDetail = "Select Item Detail";
  1434. $scope.optionsetItemDetail = [];
  1435. $scope.optionsetItemDetail = json.result;
  1436. }
  1437. }else{
  1438. $scope.textItemDetail = "Item Detail is not Available";
  1439. }
  1440. },function(){
  1441. Materialize.toast("Error connection.", 2000);
  1442. });
  1443. }
  1444.  
  1445. $scope.loadArea = function(objForm){
  1446. if(objForm.floor == "undefined" || objForm.building == "undefined"){
  1447. $scope.textArea = "Please make sure you already chosen Floor and Building.";
  1448. }else{
  1449. var floorChosen = objForm.floor.guid;
  1450. var buildingChosen = objForm.building.guid;
  1451. $scope.textArea = "Loading Area";
  1452. $scope.optionsetArea = [];
  1453.  
  1454. WebServices.Incident.GetArea({
  1455. floorGuid:floorChosen,
  1456. buildingGuid : buildingChosen
  1457. }).then(function(result){
  1458. var json = result.data;
  1459. if(json.status == "Success"){
  1460. if(json.result.length == 0){
  1461. $scope.textArea = "Location Not Available";
  1462. }else{
  1463. $scope.textArea = "Select Location";
  1464. $scope.optionsetArea = [];
  1465. $scope.optionsetArea = json.result;
  1466. }
  1467. }else{
  1468. $scope.textArea = "Location Not Available";
  1469. }
  1470. },function(){
  1471. Materialize.toast("Error connection.", 2000);
  1472. });
  1473. }
  1474. }
  1475.  
  1476. $scope.getBuildingIndex = function(building){
  1477. var returnIndex = -1;
  1478. for(var i=0; i<$scope.optionsetBuilding.length ; i++){
  1479. var item = $scope.optionsetBuilding[i];
  1480. if(item.buildingname == building){
  1481. returnIndex = i;
  1482. break;
  1483. }
  1484. }
  1485.  
  1486. return returnIndex;
  1487. }
  1488.  
  1489. $scope.InputCase = {
  1490. building : "",
  1491. floor : "",
  1492. location : "",
  1493. problemType : "",
  1494. item : "",
  1495. damageType : "",
  1496. damageLevel : "",
  1497. ownercase : storage.get('userProfile').id,
  1498. locationDetail : "",
  1499. itemDetail : "",
  1500. damageDetail : "",
  1501. title : "",
  1502. urgencydescription : "",
  1503. };
  1504.  
  1505. $scope.clearForm = function(){
  1506. storage.set('dataInputCase',"");
  1507. $location.path('/listcase').replace();
  1508. }
  1509.  
  1510. $scope.fillForm = function(){
  1511. var index = 0;
  1512.  
  1513. var dataInputCase = initialDataInputCase.InputCase;
  1514.  
  1515. angular.forEach($scope.optionsetBuilding, function(building){
  1516. if(building.guid == dataInputCase.building.guid){
  1517. $scope.InputCase.building = $scope.optionsetBuilding[index];
  1518. }
  1519. index++;
  1520. });
  1521.  
  1522. index = 0;
  1523.  
  1524. angular.forEach($scope.optionsetType, function(type){
  1525. if(type.guid == dataInputCase.problemType.guid){
  1526. $scope.InputCase.problemType = $scope.optionsetType[index];
  1527. }
  1528. index++;
  1529. });
  1530.  
  1531. index = 0;
  1532.  
  1533. angular.forEach($scope.optionsetFloor, function(floor){
  1534. if(floor.guid == dataInputCase.floor.guid){
  1535. $scope.InputCase.floor = $scope.optionsetFloor[index];
  1536. }
  1537. index++;
  1538. });
  1539.  
  1540. index = 0;
  1541.  
  1542. angular.forEach($scope.optionsetArea, function(location){
  1543. if(location.id == dataInputCase.location.id){
  1544. $scope.InputCase.location = $scope.optionsetArea[index];
  1545. }
  1546. index++;
  1547. });
  1548.  
  1549. index = 0;
  1550.  
  1551. angular.forEach($scope.optionsetItem, function(item){
  1552. if(item.id == dataInputCase.item.id){
  1553. $scope.InputCase.item = $scope.optionsetItem[index];
  1554. }
  1555. index++;
  1556. });
  1557.  
  1558. index = 0;
  1559.  
  1560. angular.forEach($scope.optionsetItemDetail, function(itemDetail){
  1561. if(itemDetail.id == dataInputCase.itemDetail.id){
  1562. $scope.InputCase.itemDetail = $scope.optionsetItemDetail[index];
  1563. }
  1564. index++;
  1565. });
  1566.  
  1567. index = 0;
  1568.  
  1569. angular.forEach($scope.optionsetCategory, function(damageType){
  1570. if(damageType.damageGuid == dataInputCase.damageType.damageGuid){
  1571. $scope.InputCase.damageType = $scope.optionsetCategory[index];
  1572. }
  1573. index++;
  1574. });
  1575.  
  1576. $scope.InputCase.damageLevel = dataInputCase.damageLevel;
  1577. }
  1578.  
  1579. if($scope.currLocation == "/inputcase"){
  1580. if(initialDataInputCase == ""){
  1581. $scope.optionsetType = initialDataForm.problemTypes;
  1582. $scope.optionsetBuilding = initialDataForm.buildings;
  1583. $scope.InputCase.building = $scope.optionsetBuilding[0];
  1584. $scope.InputCase.problemType = $scope.optionsetType[0];
  1585. $scope.loadFloor($scope.InputCase.building.guid);
  1586. $scope.loadItem($scope.InputCase.problemType.guid);
  1587. $scope.optionsetPriority = initialDataForm.damageLevels;
  1588. $scope.textType = "Select Problem Type";
  1589. $scope.textBuilding = "Select Building";
  1590. }else{
  1591. $scope.optionsetType = initialDataInputCase.optionsetType;
  1592. $scope.optionsetBuilding = initialDataInputCase.optionsetBuilding;
  1593. $scope.optionsetFloor = initialDataInputCase.optionsetFloor;
  1594. $scope.optionsetItem = initialDataInputCase.optionsetItem;
  1595. $scope.optionsetPriority = initialDataInputCase.optionsetPriority;
  1596. $scope.optionsetCategory = initialDataInputCase.optionsetCategory;
  1597. $scope.optionsetArea = initialDataInputCase.optionsetArea;
  1598. $scope.optionsetItemDetail = initialDataInputCase.optionsetItemDetail;
  1599. $scope.fillForm();
  1600. $scope.fileList = initialDataInputCase.fileList;
  1601. $scope.textType = "Select Problem Type";
  1602. $scope.textBuilding = "Select Building";
  1603. }
  1604. }
  1605.  
  1606. $scope.filterCount = function(){
  1607. var filtered = _.filter($scope.fileList,function(item){
  1608. return item.displayed === true;
  1609. });
  1610.  
  1611. return filtered.length;
  1612. }
  1613.  
  1614. $scope.resetUpload = function(){
  1615. $scope.fileList = [];
  1616. storage.set('fileList',$scope.fileList);
  1617. }
  1618.  
  1619. $scope.changeFile = function(index){
  1620. $scope.changedIndex = index;
  1621. storage.set('changedIndex',$scope.changedIndex);
  1622. storage.set('hasExecuted',false);
  1623. $('#modal1').openModal();
  1624. }
  1625.  
  1626. $scope.deleteFile = function(index){
  1627. var item = $scope.fileList[index];
  1628. if(item.id == '')$scope.fileList.splice(index,1);
  1629. else {
  1630. $scope.fileList[index].displayed = false;
  1631. $scope.fileList[index].isChanged = false;
  1632. }
  1633. storage.set('fileList',$scope.fileList);
  1634. }
  1635.  
  1636. $scope.openModal = function(){
  1637. $scope.changedIndex = -1;
  1638. storage.set('changedIndex',$scope.changedIndex);
  1639. storage.set('hasExecuted',false);
  1640. $('#modal1').openModal();
  1641. }
  1642.  
  1643. pictureSource=navigator.camera.PictureSourceType;
  1644. destinationType=navigator.camera.DestinationType;
  1645.  
  1646. function successCallback(localFileUri){
  1647. $scope.$apply(function(){
  1648. $scope.pathImage = localFileUri;
  1649. console.log($scope.pathImage);
  1650. var hasExecuted = storage.get('hasExecuted');
  1651. if(hasExecuted == false && $scope.pathImage != ''){
  1652. $scope.changedIndex = parseInt(storage.get('changedIndex'));
  1653. if($scope.changedIndex == -1) {
  1654. $scope.fileList.push({
  1655. isChanged : false,
  1656. path : $scope.pathImage,
  1657. id : '',
  1658. displayed : true,
  1659. failFlag : false
  1660. });
  1661. }else{
  1662. $scope.fileList[$scope.changedIndex].isChanged = true;
  1663. $scope.fileList[$scope.changedIndex].path = $scope.pathImage;
  1664. $scope.fileList[$scope.changedIndex].displayed = true;
  1665. }
  1666. $rootScope.prefs.remove(function(result){
  1667. $scope.pathImage = '';
  1668. storage.set('fileList',$scope.fileList);
  1669. storage.set('hasExecuted',true);
  1670. $scope.$apply(function(){
  1671. $scope.fileList = storage.get('fileList');
  1672. })
  1673. },function(){},'sqaImageTempPath');
  1674. /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
  1675. $scope.pathImage = '';
  1676. storage.set('fileList',$scope.fileList);
  1677. storage.set('hasExecuted',true);
  1678. $scope.$apply(function(){
  1679. $scope.fileList = storage.get('fileList');
  1680. })
  1681. }, function(){
  1682. });*/
  1683. }
  1684. });
  1685. }
  1686.  
  1687. function errorCallback(message){
  1688. alert('Failed because: ' + message);
  1689. }
  1690.  
  1691. function onPhotoDataSuccess(value){
  1692. window.FilePath.resolveNativePath(value, successCallback, errorCallback);
  1693. }
  1694.  
  1695. function onPhotoURISuccess(value){
  1696. window.FilePath.resolveNativePath(value, successCallback, errorCallback);
  1697. }
  1698.  
  1699. function onFail(message){
  1700. alert('Failed because: ' + message);
  1701. }
  1702.  
  1703. $scope.openGallery = function(){
  1704. $('#modal1').closeModal();
  1705.  
  1706. /*window.plugins.webintent.startActivity({
  1707. action : window.plugins.webintent.ACTION_PICK,
  1708. type : 'image/*'
  1709. },
  1710. function(){
  1711. //image picker sukses
  1712. },
  1713. function(e){
  1714. }
  1715. );*/
  1716. navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
  1717. destinationType: destinationType.NATIVE_URI,
  1718. sourceType: pictureSource.PHOTOLIBRARY
  1719. });
  1720. }
  1721.  
  1722. $scope.openCamera = function(){
  1723. $('#modal1').closeModal();
  1724.  
  1725. navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
  1726. destinationType: destinationType.NATIVE_URI
  1727. }
  1728. );
  1729.  
  1730. /*window.plugins.webintent.startActivity({
  1731. action : window.plugins.webintent.ACTION_CAMERA,
  1732. type : 'image/*'
  1733. },
  1734. function(){
  1735. //camera sukses
  1736. },
  1737. function(e){
  1738. }
  1739. );*/
  1740. }
  1741.  
  1742. document.addEventListener("resume", onDeviceResumeManageCaseCtrl, false);
  1743.  
  1744. function fileExists(fileEntry){
  1745. fileEntry.file(function(file) {
  1746. var hasExecuted = storage.get('hasExecuted');
  1747. if(hasExecuted == false && $scope.pathImage != ''){
  1748. $scope.changedIndex = parseInt(storage.get('changedIndex'));
  1749. if($scope.changedIndex == -1) {
  1750. $scope.fileList.push({
  1751. isChanged : false,
  1752. path : $scope.pathImage,
  1753. id : '',
  1754. displayed : true,
  1755. failFlag : false
  1756. });
  1757. }else{
  1758. $scope.fileList[$scope.changedIndex].isChanged = true;
  1759. $scope.fileList[$scope.changedIndex].path = $scope.pathImage;
  1760. $scope.fileList[$scope.changedIndex].displayed = true;
  1761. }
  1762. /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
  1763. $scope.pathImage = '';
  1764. storage.set('fileList',$scope.fileList);
  1765. storage.set('hasExecuted',true);
  1766. $scope.$apply(function(){
  1767. $scope.fileList = storage.get('fileList');
  1768. })
  1769. }, function(){
  1770. });*/
  1771. }
  1772. });
  1773.  
  1774. }
  1775.  
  1776. function fileDoesNotExist(){
  1777. /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
  1778. }, function(){
  1779. });*/
  1780. }
  1781.  
  1782. function checkIfFileExists(path){
  1783. var hasExecuted = storage.get('hasExecuted');
  1784. if(!hasExecuted){
  1785. window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
  1786. fileSystem.root.getFile($.url(path).attr("path"), { create: false }, fileExists, fileDoesNotExist);
  1787. }, getFSFail);
  1788. }
  1789. }
  1790.  
  1791. function getFSFail(evt) {
  1792. /*window.plugins.sharedvaluelocalnative.deleteSharedValue("sqaImageTempPath",function(result){
  1793. }, function(){
  1794. });*/
  1795. }
  1796.  
  1797. storage.set('hasExecuted',false);
  1798.  
  1799.  
  1800. });
  1801. }
  1802.  
  1803. function PreviewCaseCtrl($rootScope, $scope, $routeParams, $location, storage, Idle){
  1804. $scope.doBack = function(){
  1805. $location.path('/inputcase').replace();
  1806. }
  1807. $scope.$on('IdleTimeout', function() {
  1808. Idle.unwatch();
  1809. storage.set('redirectUrl',$location.url());
  1810. $location.path('/blocked').replace();
  1811. });
  1812.  
  1813. $scope.$on('Keepalive', function() {
  1814. storage.set('idle',storage.get('ngIdle.expiry').time);
  1815. });
  1816.  
  1817. $scope.$on('$routeChangeSuccess', function () {
  1818. $('#sidenav-overlay').remove();
  1819. });
  1820.  
  1821. $scope.hasLoadSlider = false;
  1822. $scope.slider = {};
  1823.  
  1824. $scope.currentDetail = storage.get('currentDetail');
  1825.  
  1826. $scope.currentDetail = storage.get('currentDetail');
  1827.  
  1828. if($scope.currentDetail.images){
  1829. if($scope.currentDetail.images.length > 0){
  1830. $scope.slider = $('.bxslider').bxSlider({
  1831. infiniteLoop: false,
  1832. //touchEnabled: true,
  1833. hideControlOnEnd: true
  1834. });
  1835. }
  1836. }
  1837.  
  1838. $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
  1839. if(!$scope.hasLoadSlider){
  1840. /*$scope.slider = $('.bxslider').bxSlider({
  1841. infiniteLoop: false,
  1842. //touchEnabled: true,
  1843. //hideControlOnEnd: true
  1844. });*/
  1845. $scope.slider.reloadSlider();
  1846. $scope.hasLoadSlider = true;
  1847. }else{
  1848. $scope.slider.reloadSlider();
  1849. }
  1850.  
  1851. $('.popuplink').magnificPopup({
  1852. type: 'image',
  1853. gallery: {
  1854. enabled: true,
  1855. navigateByImgClick: true,
  1856. preload: [0,1] // Will preload 0 - before current, and 1 after the current image
  1857. },
  1858. });
  1859. });
  1860. }
  1861. function DetailCaseCtrl($rootScope, $scope, $routeParams, $location, WebServices, storage, loadListAssign, loadExtendReasons, Idle){
  1862. $scope.doBack = function(){
  1863. var redirectUrl = storage.get('redirectUrl');
  1864. if(angular.isUndefined(redirectUrl))$location.path('/listcase').replace();
  1865. else $location.path(redirectUrl).replace();
  1866. }
  1867. $scope.$on('IdleTimeout', function() {
  1868. Idle.unwatch();
  1869. storage.set('redirectUrl',$location.url());
  1870. $location.path('/blocked').replace();
  1871. });
  1872.  
  1873. $scope.$on('Keepalive', function() {
  1874. storage.set('idle',storage.get('ngIdle.expiry').time);
  1875. });
  1876.  
  1877. $scope.$on('$routeChangeSuccess', function () {
  1878. $('#sidenav-overlay').remove();
  1879. $scope.userProfile = storage.get('userProfile');
  1880. $scope.statusCase = 0;
  1881. $scope.statusName = '';
  1882. $scope.description = '';
  1883. $scope.PersonToAssign = '';
  1884. $scope.loading = false;
  1885.  
  1886. function suggest_state(term) {
  1887. var q = term.toLowerCase().trim();
  1888. var results = [];
  1889. // Find first 10 states that start with `term`.
  1890. for (var i = 0; i < $scope.listPeopleToAssign.length && results.length < 10; i++) {
  1891. var look = $scope.listPeopleToAssign[i];
  1892. if (look.fullName.toLowerCase().indexOf(q) === 0)results.push({
  1893. label: look.fullName,
  1894. value: look.fullName,
  1895. obj : look
  1896. });
  1897. }
  1898.  
  1899. return results;
  1900. }
  1901.  
  1902. $scope.autocomplete_options = {
  1903. suggest: suggest_state,
  1904. on_select: function (selected) {
  1905. $scope.PersonToAssign = selected.obj;
  1906. }
  1907. };
  1908.  
  1909. $('.modal-trigger').leanModal({
  1910. dismissible: false, // Modal can be dismissed by clicking outside of the modal
  1911. });
  1912.  
  1913. if(!angular.isUndefined(loadExtendReasons.data)){
  1914. $scope.listExtendReason = loadExtendReasons.data.result;
  1915. }else{
  1916. $scope.listExtendReason = [];
  1917. }
  1918.  
  1919. $scope.listPeopleToAssign = loadListAssign;
  1920.  
  1921. $scope.openUpdateCasePage = function(object){
  1922. $location.path('/updatecase').replace();
  1923. }
  1924.  
  1925. $scope.sameHandleByPerson = function(){
  1926. var userId = storage.get('userProfile').id;
  1927. if($scope.currentDetail.handledBy == userId) return true;
  1928. else return false;
  1929. }
  1930.  
  1931. $scope.checkUserAccess = function(){
  1932. var result = false;
  1933. var userDepartmentGuid = storage.get('userProfile').departmentUser.guid;
  1934. var userDivisiGuid = storage.get('userProfile').departmentUser.divisiGuid;
  1935.  
  1936. var position = storage.get('userProfile').positionname.toLowerCase();
  1937. switch(position){
  1938. case 'super user' :
  1939. case 'gm':
  1940. case 'head':
  1941. if($scope.currentDetail.department){
  1942. if($scope.currentDetail.department.divisiGuid == userDivisiGuid) result = true;
  1943. else return false;
  1944. }else return false;
  1945. break;
  1946. case 'manager':
  1947. case 'supervisor':
  1948. case 'executor':
  1949. if($scope.currentDetail.department){
  1950. if($scope.currentDetail.department.guid == userDepartmentGuid) result = true;
  1951. }
  1952. else return false;
  1953. break;
  1954. case 'auditor' : result = true;break;
  1955. case 'reporter' : result = false;break;
  1956. }
  1957. return result;
  1958. }
  1959.  
  1960. $scope.PersonToAssign = '';
  1961.  
  1962. $scope.doAssign = function(){
  1963. if($scope.PersonToAssign == ''){
  1964. $scope.descriptionEmptyFlag = true;
  1965. Materialize.toast('Please type name person to assign first.',2000);
  1966. }else{
  1967. $('#modal1').closeModal();
  1968. $scope.doLoading(true);
  1969.  
  1970. WebServices.Incident.doAssign({
  1971. param : {
  1972. fromId : storage.get('userProfile').id,
  1973. toId : $scope.PersonToAssign.id,
  1974. caseId : $scope.currentDetail.caseid
  1975. }
  1976. }).then(function(result){
  1977. result = result.data;
  1978. if(result.status == "Success"){
  1979. Materialize.toast("Case assigned succesfully.", 2000);
  1980.  
  1981. WebServices.Incident.GetDetailListV2({
  1982. guid : $scope.currentDetail.caseid,
  1983. ownerid : storage.get('userProfile').id
  1984. }).then(function(result){
  1985. $scope.doLoading(false);
  1986. $scope.description = '';
  1987. var result = result.data;
  1988.  
  1989. if(result.status == "Success"){
  1990. storage.set('currentDetail',result.result);
  1991. $scope.currentDetail = storage.get('currentDetail');
  1992. }else{
  1993. Materialize.toast('Fail to Update case',2000);
  1994. }
  1995. },function(){
  1996. Materialize.toast("Error connection.", 2000);
  1997. });
  1998. }else{
  1999. Materialize.toast(result.errMsg,2000);
  2000. }
  2001. },function(){
  2002. Materialize.toast("Error connection.", 2000);
  2003. });
  2004. }
  2005. }
  2006.  
  2007. function isValidDate(str) {//2015-07-30 00:30
  2008. var d = moment(str,'YYYY-MM-DD hh:mm');
  2009. if(d == null || !d.isValid()) return false;
  2010. else return true;
  2011. }
  2012.  
  2013. $scope.doExtend = function(){
  2014. var error = 0;
  2015. if($scope.description == ''){
  2016. error++;
  2017. $scope.descriptionEmptyFlag = true;
  2018. }
  2019. else $scope.descriptionEmptyFlag = false;
  2020.  
  2021. if(!isValidDate($scope.extendDate)){
  2022. error++;
  2023. $scope.validDateFlag = true;
  2024. }
  2025. else $scope.validDateFlag = false;
  2026.  
  2027. if($scope.ExtendReasons == '' || angular.isUndefined($scope.ExtendReasons)){
  2028. error++;
  2029. $scope.extendNotSelectedFlag = true;
  2030. }else{
  2031. $scope.extendNotSelectedFlag = false;
  2032. }
  2033.  
  2034. if(error > 0){
  2035. Materialize.toast('Please check the field.',2000);
  2036. }else{
  2037. $('#modal4').closeModal();
  2038. $scope.doLoading(true);
  2039.  
  2040. var d = moment($scope.extendDate,'YYYY-MM-DD hh:mm');
  2041.  
  2042. WebServices.Incident.doExtend({
  2043. param : {
  2044. date : d.toISOString(),
  2045. description : $scope.description,
  2046. caseid : $scope.currentDetail.caseid,
  2047. whoExtend : storage.get('userProfile').id,
  2048. extendReason : $scope.ExtendReasons
  2049. }
  2050. }).then(function(result){
  2051. result = result.data;
  2052. if(result.status == "Success"){
  2053. Materialize.toast("Case has been succesfully extended. Updating case.. ", 2000);
  2054. WebServices.Incident.GetDetailListV2({
  2055. guid : $scope.currentDetail.caseid,
  2056. ownerid : storage.get('userProfile').id
  2057. }).then(function(result){
  2058. $scope.doLoading(false);
  2059. $scope.description = '';
  2060. var result = result.data;
  2061. if(result.status == "Success"){
  2062. storage.set('currentDetail',result.result);
  2063. $scope.currentDetail = storage.get('currentDetail');
  2064. }else{
  2065. Materialize.toast('Fail to update case',2000);
  2066. }
  2067. },function(){
  2068. Materialize.toast("Error connection.", 2000);
  2069. });
  2070. }else{
  2071. Materialize.toast(result.errMsg,2000);
  2072. }
  2073. },function(){
  2074. Materialize.toast("Error connection.", 2000);
  2075. });
  2076. }
  2077. }
  2078.  
  2079. $scope.hasLoadSlider = false;
  2080. $scope.slider = {};
  2081.  
  2082.  
  2083. $(".dropdown-button").dropdown();
  2084.  
  2085. $scope.currentDetail = storage.get('currentDetail');
  2086.  
  2087. if($scope.currentDetail.images){
  2088. if($scope.currentDetail.images.length > 0){
  2089. $scope.slider = $('.bxslider').bxSlider({
  2090. infiniteLoop: false,
  2091. //touchEnabled: true,
  2092. hideControlOnEnd: true
  2093. });
  2094. }
  2095. }
  2096.  
  2097. $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
  2098. if(!$scope.hasLoadSlider){
  2099. /*$scope.slider = $('.bxslider').bxSlider({
  2100. infiniteLoop: false,
  2101. //touchEnabled: true,
  2102. //hideControlOnEnd: true
  2103. });*/
  2104. $scope.slider.reloadSlider();
  2105. $scope.hasLoadSlider = true;
  2106. }else{
  2107. $scope.slider.reloadSlider();
  2108. }
  2109.  
  2110. $('.popuplink').magnificPopup({
  2111. type: 'image',
  2112. gallery: {
  2113. enabled: true,
  2114. navigateByImgClick: true,
  2115. preload: [0,1] // Will preload 0 - before current, and 1 after the current image
  2116. },
  2117. });
  2118. });
  2119.  
  2120. $scope.openModal = function(){
  2121. $('#modal1').openModal();
  2122. }
  2123.  
  2124. $scope.checkIsAssigned = function(){
  2125. return ($scope.currentDetail.isAssigned == null || $scope.currentDetail.isAssigned == '' || $scope.currentDetail.isAssigned == false)
  2126. }
  2127.  
  2128. $scope.checkIsExtended = function(){
  2129. return ($scope.currentDetail.isExtended == null || $scope.currentDetail.isExtended == '' || $scope.currentDetail.isExtended == false)
  2130. }
  2131.  
  2132. $scope.closeModal = function(){
  2133. $('#modal1').closeModal();
  2134. }
  2135.  
  2136. $scope.doLoading = function(bool){
  2137. if(bool){
  2138. $('#loadingmodal').openModal();
  2139. $scope.loading = true;
  2140. }else{
  2141. $('#loadingmodal').closeModal();
  2142. $scope.loading = false;
  2143. }
  2144. }
  2145.  
  2146. $scope.doUpdateStatus = function(){
  2147. if($scope.description != "" ){
  2148. $('#modal3').closeModal();
  2149. $scope.doLoading(true);
  2150. WebServices.Incident.updateStatusReason({
  2151. entityid : $scope.currentDetail.caseid,
  2152. nameStatus : $scope.statusName,
  2153. valStatus : $scope.statusCase,
  2154. userid : storage.get('userProfile').id,
  2155. desc : $scope.description
  2156. }).then(function(result){
  2157. WebServices.Incident.GetDetailListV2({
  2158. guid : $scope.currentDetail.caseid,
  2159. ownerid : storage.get('userProfile').id
  2160. }).then(function(result){
  2161. $scope.doLoading(false);
  2162. $scope.description = '';
  2163. var result = result.data;
  2164. if(result.status == "Success"){
  2165. storage.set('currentDetail',result.result);
  2166. $scope.currentDetail = storage.get('currentDetail');
  2167. }else{
  2168. Materialize.toast('Fail to update Case',2000);
  2169. }
  2170. },function(){
  2171. Materialize.toast("Error connection.", 2000);
  2172. });
  2173. });
  2174. }else{
  2175. $scope.descriptionEmptyFlag = true;
  2176. Materialize.toast("Please fill the description !",2000);
  2177. }
  2178.  
  2179. }
  2180.  
  2181. $('*[name=datetimepicker]').appendDtpicker({
  2182. "futureOnly": true,
  2183. "minTime":"00:00",
  2184. "maxTime":"23:30",
  2185. "timelistScroll": false,
  2186. "calendarMouseScroll": false,
  2187. "autodateOnStart": false
  2188. });
  2189.  
  2190. $scope.openModalByID = function(id){
  2191. $('#'+id).openModal();
  2192. }
  2193.  
  2194. $scope.getTimePart = function(value){
  2195. var momentValue = moment(value).format("DD/MM/YYYY HH:mm");
  2196. if(momentValue == "Invalid date"){
  2197. return " - ";
  2198. }else{
  2199. return momentValue;
  2200. }
  2201. }
  2202. });
  2203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement