assessment.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. define(['app'], function (app) {
  2. app.controller('AssessmentCtrl', function ($scope, $rootScope, AppData, $location) {
  3. $rootScope.menucont = true;
  4. $rootScope.pageLoadComp = false;
  5. $scope.formLoad = false;
  6. $scope.listFound = false;
  7. $scope.pageData = assessmentData[$rootScope.selLanguage];
  8. console.log($scope.pageData.assessment_publish_time)
  9. $scope.itemdetail = [];
  10. $scope.selectedList = [];
  11. $scope.totalques = [];
  12. // $scope.totalAdded = false;
  13. $scope.quesionAdded = false
  14. //$scope.modelData = [];
  15. $scope.zoneList = [];
  16. $scope.stateList = [];
  17. $scope.cityList = [];
  18. $scope.dealerList = [];
  19. $scope.expiredtype = [];
  20. $scope.stateVisible = false;
  21. $scope.cityVisible = false;
  22. $scope.dealerVisible = false;
  23. //$scope.isCategoryVisible = true;
  24. $scope.isExpiredRowVisible = false;
  25. $scope.isExpiredDaysVisible = false;
  26. $scope.isfirst = false;
  27. $scope.selectedIndex = null;
  28. $rootScope.cofirmWindow = false;
  29. $rootScope.modalpublishShown = false;
  30. $scope.search_show = true;
  31. $scope.url = "../senddata/log/";
  32. $scope.pageurl = "../senddata/assessment/";
  33. $scope.exporturl = "../senddata/export/";
  34. $scope.commonurl = "../senddata/common/";
  35. $scope.search_box = true;
  36. $scope.submenu = $scope.pageData.sidemenu;
  37. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  38. $scope.tblheading = $rootScope.sideselect.headingText;
  39. //pagination
  40. $scope.viewby = '10';
  41. $scope.currentPage = 1;
  42. $scope.itemsPerPage = $scope.viewby;
  43. $scope.maxSize = 5; //Number of pager buttons to show
  44. //Check Session//
  45. $scope.formData = {}
  46. $rootScope.formData = {}
  47. $scope.formData.ismenuload = "Yes";
  48. if ($rootScope.items == undefined || $rootScope.items == null) {
  49. $scope.formData.ismenuload = "No";
  50. }
  51. $scope.formData.funName = "checksession";
  52. $scope.formData.lang = $rootScope.selLanguage;
  53. $scope.formData.start = 2;
  54. $scope.formData.limit = 5;
  55. //this page Variable//
  56. //$scope.roleitem = null;
  57. $scope.cateitem = null;
  58. $scope.questionitem = null;
  59. $scope.assignquestionitem = [];
  60. $scope.assignquestionnum = [];
  61. AppData.sendData($scope.url, $scope.formData, function (res) {
  62. if (res.cont) {
  63. if ($rootScope.items == undefined || $rootScope.items == null) {
  64. $rootScope.items = res.item.control;
  65. }
  66. for (var i = 0; i < $rootScope.items.length; i++) {
  67. if ($location.path() == $rootScope.items[i].modulepath) {
  68. $rootScope.modulename = $rootScope.items[i].modulename;
  69. console.log($rootScope.modulename, '$rootScope.modulename')
  70. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  71. }
  72. }
  73. $scope.statusobj = res.item.status;
  74. $rootScope.username = res.item.username;
  75. $scope.listFound = true;
  76. $scope.start_time = $scope.pageData.assessment_publish_time;
  77. $scope.end_time = $scope.pageData.assessment_publish_time;
  78. //$rootScope.role = res.item.role;
  79. $scope.assessmentList();
  80. //$scope.moduleData();
  81. } else {
  82. $location.path("/login");
  83. }
  84. })
  85. $scope.assessmentList = function () {
  86. $scope.search_show = true;
  87. $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
  88. var fobj = {};
  89. fobj.funName = "assessmentlist";
  90. if ($rootScope.sideselect.id == 1) {
  91. fobj.pn = $scope.currentPage;
  92. fobj.nr = $scope.itemsPerPage;
  93. } else {
  94. fobj.pn = '';
  95. fobj.nr = '';
  96. }
  97. fobj.lang = $rootScope.selLanguage;
  98. fobj.key = $scope.searchvalue;
  99. $rootScope.pageLoadComp = true;
  100. AppData.sendData($scope.pageurl, fobj, function (res) {
  101. $rootScope.pageLoadComp = true;
  102. if (res.cont) {
  103. if (res.item != undefined) {
  104. $scope.itemdetail = res.item.assessment;
  105. $scope.totalItems = res.item.total_records;
  106. $scope.listFound = true;
  107. $scope.formLoad = false;
  108. $scope.search_box = true;
  109. }
  110. //$scope.formData = {}
  111. } else {
  112. $scope.listFound = false;
  113. $scope.errorMsg = res.mess;
  114. }
  115. //$scope.roleitem=res.item.roleitem;
  116. })
  117. }
  118. $scope.setPage = function (pageNo) {
  119. $scope.currentPage = pageNo;
  120. };
  121. $scope.pageChanged = function () {
  122. $scope.assessmentList();
  123. };
  124. $scope.setItemsPerPage = function (num) {
  125. $scope.itemsPerPage = num;
  126. $scope.currentPage = 1; //reset to first page
  127. $scope.assessmentList();
  128. }
  129. $scope.filterData = function () {
  130. $scope.assessmentList();
  131. }
  132. $scope.listClick = function (obj) {
  133. $scope.searchtext = '';
  134. $scope.formData = {};
  135. $scope.currentPage = 1;
  136. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  137. $scope.formLoad = false;
  138. $rootScope.sideselect = obj;
  139. $scope.selectedIndex = null;
  140. $scope.tblheading = obj.headingText;
  141. $scope.assessmentList();
  142. }
  143. $scope.deleterow = function (obj, i) {
  144. $scope.formData = obj;
  145. $scope.selectedIndex = i;
  146. $scope.deleteFun();
  147. }
  148. $scope.exportrow = function (obj, i) {
  149. $scope.formData = obj;
  150. $scope.selectedIndex = i;
  151. $scope.exportFun();
  152. }
  153. $scope.editrow = function (obj, i, type) {
  154. $scope.formData = obj;
  155. $scope.selectedIndex = i;
  156. $scope.search_box = false;
  157. $scope.listFound = false;
  158. $scope.formLoad = true;
  159. $scope.questionList();
  160. $scope.getTag();
  161. // $scope.getAssessmentReview();
  162. setTimeout(function () {
  163. $scope.editFun(type);
  164. }, 200)
  165. }
  166. $scope.viewTiprow = function (obj, i) {
  167. $scope.formData = obj;
  168. $scope.selectedIndex = i;
  169. $scope.viewTipFun();
  170. }
  171. $scope.viewrow = function (obj, i) {
  172. $scope.formData = obj;
  173. $scope.selectedIndex = i;
  174. $scope.viewFun();
  175. }
  176. $scope.onSearchChange = function () {
  177. console.log($scope.formData.mymodel)
  178. $scope.assessmentList();
  179. }
  180. $scope.onremoveQuestion = function (val) {
  181. console.log(val);
  182. }
  183. $scope.getAssessmentReview = function () {
  184. var obj = {};
  185. obj.funName = "assessmentdetails";
  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. }
  195. } else {
  196. }
  197. })
  198. }
  199. $scope.editFun = function (type) {
  200. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  201. if ($scope.selectedIndex != null) {
  202. $scope.random_question = {}
  203. $scope.formLoad = true;
  204. if(type==0){
  205. $scope.formAction = 'Edit';
  206. }
  207. else{
  208. $scope.formAction = 'Add';
  209. }
  210. if ($scope.sideselect.id == 1) {
  211. $scope.formtitle = "Edit Assessment";
  212. $scope.formData.zoneList = {};
  213. // $scope.formData.regionList = {};
  214. $scope.formData.dealerList = {};
  215. $scope.regionList = []
  216. $scope.questypeList();
  217. $scope.getRole();
  218. $scope.getZone();
  219. $scope.getUserType();
  220. $scope.scoreListFun();
  221. var obj = {};
  222. obj.funName = "assessmentdetails";
  223. obj.lang = $rootScope.selLanguage;
  224. obj.assessmentid = $scope.formData.assessmentid;
  225. AppData.sendData($scope.pageurl, obj, function (res) {
  226. $rootScope.pageLoadComp = true;
  227. if (res.cont) {
  228. if (res.cont) {
  229. console.log(res.item)
  230. $scope.formData = res.item;
  231. $scope.formData.zoneList = {}
  232. console.log(res.item.question_arr)
  233. $scope.formData.dealerList = {};
  234. $scope.formData.roleList = {};
  235. // $scope.formData.filter_zone=res.item.filter_zone;
  236. if ($scope.formData.filter_zone.length > 0) {
  237. angular.forEach($scope.formData.filter_zone, function (element, index) {
  238. console.log(element)
  239. $scope.formData.zoneList[element.zone] = true;
  240. if (element != '') {
  241. $scope.zoneChanged(element, index);
  242. }
  243. });
  244. } else {
  245. $scope.stateVisible = false;
  246. $scope.dealerVisible = false;
  247. }
  248. $scope.formData.regionList = {};
  249. if ($scope.formData.filter_region.length > 0) {
  250. angular.forEach($scope.formData.filter_region, function (element, index) {
  251. console.log(element)
  252. $scope.formData.regionList[element.city] = true;
  253. if (element != '') {
  254. $scope.regionChanged(element.city, index);
  255. }
  256. });
  257. } else {
  258. $scope.dealerVisible = false;
  259. }
  260. $scope.formData.dealerList = {};
  261. if ($scope.formData.filter_dealer.length > 0) {
  262. angular.forEach($scope.formData.filter_dealer, function (element) {
  263. $scope.formData.dealerList[element.dealer_code] = true;
  264. });
  265. }
  266. if (type == 0) {
  267. $scope.formData.roleList = $scope.formData.user_type;
  268. }
  269. else {
  270. $scope.formData.assessmentid = {}
  271. $scope.formData.roleList =''
  272. // // $scope.formData.funName = "addassessment";
  273. $scope.formAction == "Add"
  274. }
  275. // $scope.formData.roleList = $scope.formData.user_type;
  276. console.log($scope.formData.questionList)
  277. for (var key in $scope.formData.questionList) {
  278. $scope.formData.questionList[key] = false;
  279. }
  280. // for(i=0;i<$scope.formData.questionList.length;i++){
  281. // $scope.formData.questionList[$scope.formData.questionList[i].id]=false;
  282. // }
  283. // $scope.formData.roleList = $scope.formData.filter_role_name;
  284. console.log($scope.formData.question_arr, "heree")
  285. $scope.questionTempList = $scope.formData.question_arr;
  286. console.log('I am here', $scope.questionTempList)
  287. // $scope.random_question = {}
  288. // $scope.random_question_no = {}
  289. // for (var key in $scope.formData.questionList) {
  290. // console.log('qid here', key, $scope.assessment_question)
  291. // angular.forEach($scope.assessment_question, function (val) {
  292. // if (val.id == key) {
  293. // $scope.random_question[val.id] = val.questiontext
  294. // $scope.quesionAdded = true
  295. // }
  296. // })
  297. // }
  298. // console.log('+++++', $scope.random_question)
  299. // $scope.random_question = [];
  300. // for (var h in $scope.formData.question_arr) {
  301. // $scope.random_question.push({ qid: $scope.formData.question_arr[h].qid, is_mandatory: $scope.formData.question_arr[h].is_mandatory });
  302. // }
  303. // $scope.random_question = JSON.stringify($scope.question_json);
  304. // console.log('Im here', $scope.question_json)
  305. // $scope.formData.question_json = JSON.stringify($scope.question_json);
  306. // console.log('$scope.formData.question_json',$scope.formData.question_json)
  307. }
  308. } else {
  309. }
  310. })
  311. console.log($scope.formData.filter_zone, "zoneee")
  312. } else if ($scope.sideselect.id == 2) {
  313. $scope.formtitle = "Edit Participant";
  314. }
  315. } else {
  316. $rootScope.modalShown = true;
  317. $rootScope.message = $scope.pageData.errorMsg[0];
  318. }
  319. }
  320. $scope.questypeList = function () {
  321. var qobj = {};
  322. qobj.funName = "questiontype";
  323. qobj.type = $scope.formData.type;
  324. qobj.lang = $rootScope.selLanguage;
  325. AppData.sendData($scope.commonurl, qobj, function (res) {
  326. if (res.cont) {
  327. $scope.questype = res.item;
  328. } else {
  329. $rootScope.modalShown = true;
  330. $rootScope.message = (res.mess);
  331. }
  332. })
  333. }
  334. $scope.deleteFun = function () {
  335. if ($scope.selectedIndex != null) {
  336. $rootScope.cofirmWindow = true;
  337. $rootScope.modalShown = true;
  338. $rootScope.message = $scope.pageData.errorMsg[1];
  339. } else {
  340. $rootScope.modalShown = true;
  341. $rootScope.message = $scope.pageData.errorMsg[0];
  342. }
  343. }
  344. $scope.$on("confirmDelete", function () {
  345. if ($scope.sideselect.id == 1) {
  346. $scope.formData.funName = "deleteassessment";
  347. } else {
  348. $scope.formData.funName = "deleteassessmentuser";
  349. }
  350. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  351. if (res.cont) {
  352. if ($scope.sideselect.id == 1) {
  353. var index = $scope.itemdetail.indexOf($scope.formData);
  354. if (index != -1) {
  355. $scope.itemdetail.splice(index, 1);
  356. }
  357. }
  358. $rootScope.modalShown = true;
  359. $rootScope.cofirmWindow = false;
  360. $rootScope.message = (res.mess);
  361. } else {
  362. $rootScope.modalShown = true;
  363. $rootScope.message = (res.mess);
  364. }
  365. })
  366. })
  367. $scope.questionList = function () {
  368. var fobj = {};
  369. fobj.funName = "questions";
  370. fobj.lang = $rootScope.selLanguage;
  371. fobj.certified = 0;
  372. fobj.is_survey = 0;
  373. AppData.sendData($scope.commonurl, fobj, function (res) {
  374. $rootScope.pageLoadComp = true;
  375. if (res.cont) {
  376. if (res.item != undefined) {
  377. $scope.assessment_question = res.item;
  378. console.log($scope.assessment_question)
  379. // angular.forEach($scope.assessment_question,function(element){
  380. // element.selected = false;
  381. // })
  382. }
  383. } else {
  384. //$scope.listFound = false;
  385. $scope.errorMsg = res.mess;
  386. }
  387. })
  388. }
  389. $scope.getRole = function () {
  390. var obj = {};
  391. obj.funName = "role";
  392. obj.lang = $rootScope.selLanguage;
  393. obj.type = "dse"
  394. AppData.sendData($scope.commonurl, obj, function (res) {
  395. if (res.cont) {
  396. if (res.item != undefined) {
  397. $scope.role = res.item;
  398. }
  399. }
  400. })
  401. }
  402. $scope.getZone = function () {
  403. var zobj = {};
  404. zobj.funName = "zone";
  405. zobj.lang = $rootScope.selLanguage;
  406. AppData.sendData($scope.commonurl, zobj, function (res) {
  407. if (res.cont) {
  408. if (res.item != undefined) {
  409. $scope.zoneList = res.item;
  410. }
  411. }
  412. })
  413. }
  414. $scope.zoneChanged = function (item, i) {
  415. var obj = {};
  416. obj.cont = true;
  417. angular.forEach($scope.regionList, function (cityname, index) {
  418. if (item.zone == cityname.title) {
  419. angular.forEach(cityname.child, function (city, ind) {
  420. for (var k in $scope.formData.regionList) {
  421. if (city == k) {
  422. $scope.formData.regionList[k] = false;
  423. }
  424. }
  425. })
  426. $scope.regionList.splice(index, 1);
  427. obj.cont = false;
  428. }
  429. })
  430. // $scope.regionList=[]
  431. var fobj = {};
  432. fobj.lang = $rootScope.selLanguage;
  433. fobj.funName = "city";
  434. var zonename = item.zone;
  435. fobj.zone = (zonename == undefined) ? "" : zonename;
  436. if (obj.cont) {
  437. AppData.sendData($scope.commonurl, fobj, function (res) {
  438. $rootScope.pageLoadComp = true;
  439. if (res.cont) {
  440. if (res.item != undefined) {
  441. $scope.stateVisible = true;
  442. var arr = [];
  443. for (var id = 0; id < res.item.length; id++) {
  444. arr.push(res.item[id].city);
  445. }
  446. console.log(res.item, arr, "helloooo", $scope.regionList)
  447. $scope.regionList.push({ "title": zonename, "child": arr });
  448. } else {
  449. $scope.regionList = [];
  450. $scope.dealerList = [];
  451. $scope.stateVisible = false;
  452. $scope.dealerVisible = false;
  453. }
  454. }
  455. });
  456. } else {
  457. //angular.forEach($scope.dealerList,function(item,index){
  458. if ($scope.dealerList.length != undefined) {
  459. for (i = 0; i < $scope.dealerList.length; i++) {
  460. for (var k in $scope.formData.regionList) {
  461. if ($scope.dealerList.length != undefined && $scope.dealerList.length > 0) {
  462. if (k == $scope.dealerList[i].title) {
  463. if ($scope.formData.regionList[k] == false) {
  464. angular.forEach($scope.dealerList[i].child, function (dealer, ind) {
  465. for (var j in $scope.formData.dealerList) {
  466. if (j == dealer.dealer_code) {
  467. $scope.formData.dealerList[j] = false;
  468. }
  469. }
  470. $scope.dealerList.splice(i, 1);
  471. })
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. }
  480. $scope.regionChanged = function (item, i) {
  481. var dobj = {};
  482. dobj.cont = true;
  483. if ($scope.dealerList != undefined) {
  484. angular.forEach($scope.dealerList, function (dealername, index) {
  485. if (item == dealername.title) {
  486. angular.forEach(dealername.child, function (dealer, ind) {
  487. for (var k in $scope.formData.dealerList) {
  488. if (dealer.dealer_code == k) {
  489. $scope.formData.dealerList[k] = false;
  490. }
  491. }
  492. })
  493. $scope.dealerList.splice(index, 1);
  494. // dobj.cont = false;
  495. }
  496. })
  497. }
  498. var fobj = {};
  499. fobj.lang = $rootScope.selLanguage;
  500. fobj.funName = "dealer";
  501. var dealer_name = item;
  502. // if($scope.is_edit_dealer==false){
  503. // }else{
  504. // var dealer_name = item.toString();
  505. // $scope.is_edit_dealer= false;
  506. // }
  507. fobj.city = (dealer_name == undefined) ? "" : dealer_name;
  508. if (dobj.cont) {
  509. AppData.sendData($scope.commonurl, fobj, function (res) {
  510. $rootScope.pageLoadComp = true;
  511. if (res.cont) {
  512. if (res.item != undefined) {
  513. $scope.dealerVisible = true;
  514. var arr = [];
  515. for (var id = 0; id < res.item.length; id++) {
  516. var obj = {};
  517. obj.dealer_name = res.item[id].dealer_name;
  518. obj.dealer_code = res.item[id].dealer_code;
  519. arr.push(obj);
  520. }
  521. $scope.dealerList.push({ "title": dealer_name, "child": arr });
  522. } else {
  523. $scope.dealerVisible = false;
  524. $scope.dealerList = [];
  525. }
  526. }
  527. });
  528. } else {
  529. }
  530. }
  531. $scope.getTag = function () {
  532. var obj = {};
  533. obj.funName = "questiontag";
  534. obj.lang = $rootScope.selLanguage;
  535. obj.certified = "0";
  536. obj.is_survey = "0";
  537. obj.questiontypeid = "";
  538. AppData.sendData($scope.commonurl, obj, function (res) {
  539. $rootScope.pageLoadComp = true;
  540. if (res.cont) {
  541. if (res.item != undefined) {
  542. console.log(res.item)
  543. $scope.tagList = res.item;
  544. } else {
  545. }
  546. }
  547. });
  548. }
  549. $scope.getUserType = function () {
  550. var obj = {};
  551. obj.funName = "accessmentusertype";
  552. obj.lang = $rootScope.selLanguage;
  553. obj.certified = "0";
  554. obj.is_survey = "0";
  555. obj.questiontypeid = "";
  556. AppData.sendData($scope.commonurl, obj, function (res) {
  557. $rootScope.pageLoadComp = true;
  558. if (res.cont) {
  559. if (res.item != undefined) {
  560. console.log(res.item)
  561. $scope.UserType = res.item;
  562. } else {
  563. }
  564. }
  565. });
  566. }
  567. $scope.changeTag = function () {
  568. var obj = {};
  569. obj.funName = "questions";
  570. obj.lang = $rootScope.selLanguage;
  571. obj.certified = "0";
  572. obj.is_survey = "0";
  573. obj.questiontypeid = "";
  574. obj.tag = $scope.formData.tag;
  575. AppData.sendData($scope.commonurl, obj, function (res) {
  576. $rootScope.pageLoadComp = true;
  577. if (res.cont) {
  578. if (res.item != undefined) {
  579. console.log(res.item)
  580. $scope.assessment_question = res.item;
  581. // $scope.questionList = res.item;
  582. } else {
  583. }
  584. }
  585. });
  586. }
  587. $scope.scoreListFun = function(){
  588. for(var i=1;i<=100;i++){
  589. // console.log(i)
  590. $scope.scoreList.push(i);
  591. }
  592. $scope.formData.pass_score = '80';
  593. }
  594. $scope.addFun = function () {
  595. $scope.formData = {};
  596. $scope.assessment_question = [];
  597. $scope.scoreList=[];
  598. $scope.formData.assessmenttime = 30;
  599. $scope.formData.attemptslimit = 1;
  600. $scope.formData.questionList = {};
  601. $scope.zoneList = [];
  602. $scope.regionList = [];
  603. $scope.dealerList = [];
  604. $scope.formData.regionList = {};
  605. $scope.formData.dealerList = {};
  606. $scope.search_box = false;
  607. $scope.formLoad = true;
  608. $scope.listFound = false;
  609. $scope.questionTempList = []
  610. $("input#myCheck").attr("disabled", true);
  611. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  612. $scope.formAction = 'Add';
  613. $scope.formLoad = true;
  614. $scope.formData.funName = "addassessment";
  615. $scope.formtitle = "Add Assessment";
  616. console.log($scope.formtitle)
  617. $scope.question_json = [];
  618. $scope.random_question = {};
  619. $scope.formData.is_mandatory = {};
  620. $scope.questionList();
  621. $scope.getRole();
  622. $scope.getZone();
  623. $scope.getTag();
  624. $scope.getUserType();
  625. $scope.scoreListFun();
  626. }
  627. $scope.quesChange = function (item, i) {
  628. console.log('+++++', $scope.assessment_question)
  629. if (item != undefined) {
  630. for (var i = 0; i < $scope.assessment_question.length; i++) {
  631. if ($scope.assessment_question[i].id == item.id) {
  632. // console.log($scope.assessment_question[i].selected)
  633. if ($scope.assessment_question[i].selected) {
  634. $scope.formData.is_mandatory[item.id] = '0';
  635. $scope.formData.questionList[item.id] = true;
  636. } else {
  637. $scope.formData.questionList[item.id] = false;
  638. }
  639. }
  640. }
  641. // if(item.id == val.id){
  642. // console.log($scope.formData.questionList,val)
  643. //
  644. // console.log($scope.formData.questionList[val.id])
  645. // var index = $scope.questionTempList.indexOf(item);
  646. // console.log(index)
  647. // if($scope.formData.questionList[val.id]){
  648. // $scope.questionTempList.push(item)
  649. // }else{
  650. // $scope.questionTempList.splice(index,1)
  651. // }
  652. // }
  653. }
  654. // console.log(item)
  655. // if (item != undefined) {
  656. // angular.forEach($scope.assessment_question, function (val) {
  657. // if (item.id == val.id) {
  658. // console.log('SCOPE', $scope.formData)
  659. // $scope.formData.is_mandatory[val.id] = '0';
  660. // // $scope.formData.questionId[val.id]=val.id;
  661. // }
  662. // })
  663. // }
  664. }
  665. $scope.closeForm = function () {
  666. $scope.formLoad = false;
  667. $scope.formData = {};
  668. $scope.selectedIndex = null;
  669. $scope.search_box = true;
  670. $scope.listFound = true;
  671. $scope.assessmentList();
  672. $scope.clearErrorMsg()
  673. }
  674. $scope.onremoveQuestion = function (val) {
  675. $scope.random_question = {}
  676. var index = val
  677. angular.forEach(this.assessment_question, function (val) {
  678. if (val.id == index) {
  679. console.log($scope.random_question[index])
  680. $scope.random_question[index].splice(val.id, 1);
  681. }
  682. })
  683. // $scope.this.assessment_question.splice(index,1);
  684. }
  685. $scope.addQuestions = function () {
  686. for (var i = 0; i < $scope.assessment_question.length; i++) {
  687. //console.log($scope.assessment_question[i])
  688. var index = $scope.questionTempList.indexOf($scope.assessment_question[i]);
  689. if ($scope.assessment_question[i].selected) {
  690. if (index == -1) {
  691. $scope.questionTempList.push($scope.assessment_question[i])
  692. $scope.assessment_question[i].selected= false;
  693. } else {
  694. // $rootScope.modalShown = true;
  695. // $rootScope.message = "Same question already added in the question list";
  696. }
  697. }
  698. }
  699. console.log('addQuestions', $scope.questionTempList.length)
  700. $scope.question_tag_error= ($scope.questionTempList.length == undefined || $scope.questionTempList.length == '0' ) ? 'Please select atleast one question': '';
  701. // $scope.random_question = {}
  702. // for (var key in $scope.formData.questionList) {
  703. // angular.forEach(this.assessment_question, function (val) {
  704. // if (val.id == key) {
  705. // $scope.random_question[val.id] = val.questiontext
  706. // $scope.quesionAdded = true
  707. // }
  708. // })
  709. // }
  710. // angular.forEach($scope.formData.questionList, function (val) {
  711. // $scope.formData.random_question[val.id]=""
  712. // })
  713. }
  714. $scope.fieldValidation = function () {
  715. $scope.assessment_error = ($scope.formData.assessmentname == undefined || $scope.formData.assessmentname == '') ? 'Please enter assessment name' : '';
  716. $scope.type_error = ($scope.formData.assessmenttimetype == undefined || $scope.formData.assessmenttimetype == '') ? 'Please select assessment type' : '';
  717. $scope.publisheddate_error = ($scope.formData.publisheddate == undefined || $scope.formData.publisheddate == '') ? 'Please select published date' : '';
  718. $scope.enddate_error = ($scope.formData.enddate == undefined || $scope.formData.enddate == '') ? 'Please select end date' : '';
  719. $scope.starttime_error = ($scope.formData.publishedtime == undefined || $scope.formData.publishedtime == '') ? 'Please select start time' : '';
  720. $scope.endtime_error = ($scope.formData.endtime == undefined || $scope.formData.endtime == '') ? 'Please select end time' : '';
  721. $scope.ques_error = ($scope.formData.randomcond == undefined || $scope.formData.randomcond == '') ? 'Please select question type' : '';
  722. $scope.role_error = ($scope.formData.roleList == undefined || $scope.formData.roleList == '') ? 'Please select user type' : '';
  723. $scope.segment_error = ($scope.formData.segment == undefined || $scope.formData.segment == '') ? 'Please select any one' : '';
  724. // $scope.zone_error = ($scope.formData.zoneList == undefined || $scope.formData.zoneList == '') ? 'Please select zone' : '';
  725. $scope.addquestion_error = ($scope.questionTempList.length == 0) ? 'Please add a question ' : '';
  726. // console.log("9999", $scope.questionTempList)
  727. // $scope.limit_error = ($scope.formData.attemptslimit == undefined || $scope.formData.attemptslimit == '') ? 'Please enter no. of attempts limit' : '';
  728. // $scope.assessmenttime_error = ($scope.formData.assessmenttime == undefined || $scope.formData.assessmenttime == '') ? 'Please enter assessment time' : '';
  729. // console.log('+-+-+-',$scope.assessment_error,$scope.type_error , $scope.publisheddate_error,$scope.enddate_error,$scope.starttime_error , $scope.endtime_error, $scope.ques_error,$scope.role_error ,$scope.zone_error&&$scope.addquestion_error)
  730. return ($scope.assessment_error == '' && $scope.type_error == '' && $scope.publisheddate_error == '' && $scope.enddate_error == '' && $scope.starttime_error == '' && $scope.endtime_error == '' && $scope.ques_error == '' && $scope.role_error == '' && $scope.addquestion_error == '' && $scope.segment_error=='') ? true : false;
  731. }
  732. $scope.clearErrorMsg = function () {
  733. $scope.assessment_error = '';
  734. $scope.type_error = '';
  735. $scope.publisheddate_error = '';
  736. $scope.enddate_error = '';
  737. $scope.starttime_error = '';
  738. $scope.endtime_error = '';
  739. $scope.ques_error = '';
  740. $scope.role_error = '';
  741. $scope.zone_error = '';
  742. $scope.addquestion_error = ''
  743. $scope.segment_error='';
  744. // $scope.questiontype_error = '';
  745. // $scope.limit_error = '';
  746. // $scope.assessmenttime_error = '';
  747. }
  748. $scope.assessmentSubmit = function () {
  749. $scope.clearErrorMsg();
  750. if ($scope.formAction == "Add") {
  751. $scope.formData.funName = "addassessment";
  752. } else {
  753. $scope.formData.funName = "editassessment";
  754. $scope.formData.assessmentid = $scope.formData.assessmentid;
  755. }
  756. if ($scope.formData.cityList != undefined) {
  757. var cityarr = [];
  758. for (k in $scope.formData.cityList) {
  759. if ($scope.formData.cityList[k] == true) {
  760. cityarr.push(k)
  761. }
  762. }
  763. if (cityarr.length != 0) {
  764. $scope.formData.filter_city = cityarr.toString();
  765. }
  766. }
  767. if ($scope.formData.regionList != undefined) {
  768. var statearr = [];
  769. console.log($scope.formData.regionList, "$scope.formData.regionList")
  770. for (k in $scope.formData.regionList) {
  771. if ($scope.formData.regionList[k] == true) {
  772. statearr.push(k)
  773. }
  774. }
  775. if (statearr.length != 0) {
  776. $scope.formData.filter_region = statearr.toString();
  777. }
  778. }
  779. if ($scope.formData.dealerList != undefined) {
  780. var dealerarr = [];
  781. console.log($scope.formData.dealerList, "$scope.formData.dealerList")
  782. for (k in $scope.formData.dealerList) {
  783. if ($scope.formData.dealerList[k] == true) {
  784. dealerarr.push(k)
  785. }
  786. }
  787. if (dealerarr.length != 0) {
  788. $scope.formData.filter_dealer = dealerarr.toString();
  789. }
  790. }
  791. if ($scope.formData.zoneList != undefined) {
  792. var zonearr = [];
  793. console.log($scope.formData.zoneList, "$scope.formData.zoneList")
  794. for (k in $scope.formData.zoneList) {
  795. if ($scope.formData.zoneList[k] == true) {
  796. zonearr.push(k)
  797. console.log(zonearr, "zonearr")
  798. }
  799. }
  800. if (zonearr.length != 0) {
  801. $scope.formData.filter_zone = zonearr.toString();
  802. }
  803. }
  804. var arr = [];
  805. $scope.question_json = [];
  806. console.log($scope.questionTempList)
  807. for (var h = 0; h < $scope.questionTempList.length; h++) {
  808. $scope.question_json.push({ qid: ($scope.questionTempList[h].id!=undefined)?$scope.questionTempList[h].id:$scope.questionTempList[h].qid, is_mandatory: $scope.formData.is_mandatory[($scope.questionTempList[h].id!=undefined)?$scope.questionTempList[h].id:$scope.questionTempList[h].qid] });
  809. }
  810. console.log($scope.question_json)
  811. $scope.formData.question_json = JSON.stringify($scope.question_json);
  812. console.log($scope.formData.question_json)
  813. $scope.formData.assessmentnotification = "1";
  814. $scope.formData.total_question = $scope.questionTempList.length;
  815. $scope.formData.user_type = $scope.formData.roleList;
  816. $scope.formData.segment = $scope.formData.segment
  817. // if ($scope.formData.roleList.length != 0) {
  818. // var rolearr = [];
  819. // for (var id = 0; id < $scope.formData.roleList.length; id++) {
  820. // rolearr.push($scope.formData.roleList[id].id)
  821. // }
  822. // $scope.formData.filter_role = rolearr.toString();
  823. // }
  824. // $scope.formData.filter_role = []
  825. // $scope.formData.total_question = Object.keys($scope.random_question).length;
  826. // console.log(Object.keys($scope.random_question).length)
  827. // $scope.formData.atype = '0'
  828. // $scope.formData.user_type = $scope.formData.roleList;
  829. // var arr = [];
  830. // $scope.question_json = [];
  831. // for (var h in $scope.random_question) {
  832. // if ($scope.random_question[h]) {
  833. // $scope.question_json.push({ qid: h, is_mandatory: $scope.formData.is_mandatory[h] });
  834. // }
  835. // }
  836. // $scope.formData.question_json = JSON.stringify($scope.question_json);
  837. // console.log($scope.formData.question_json)
  838. // for (var h in $scope.formData.questionList) {
  839. // if ($scope.formData.questionList[h]) {
  840. // $scope.question_json.push({ qid: h, is_mandatory: $scope.formData.is_mandatory[h] });
  841. // }
  842. // }
  843. // $scope.formData.question_json = JSON.stringify($scope.question_json);
  844. console.log('$scope.fieldValidation())', $scope.fieldValidation())
  845. if ($scope.fieldValidation()) {
  846. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  847. if (res.cont) {
  848. $rootScope.modalShown = true;
  849. $rootScope.message = (res.mess);
  850. $scope.assessmentList();
  851. $scope.selectedIndex = null;
  852. $scope.formLoad = false;
  853. $scope.listFound = true;
  854. } else {
  855. $rootScope.modalShown = true;
  856. $rootScope.message = (res.mess);
  857. }
  858. })
  859. }
  860. }
  861. $scope.deleteQuestion = function (item) {
  862. var index = $scope.questionTempList.indexOf(item);
  863. if (index != -1) {
  864. $scope.questionTempList.splice(index, 1);
  865. }
  866. // console.log($scope.questionTempList)
  867. }
  868. });
  869. });