survey.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. define(['app'], function (app) {
  2. app.controller('SurveyCtrl', function ($scope,$rootScope,AppData,$location) {
  3. $rootScope.menucont = true;
  4. $rootScope.pageLoadComp = false;
  5. $scope.formLoad = false;
  6. $scope.listFound = false;
  7. $scope.pageData = surveyData[$rootScope.selLanguage];
  8. $scope.itemdetail = [];
  9. $scope.selectedList = [];
  10. //$scope.modelData = [];
  11. $scope.zoneList = [];
  12. $scope.stateList = [];
  13. $scope.cityList = [];
  14. $scope.dealerList = [];
  15. $scope.expiredtype = [];
  16. $scope.stateVisible = false;
  17. $scope.cityVisible = false;
  18. $scope.dealerVisible = false;
  19. //$scope.isCategoryVisible = true;
  20. $scope.isExpiredRowVisible = false;
  21. $scope.isExpiredDaysVisible = false;
  22. $scope.isfirst = false;
  23. $scope.selectedIndex = null;
  24. $rootScope.cofirmWindow = false;
  25. $rootScope.modalpublishShown =false;
  26. $scope.search_show = true;
  27. $scope.url = "../senddata/log/";
  28. $scope.pageurl = "../senddata/survey/";
  29. $scope.exporturl = "../senddata/export/";
  30. $scope.commonurl = "../senddata/common/";
  31. $scope.search_box = true;
  32. $scope.submenu = $scope.pageData.sidemenu;
  33. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  34. $scope.tblheading = $rootScope.sideselect.headingText;
  35. //pagination
  36. $scope.viewby = '10';
  37. $scope.currentPage = 1;
  38. $scope.itemsPerPage = $scope.viewby;
  39. $scope.maxSize = 5; //Number of pager buttons to show
  40. // $scope.formtitle = "Add Survey";
  41. //Check Session//
  42. $scope.formData = {}
  43. $rootScope.formData = {}
  44. $scope.formData.ismenuload = "Yes";
  45. if($rootScope.items == undefined || $rootScope.items == null){
  46. $scope.formData.ismenuload = "No";
  47. }
  48. $scope.formData.funName = "checksession";
  49. $scope.formData.lang = $rootScope.selLanguage;
  50. $scope.formData.start = 2;
  51. $scope.formData.limit = 5;
  52. //this page Variable//
  53. //$scope.roleitem = null;
  54. $scope.cateitem = null;
  55. $scope.questionitem = null;
  56. $scope.assignquestionitem = [];
  57. $scope.assignquestionnum = [];
  58. AppData.sendData($scope.url,$scope.formData,function(res){
  59. if(res.cont){
  60. if($rootScope.items == undefined || $rootScope.items == null){
  61. $rootScope.items = res.item.control;
  62. }
  63. for(var i = 0; i < $rootScope.items.length; i++){
  64. if($location.path() == $rootScope.items[i].modulepath){
  65. $rootScope.modulename = $rootScope.items[i].modulename;
  66. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  67. }
  68. }
  69. $scope.statusobj = res.item.status;
  70. $rootScope.username = res.item.username;
  71. $scope.listFound = true;
  72. $scope.start_time = $scope.pageData.assessment_publish_time;
  73. $scope.end_time = $scope.pageData.assessment_publish_time;
  74. $scope.surveyList();
  75. }else{
  76. $location.path("/login");
  77. }
  78. })
  79. $scope.surveyList = function(){
  80. $scope.search_show = true;
  81. $scope.searchvalue = ($scope.formData.mymodel!='')?$scope.formData.mymodel : "";
  82. var fobj = {};
  83. fobj.funName = "surveylist";
  84. if($rootScope.sideselect.id == 1){
  85. fobj.pn = $scope.currentPage;
  86. fobj.nr = $scope.itemsPerPage;
  87. }else{
  88. fobj.pn = '';
  89. fobj.nr = '';
  90. }
  91. fobj.lang = $rootScope.selLanguage;
  92. fobj.key = $scope.searchvalue;
  93. $rootScope.pageLoadComp = true;
  94. AppData.sendData($scope.pageurl,fobj,function(res){
  95. $rootScope.pageLoadComp = true;
  96. if(res.cont){
  97. if(res.item!= undefined){
  98. $scope.itemdetail = res.item.survey;
  99. $scope.totalItems = res.item.total_records;
  100. $scope.listFound = true;
  101. $scope.formLoad = false;
  102. $scope.search_box = true;
  103. }
  104. //$scope.formData = {}
  105. }else{
  106. $scope.listFound = false;
  107. $scope.errorMsg = res.mess;
  108. }
  109. //$scope.roleitem=res.item.roleitem;
  110. })
  111. }
  112. $scope.setPage = function (pageNo) {
  113. $scope.currentPage = pageNo;
  114. };
  115. $scope.pageChanged = function() {
  116. $scope.surveyList();
  117. };
  118. $scope.setItemsPerPage = function(num) {
  119. $scope.itemsPerPage = num;
  120. $scope.currentPage = 1; //reset to first page
  121. $scope.surveyList();
  122. }
  123. $scope.filterData = function() {
  124. $scope.surveyList();
  125. }
  126. $scope.listClick = function(obj){
  127. $scope.searchtext='';
  128. $scope.formData={};
  129. $scope.currentPage = 1;
  130. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  131. $scope.formLoad = false;
  132. $rootScope.sideselect = obj;
  133. $scope.selectedIndex = null;
  134. $scope.tblheading = obj.headingText;
  135. $scope.surveyList();
  136. }
  137. $scope.deleterow = function(obj, i){
  138. $scope.formData = obj;
  139. $scope.selectedIndex = i;
  140. $scope.deleteFun();
  141. }
  142. $scope.exportrow = function(obj, i){
  143. $scope.formData = obj;
  144. $scope.selectedIndex = i;
  145. $scope.exportFun();
  146. }
  147. $scope.editrow = function(obj, i){
  148. $scope.formData = obj;
  149. $scope.selectedIndex = i;
  150. $scope.search_box = false;
  151. $scope.listFound = false;
  152. $scope.formLoad = true;
  153. $scope.editFun();
  154. }
  155. $scope.viewTiprow = function(obj, i){
  156. $scope.formData = obj;
  157. $scope.selectedIndex = i;
  158. $scope.viewTipFun();
  159. }
  160. $scope.viewrow = function(obj, i){
  161. $scope.formData = obj;
  162. $scope.selectedIndex = i;
  163. $scope.viewFun();
  164. }
  165. $scope.onSearchChange = function(){
  166. // console.log($scope.formData.mymodel)
  167. $scope.surveyList();
  168. }
  169. $scope.editFun = function(){
  170. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  171. if($scope.selectedIndex != null){
  172. $scope.formLoad = true;
  173. $scope.formAction = 'Edit';
  174. if($scope.sideselect.id==1){
  175. // $scope.formtitle = "Edit Survey";
  176. $scope.modalTitle = "Edit Survey";
  177. $scope.questionList();
  178. $scope.getRole();
  179. $scope.getZone();
  180. $scope.regionList=[]
  181. $scope.formData.zoneList = {};
  182. // $scope.formData.regionList = {};
  183. $scope.formData.dealerList = {};
  184. var obj = {};
  185. obj.funName = "surveydetails";
  186. obj.lang = $rootScope.selLanguage;
  187. obj.assessmentid = $scope.formData.assessmentid;
  188. AppData.sendData($scope.pageurl,obj,function(res){
  189. $rootScope.pageLoadComp = true;
  190. if(res.cont){
  191. if(res.cont){
  192. // console.log(res.item)
  193. $scope.formData=res.item;
  194. $scope.formData.zoneList={}
  195. // $scope.formData.dealerList = {};
  196. // $scope.formData.roleList={};
  197. // $scope.formData.filter_zone=res.item.filter_zone;
  198. if ($scope.formData.filter_zone.length > 0) {
  199. angular.forEach($scope.formData.filter_zone, function (element,index) {
  200. // console.log(element)
  201. $scope.formData.zoneList[element.zone]= true;
  202. if (element != '') {
  203. $scope.zoneChanged(element,index);
  204. }
  205. });
  206. } else {
  207. $scope.stateVisible = false;
  208. $scope.dealerVisible = false;
  209. }
  210. console.log($scope.formData.filter_region,"$scope.formData.filter_region",$scope.formData.filter_dealer,$scope.formData.regionList)
  211. $scope.formData.regionList = {};
  212. if ($scope.formData.filter_region.length > 0) {
  213. angular.forEach($scope.formData.filter_region, function (element,index) {
  214. console.log(element,"region")
  215. $scope.formData.regionList[element.city] = true;
  216. if (element != '') {
  217. $scope.regionChanged(element.city ,index);
  218. }
  219. });
  220. console.log($scope.formData.regionList,"$scope.formData.regionList")
  221. } else {
  222. $scope.dealerVisible = false;
  223. }
  224. $scope.formData.dealerList = {};
  225. if ($scope.formData.filter_dealer.length > 0) {
  226. angular.forEach($scope.formData.filter_dealer, function (element) {
  227. $scope.formData.dealerList[element.dealer_code] = true;
  228. });
  229. }
  230. $scope.formData.roleList = $scope.formData.filter_role_name;
  231. console.log($scope.formData.filter_role_name,"filter_role_name")
  232. }
  233. }else{
  234. }
  235. })
  236. // console.log($scope.formData.filter_zone.length)
  237. }
  238. }else{
  239. $rootScope.modalShown =true;
  240. $rootScope.message=$scope.pageData.errorMsg[0];
  241. }
  242. }
  243. $scope.deleteFun = function(){
  244. if($scope.selectedIndex != null){
  245. $rootScope.cofirmWindow = true;
  246. $rootScope.modalShown =true;
  247. $rootScope.message=$scope.pageData.errorMsg[1];
  248. }else{
  249. $rootScope.modalShown =true;
  250. $rootScope.message=$scope.pageData.errorMsg[0];
  251. }
  252. }
  253. $scope.$on("confirmDelete",function(){
  254. $scope.formData.funName = "deletesurvey";
  255. AppData.sendData($scope.pageurl,$scope.formData,function(res){
  256. if(res.cont){
  257. if($scope.sideselect.id==1){
  258. var index = $scope.itemdetail.indexOf($scope.formData);
  259. if(index != -1){
  260. $scope.itemdetail.splice(index,1);
  261. }
  262. }
  263. $rootScope.modalShown =true;
  264. $rootScope.cofirmWindow = false;
  265. $rootScope.message=(res.mess);
  266. }else{
  267. $rootScope.modalShown =true;
  268. $rootScope.message=(res.mess);
  269. }
  270. })
  271. })
  272. $scope.questionList = function(){
  273. var fobj = {};
  274. fobj.funName = "questions";
  275. fobj.lang = $rootScope.selLanguage;
  276. // fobj.certified=1;
  277. fobj.is_survey=1;
  278. AppData.sendData($scope.commonurl,fobj,function(res){
  279. $rootScope.pageLoadComp = true;
  280. if(res.cont){
  281. if(res.item!= undefined){
  282. $scope.assessment_question = res.item;
  283. console.log($scope.assessment_question)
  284. }
  285. }else{
  286. //$scope.listFound = false;
  287. $scope.errorMsg = res.mess;
  288. }
  289. })
  290. }
  291. $scope.getRole = function () {
  292. var obj = {};
  293. obj.funName = "role";
  294. obj.lang = $rootScope.selLanguage;
  295. obj.type = "dse"
  296. AppData.sendData($scope.commonurl, obj, function (res) {
  297. if (res.cont) {
  298. if (res.item != undefined) {
  299. $scope.role = res.item;
  300. }
  301. }
  302. })
  303. }
  304. $scope.getZone = function () {
  305. var zobj = {};
  306. zobj.funName = "zone";
  307. zobj.lang = $rootScope.selLanguage;
  308. AppData.sendData($scope.commonurl, zobj, function (res) {
  309. if (res.cont) {
  310. if (res.item != undefined) {
  311. $scope.zoneList = res.item;
  312. }
  313. }
  314. })
  315. }
  316. $scope.zoneChanged = function (item,i) {
  317. console.log(item,i,$scope.regionList)
  318. var obj = {};
  319. obj.cont = true;
  320. angular.forEach($scope.regionList,function(cityname,index){
  321. if(item.zone == cityname.title){
  322. angular.forEach(cityname.child,function(city,ind){
  323. for (var k in $scope.formData.regionList) {
  324. if(city == k){
  325. $scope.formData.regionList[k] = false;
  326. }
  327. }
  328. })
  329. $scope.regionList.splice(index,1);
  330. obj.cont = false;
  331. }
  332. })
  333. // $scope.regionList=[]
  334. var fobj = {};
  335. fobj.lang = $rootScope.selLanguage;
  336. fobj.funName = "city";
  337. var zonename = item.zone;
  338. // if($scope.is_edit_region==false){
  339. // }else{
  340. // var zonename = item.toString();
  341. // console.log(zonename)
  342. // $scope.is_edit_region=false;
  343. // }
  344. // console.log(zonename)
  345. // $scope.regionList[zonename] = {};
  346. fobj.zone = (zonename == undefined) ? "" :zonename;
  347. if(obj.cont){
  348. AppData.sendData($scope.commonurl, fobj, function (res) {
  349. $rootScope.pageLoadComp = true;
  350. if (res.cont) {
  351. if (res.item != undefined) {
  352. $scope.stateVisible = true;
  353. // $scope.regionList=[]
  354. var arr=[];
  355. for (var id = 0; id < res.item.length; id++) {
  356. arr.push(res.item[id].city);
  357. }
  358. console.log(res.item,arr,"helloooo",$scope.regionList)
  359. $scope.regionList.push({"title":zonename,"child":arr}) ;
  360. // console.log($scope.regionList)
  361. } else {
  362. $scope.regionList = [];
  363. $scope.dealerList = [];
  364. $scope.stateVisible = false;
  365. $scope.dealerVisible = false;
  366. }
  367. }
  368. });
  369. }else{
  370. // console.log("here")
  371. angular.forEach($scope.dealerList,function(item,index){
  372. for (var k in $scope.formData.regionList) {
  373. if(k == item.title){
  374. // console.log(k,item)
  375. if($scope.formData.regionList[k]==false){
  376. angular.forEach(item.child,function(dealer,ind){
  377. for (var j in $scope.formData.dealerList) {
  378. // console.log(j,dealer)
  379. if(j==dealer.dealer_code){
  380. $scope.formData.dealerList[j]=false;
  381. }
  382. }
  383. })
  384. $scope.dealerList.splice(index,1);
  385. }
  386. }
  387. }
  388. })
  389. }
  390. }
  391. $scope.regionChanged = function (item,i) {
  392. // console.log(item)
  393. var dobj = {};
  394. dobj.cont = true;
  395. console.log($scope.dealerList,"dealerList")
  396. if($scope.dealerList!=undefined){
  397. angular.forEach($scope.dealerList,function(dealername,index){
  398. // console.log(dealername)
  399. if(item == dealername.title){
  400. angular.forEach(dealername.child,function(dealer,ind){
  401. for (var k in $scope.formData.dealerList) {
  402. // console.log(k,dealer)
  403. if(dealer.dealer_code == k){
  404. $scope.formData.dealerList[k] = false;
  405. }
  406. }
  407. })
  408. $scope.dealerList.splice(index,1);
  409. // dobj.cont = false;
  410. }
  411. })
  412. }
  413. // $scope.dealerList=[]
  414. var fobj = {};
  415. fobj.lang = $rootScope.selLanguage;
  416. fobj.funName = "dealer";
  417. var dealer_name = item;
  418. // if($scope.is_edit_dealer==false){
  419. // }else{
  420. // var dealer_name = item.toString();
  421. // $scope.is_edit_dealer= false;
  422. // }
  423. fobj.city = (dealer_name == undefined) ? "" :dealer_name;
  424. if (dobj.cont) {
  425. AppData.sendData($scope.commonurl, fobj, function (res) {
  426. $rootScope.pageLoadComp = true;
  427. if (res.cont) {
  428. if (res.item != undefined) {
  429. $scope.dealerVisible = true;
  430. var arr=[];
  431. for (var id = 0; id < res.item.length; id++) {
  432. var obj={};
  433. obj.dealer_name = res.item[id].dealer_name;
  434. obj.dealer_code = res.item[id].dealer_code;
  435. arr.push(obj);
  436. }
  437. // console.log(obj)
  438. $scope.dealerList.push({"title":dealer_name,"child":arr});
  439. // console.log($scope.dealerList)
  440. } else {
  441. $scope.dealerVisible = false;
  442. $scope.dealerList = [];
  443. }
  444. }
  445. });
  446. }else{
  447. alert("error")
  448. }
  449. }
  450. $scope.addFun = function(){
  451. // $scope.formtitle = "Add Survey";
  452. $scope.modalTitle = "Add survey";
  453. $scope.formData = {}
  454. $scope.formData.assessmenttime = 30;
  455. $scope.formData.questionList = {};
  456. $scope.zoneList = [];
  457. $scope.regionList = [];
  458. $scope.dealerList = [];
  459. $scope.formData.regionList = {};
  460. $scope.formData.dealerList = {};
  461. $scope.search_box = false;
  462. $scope.formLoad = true;
  463. $scope.listFound = false;
  464. $("input#myCheck").attr("disabled", true);
  465. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  466. $scope.formAction = 'Add';
  467. $scope.formLoad = true;
  468. $scope.formData.funName = "addsurvey";
  469. console.log('$scope.formtitle = "Add Survey";',$scope.formtitle)
  470. $scope.question_json = [];
  471. $scope.formData.random_question={};
  472. $scope.formData.is_mandatory={};
  473. $scope.questionList();
  474. $scope.getRole();
  475. $scope.getZone();
  476. }
  477. $scope.quesChange = function(item,i){
  478. // console.log(item)
  479. if(item!=undefined){
  480. angular.forEach($scope.assessment_question,function(val) {
  481. if(item.id == val.id){
  482. // console.log($scope.formData.questionList,val)
  483. $scope.formData.is_mandatory[val.id]='0';
  484. // $scope.formData.questionList[item.id]=true;
  485. }
  486. })
  487. }
  488. }
  489. $scope.totalques = [];
  490. $scope.closeForm = function(){
  491. $scope.formLoad = false;
  492. $scope.formData = {};
  493. $scope.selectedIndex = null;
  494. $scope.search_box = true;
  495. $scope.listFound = true;
  496. $scope.surveyList();
  497. }
  498. $scope.surveySubmit = function(){
  499. if($scope.formAction=="Add"){
  500. $scope.formData.funName = "addsurvey";
  501. }else{
  502. $scope.formData.funName = "editsurvey";
  503. $scope.formData.assessmentid = $scope.formData.assessmentid;
  504. }
  505. $scope.formData.segment=$scope.formData.segment;
  506. if ($scope.formData.cityList != undefined) {
  507. var cityarr = [];
  508. for (k in $scope.formData.cityList) {
  509. if ($scope.formData.cityList[k] == true) {
  510. cityarr.push(k)
  511. }
  512. }
  513. if (cityarr.length != 0) {
  514. $scope.formData.filter_city = cityarr.toString();
  515. }
  516. }
  517. if ($scope.formData.regionList != undefined) {
  518. var statearr = [];
  519. for (k in $scope.formData.regionList) {
  520. if ($scope.formData.regionList[k] == true) {
  521. statearr.push(k)
  522. }
  523. }
  524. if (statearr.length != 0) {
  525. $scope.formData.filter_region = statearr.toString();
  526. }
  527. }
  528. if ($scope.formData.dealerList != undefined) {
  529. var dealerarr = [];
  530. for (k in $scope.formData.dealerList) {
  531. if ($scope.formData.dealerList[k] == true) {
  532. dealerarr.push(k)
  533. }
  534. }
  535. if (dealerarr.length != 0) {
  536. $scope.formData.filter_dealer = dealerarr.toString();
  537. }
  538. }
  539. if ($scope.formData.zoneList != undefined) {
  540. var zonearr = [];
  541. for (k in $scope.formData.zoneList) {
  542. if ($scope.formData.zoneList[k] == true) {
  543. zonearr.push(k)
  544. }
  545. }
  546. if (zonearr.length != 0) {
  547. $scope.formData.filter_zone = zonearr.toString();
  548. }
  549. }
  550. if ($scope.formData.roleList.length != 0) {
  551. var rolearr = [];
  552. for (var id = 0; id < $scope.formData.roleList.length; id++) {
  553. rolearr.push($scope.formData.roleList[id].id)
  554. }
  555. $scope.formData.filter_role = rolearr.toString();
  556. }
  557. var arr=[];
  558. $scope.question_json=[];
  559. for(var h in $scope.formData.questionList){
  560. if($scope.formData.questionList[h]){
  561. $scope.question_json.push({qid:h,is_mandatory:$scope.formData.is_mandatory[h]});
  562. }
  563. }
  564. $scope.formData.question_json = JSON.stringify($scope.question_json);
  565. //Set notification as 1 default
  566. $scope.formData.assessmentnotification = "1"
  567. AppData.sendData($scope.pageurl,$scope.formData,function(res){
  568. if(res.cont){
  569. $rootScope.modalShown =true;
  570. $rootScope.message=(res.mess);
  571. $scope.surveyList();
  572. $scope.selectedIndex = null;
  573. $scope.formLoad = false;
  574. $scope.listFound = true;
  575. }else{
  576. $rootScope.modalShown =true;
  577. $rootScope.message=(res.mess);
  578. }
  579. })
  580. }
  581. });
  582. });