question.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. define(['app'], function (app) {
  2. app.controller('QuestionCtrl', function ($scope, $rootScope, AppData, $location) {
  3. //Every module Set Same Variable//
  4. $rootScope.menucont = true;
  5. $rootScope.pageLoadComp = false;
  6. $scope.formLoad = false;
  7. $scope.listFound = false;
  8. $scope.pageData = questionData[$rootScope.selLanguage];
  9. $scope.formAction = "Add";
  10. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  11. console.log($rootScope.sideselect)
  12. $scope.itemdetail = [];
  13. $scope.selectedIndex = null;
  14. $rootScope.cofirmWindow = false;
  15. $scope.submenu = $scope.pageData.sidemenu;
  16. $scope.title = $rootScope.sideselect.name;
  17. $scope.tblheading = $rootScope.sideselect.headingText;
  18. $scope.url = "../senddata/log/";
  19. $scope.pageurl = "../senddata/question/";
  20. $scope.commonurl = "../senddata/common/";
  21. $rootScope.imageFormat = ["image/jpeg", "image/png", "video/mp4"];
  22. $rootScope.qimage = '';
  23. $scope.search_box = true;
  24. //pagination
  25. $scope.viewby = '10';
  26. $scope.currentPage = 1;
  27. $scope.itemsPerPage = $scope.viewby;
  28. $scope.maxSize = 5; //Number of pager buttons to show
  29. $scope.pageSize = 10;
  30. //Check Session//
  31. $scope.formData = {}
  32. $scope.formData.ismenuload = "Yes";
  33. if ($rootScope.items == undefined || $rootScope.items == null) {
  34. $scope.formData.ismenuload = "No";
  35. }
  36. $scope.formData.funName = "checksession";
  37. $scope.formData.lang = $rootScope.selLanguage;
  38. $scope.formData.start = 0;
  39. $scope.formData.limit = 2;
  40. //this page Variable//
  41. $scope.catearray = [];
  42. $scope.typearray = [];
  43. $scope.optdetail = [];
  44. AppData.sendData($scope.url, $scope.formData, function (res) {
  45. if (res.cont) {
  46. if ($rootScope.items == undefined || $rootScope.items == null) {
  47. $rootScope.items = res.item.control;
  48. }
  49. for (var i = 0; i < $rootScope.items.length; i++) {
  50. if ($location.path() == $rootScope.items[i].modulepath) {
  51. $rootScope.modulename = $rootScope.items[i].modulename;
  52. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  53. }
  54. }
  55. $scope.statusobj = res.item.status;
  56. $rootScope.username = res.item.username;
  57. $scope.questionList = function () {
  58. $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
  59. var fobj = {};
  60. fobj.funName = "questionlist";
  61. fobj.lang = $rootScope.selLanguage;
  62. fobj.pn = $scope.currentPage;
  63. fobj.nr = $scope.itemsPerPage;
  64. fobj.lang = $rootScope.selLanguage;
  65. fobj.key = $scope.searchvalue;
  66. fobj.tag = ($scope.formData.tag!=undefined || $scope.formData.tag!='')?$scope.formData.tag:'';
  67. // fobj.cateid = 0;
  68. $rootScope.pageLoadComp = true;
  69. AppData.sendData($scope.pageurl, fobj, function (res) {
  70. $rootScope.pageLoadComp = true;
  71. if (res.cont) {
  72. if (res.item != undefined) {
  73. $scope.question_data = res.item.questions;
  74. $scope.totalItems = res.item.total_records;
  75. $scope.listFound = true;
  76. $scope.search_box = true;
  77. }
  78. } else {
  79. $scope.listFound = false;
  80. $scope.errorMsg = res.mess;
  81. }
  82. })
  83. }
  84. $scope.getTag = function () {
  85. var obj = {};
  86. obj.funName = "allquestiontag";
  87. obj.lang = $rootScope.selLanguage;
  88. obj.certified = "0";
  89. obj.is_survey = "0";
  90. obj.questiontypeid = "";
  91. AppData.sendData($scope.commonurl, obj, function (res) {
  92. $rootScope.pageLoadComp = true;
  93. if (res.cont) {
  94. if (res.item != undefined) {
  95. console.log(res.item)
  96. $scope.tagList = res.item;
  97. } else {
  98. }
  99. }
  100. });
  101. }
  102. $scope.changeTag = function(){
  103. $scope.questionList();
  104. $scope.getTag()
  105. }
  106. $scope.getTag()
  107. $scope.questionList();
  108. $scope.setPage = function (pageNo) {
  109. $scope.currentPage = pageNo;
  110. };
  111. $scope.pageChanged = function () {
  112. console.log('Page changed to: ' + $scope.currentPage);
  113. console.log('ItemPage : ' + $scope.viewby);
  114. $scope.questionList();
  115. };
  116. $scope.setItemsPerPage = function (num) {
  117. $scope.itemsPerPage = num;
  118. $scope.currentPage = 1; //reset to first page
  119. console.log('ItemPage : ' + $scope.itemsPerPage);
  120. $scope.questionList();
  121. }
  122. $scope.filterData = function () {
  123. console.log($scope.searchtext)
  124. $scope.questionList();
  125. }
  126. } else {
  127. $location.path("/login");
  128. }
  129. })
  130. $scope.onSearchChange = function () {
  131. console.log($scope.formData.mymodel)
  132. $scope.questionList();
  133. }
  134. $scope.cartiQuesList = function () {
  135. var fobj = {};
  136. fobj.funName = "questionlist";
  137. fobj.lang = $rootScope.selLanguage;
  138. fobj.pn = $scope.currentPage;
  139. fobj.nr = $scope.itemsPerPage;
  140. fobj.lang = $rootScope.selLanguage;
  141. fobj.key = $scope.searchtext;
  142. fobj.certified = 1;
  143. $rootScope.pageLoadComp = true;
  144. AppData.sendData($scope.pageurl, fobj, function (res) {
  145. $rootScope.pageLoadComp = true;
  146. if (res.cont) {
  147. if (res.item != undefined) {
  148. $scope.cert_ques_data = res.item.questions;
  149. $scope.totalItems = res.item.total_records;
  150. $scope.listFound = true;
  151. $scope.search_box = true;
  152. }
  153. $scope.formData = {}
  154. } else {
  155. $scope.listFound = false;
  156. $scope.errorMsg = res.mess;
  157. }
  158. })
  159. }
  160. $scope.listClick = function (obj) {
  161. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  162. $scope.formLoad = false;
  163. $rootScope.sideselect = obj;
  164. $scope.itemdetail = [];
  165. $scope.selectedIndex = null;
  166. var fobj = {};
  167. fobj.lang = $rootScope.selLanguage;
  168. fobj.funName = "questionlist";
  169. $scope.title = obj.name;
  170. if (obj.id == 1) {
  171. $scope.tblheading = obj.headingText;
  172. $scope.questionList();
  173. } else if (obj.id == 2) {
  174. $scope.tblheading = obj.headingText;
  175. $scope.cartiQuesList();
  176. }
  177. }
  178. $scope.changeRemarks = function () {
  179. if ($scope.formData.rtype == 2 || $scope.formData.rtype == 3) {
  180. $scope.optdetail = [];
  181. $scope.optdetail.push({ optid: 1, iscorrect: 0, opttext: "", score: "" });
  182. $scope.optdetail.push({ optid: 2, iscorrect: 0, opttext: "", score: "" });
  183. console.log($scope.optdetail)
  184. }
  185. }
  186. /*$scope.curRowClick = function(obj,e){
  187. $scope.formData = obj
  188. $scope.selectedIndex = e;
  189. }*/
  190. $scope.deleterow = function (obj, i) {
  191. $scope.formData = obj;
  192. $scope.selectedIndex = i;
  193. $scope.deleteFun();
  194. }
  195. $scope.editrow = function (obj, i) {
  196. console.log(obj)
  197. $scope.formData = obj;
  198. $scope.selectedIndex = i;
  199. console.log($scope.formData);
  200. $scope.search_box = false;
  201. $scope.formLoad = true;
  202. $scope.listFound = false;
  203. $rootScope.qimage = '';
  204. if ($scope.formData.qtype == 3) {
  205. $scope.formData.rtype = $scope.formData.surveyqtype;
  206. $scope.category = $scope.surveycatearray;
  207. } else {
  208. $scope.category = $scope.catearray;
  209. $scope.formData.cattype = $scope.formData.cattype;
  210. }
  211. $scope.editFun();
  212. }
  213. $scope.viewTiprow = function (obj, i) {
  214. $scope.formData = obj;
  215. $scope.selectedIndex = i;
  216. $scope.viewTipFun();
  217. }
  218. $scope.viewrow = function (item, i) {
  219. var obj = {};
  220. obj.id = item.id;
  221. obj.funName = "questiondetails";
  222. AppData.sendData($scope.pageurl, obj, function (res) {
  223. if (res.cont) {
  224. $scope.view_question = res.item;
  225. //console.log($scope.view_question)
  226. // console.log($scope.view_question[0].options)
  227. // $scope.optdetail = res.item;
  228. }
  229. })
  230. // angular.forEach($scope.question_data,function(element) {
  231. // if(element.id==obj.id){
  232. // console.log(element)
  233. // $scope.view_question = element;
  234. // }
  235. // });
  236. }
  237. $scope.editFun = function () {
  238. $scope.questypeList();
  239. $scope.getTrainingLevel();
  240. if ($scope.optdetail != undefined && $scope.optdetail != '') {
  241. if ($scope.optdetail.length < 0) {
  242. $scope.formData.child = [];
  243. }
  244. } else {
  245. $scope.formData.child = [];
  246. }
  247. console.log($scope.optdetail)
  248. $scope.formtitle = "Edit Question";
  249. $scope.formData.funName = "editquestion";
  250. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  251. $scope.formData.lvl_id = $scope.formData.cateid
  252. if ($scope.selectedIndex != null) {
  253. if ($scope.formData.questiontypeid == '1' || $scope.formData.questiontypeid == '2' || $scope.formData.questiontypeid == '5' || $scope.formData.questiontypeid == '6') {
  254. console.log($scope.formData.qtype)
  255. var obj = {};
  256. obj.id = $scope.formData.id;
  257. obj.funName = "questionoptionlist";
  258. AppData.sendData($scope.pageurl, obj, function (res) {
  259. if (res.cont) {
  260. $scope.formData.child = res.item;
  261. console.log($scope.formData.child)
  262. $scope.optdetail = res.item;
  263. }
  264. })
  265. }
  266. $scope.formLoad = true;
  267. $scope.formAction = "Edit";
  268. // $scope.title = $rootScope.sideselect.title[1];
  269. } else {
  270. $rootScope.modalShown = true;
  271. $rootScope.message = $scope.pageData.errorMsg[0];
  272. }
  273. }
  274. $scope.deleteFun = function () {
  275. if ($scope.selectedIndex != null) {
  276. $rootScope.cofirmWindow = true;
  277. $rootScope.modalShown = true;
  278. $rootScope.message = $scope.pageData.errorMsg[1];
  279. } else {
  280. $rootScope.modalShown = true;
  281. $rootScope.message = $scope.pageData.errorMsg[0];
  282. }
  283. }
  284. $scope.$on("confirmDelete", function () {
  285. $scope.formData.funName = "deletequestion";
  286. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  287. if (res.cont) {
  288. if ($rootScope.sideselect.id == 1) {
  289. var index = $scope.question_data.indexOf($scope.formData);
  290. if (index != -1) {
  291. $scope.question_data.splice(index, 1);
  292. }
  293. } else if ($rootScope.sideselect.id == 2) {
  294. var index = $scope.cert_ques_data.indexOf($scope.formData);
  295. if (index != -1) {
  296. $scope.cert_ques_data.splice(index, 1);
  297. }
  298. }
  299. $rootScope.modalShown = true;
  300. $rootScope.cofirmWindow = false;
  301. $rootScope.message = (res.mess);
  302. } else {
  303. $rootScope.modalShown = true;
  304. $rootScope.message = (res.mess);
  305. }
  306. })
  307. })
  308. //$scope.optionshow = false;
  309. $scope.changeQuestype = function () {
  310. if ($scope.formData.questiontypeid == 1 || $scope.formData.questiontypeid == 2 || $scope.formData.questiontypeid == 5 || $scope.formData.questiontypeid == 6) {
  311. //$scope.optionshow = true;
  312. $scope.optdetail = [];
  313. $scope.optdetail.push({ optid: 1, iscorrect: 0, opttext: "", score: "" });
  314. $scope.optdetail.push({ optid: 2, iscorrect: 0, opttext: "", score: "" });
  315. console.log($scope.optdetail)
  316. } else {
  317. //$scope.optionshow = false;
  318. $scope.optdetail = [];
  319. }
  320. }
  321. $scope.changetype = function () {
  322. if ($scope.formData.type == 1) {
  323. $scope.questypeList();
  324. $scope.getTrainingLevel()
  325. } else {
  326. $scope.questypeList();
  327. }
  328. }
  329. // get the Training Level list Basic, Bronze, Silver, Gold
  330. $scope.getTrainingLevel = function () {
  331. var fobj = {};
  332. fobj.lang = $rootScope.selLanguage;
  333. fobj.type = '1';
  334. fobj.funName = "certificate_level";
  335. AppData.sendData($scope.commonurl, fobj, function (res) {
  336. if (res.cont) {
  337. if (res.item != undefined) {
  338. $scope.topicVisible = true;
  339. if (res.item.length > 0) {
  340. $scope.traininglevels = res.item;
  341. }
  342. } else {
  343. }
  344. }
  345. });
  346. }
  347. $scope.questypeList = function () {
  348. var qobj = {};
  349. qobj.funName = "questiontype";
  350. qobj.type = $scope.formData.type;
  351. qobj.lang = $rootScope.selLanguage;
  352. AppData.sendData($scope.commonurl, qobj, function (res) {
  353. if (res.cont) {
  354. $scope.questype = res.item;
  355. } else {
  356. $rootScope.modalShown = true;
  357. $rootScope.message = (res.mess);
  358. }
  359. })
  360. }
  361. $scope.addFun = function () {
  362. $scope.formLoad = true;
  363. $scope.listFound = false;
  364. $scope.search_box = false;
  365. $scope.formAction = "Add";
  366. $scope.formtitle = "Add Question";
  367. $scope.title = $rootScope.sideselect.title[0];
  368. $scope.selectedIndex = null;
  369. $(".supplieredit").prop('disabled', false);
  370. // $scope.questypeList();
  371. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  372. $scope.formData = {};
  373. $scope.formData.funName = "addquestion";
  374. $scope.formData.child = [];
  375. $scope.optdetail = []
  376. $scope.category = [];
  377. $scope.optdetail.push({ optid: 1, iscorrect: 0, opttext: "", score: "" });
  378. $scope.optdetail.push({ optid: 2, iscorrect: 0, opttext: "", score: "" });
  379. console.log($scope.optdetail)
  380. }
  381. $scope.addChoice = function () {
  382. var len = getMaxID($scope.optdetail);
  383. $scope.optdetail.push({ optid: len, iscorrect: 0, opttext: "", score: "" });
  384. console.log($scope.optdetail)
  385. }
  386. $scope.deleteChioce = function (index, item) {
  387. console.log(index, item)
  388. if ($scope.optdetail.length > 2) {
  389. if ($scope.optdetail != undefined) {
  390. var num = $scope.optdetail.indexOf(index);
  391. if (num != -1) {
  392. $scope.optdetail.splice(num, 1);
  393. console.log($scope.optdetail);
  394. }
  395. }
  396. if ($scope.formAction == "Add") {
  397. if ($scope.formData.child != undefined) {
  398. var num2 = $scope.formData.child.indexOf(item);
  399. if (num2 != -1) {
  400. $scope.formData.child.splice(num2, 1);
  401. }
  402. }
  403. }
  404. console.log($scope.optdetail, $scope.formData.child);
  405. }
  406. }
  407. $scope.closeForm = function () {
  408. $scope.formLoad = false;
  409. $scope.formData = {};
  410. $scope.selectedIndex = null;
  411. $scope.search_box = true;
  412. $scope.listFound = true;
  413. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  414. $scope.questionList();
  415. }
  416. $scope.questionSubmit = function () {
  417. $scope.formData.lang = $rootScope.selLanguage;
  418. $scope.formData.cateid = $scope.formData.lvl_id;
  419. // $scope.formData.tag=$scope.formData.tag;
  420. console.log($scope.formData.tag)
  421. var obj = selectcheckboxStatus($scope.pageData.errorMsg, $scope.formData.qtype);
  422. var arr = checkboxStatus();
  423. //console.log(arr)
  424. for (id = 0; id < arr.length; id++) {
  425. $scope.formData.child[arr[id]].iscorrect = 0;
  426. }
  427. var str = JSON.stringify($scope.formData.child);
  428. $scope.formData.child = str;
  429. // $scope.formData.tag=" ";
  430. console.log($scope.formData)
  431. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  432. if (res.cont) {
  433. $rootScope.modalShown = true;
  434. $rootScope.message = (res.mess);
  435. // $scope.formData.tag=''
  436. $scope.questionList();
  437. $scope.getTag();
  438. $scope.selectedIndex = null;
  439. $scope.formLoad = false;
  440. $scope.listFound = true;
  441. } else {
  442. $rootScope.modalShown = true;
  443. $rootScope.message = (res.mess);
  444. }
  445. })
  446. }
  447. // $scope.fieldValidation = function(){
  448. // $scope.type_error = ($scope.formData.type == undefined || $scope.formData.type == '') ? 'Please select the type' : '';
  449. // $scope.qtype_error = ($scope.formData.questiontypeid == undefined || $scope.formData.questiontypeid == '') ? 'Please select the Question type' : '';
  450. // $scope.ctype_error = ($scope.formData.lvl_id == undefined || $scope.formData.lvl_id == '') ? 'Please select the Category type' : '';
  451. // $scope.tag_error = ($scope.formData.tag == undefined || $scope.formData.tag == '') ? 'Please enter the tag' : '';
  452. // }
  453. $scope.certiQuestionSub = function () {
  454. $scope.formData.lang = $rootScope.selLanguage;
  455. var obj = selectcheckboxStatus($scope.pageData.errorMsg, $scope.formData.qtype);
  456. var arr = checkboxStatus();
  457. console.log(arr)
  458. for (id = 0; id < arr.length; id++) {
  459. $scope.formData.child[arr[id]].iscorrect = 0;
  460. }
  461. var str = JSON.stringify($scope.formData.child);
  462. $scope.formData.child = str;
  463. console.log(str)
  464. AppData.sendData($scope.pageurl, $scope.formData, function (res) {
  465. if (res.cont) {
  466. $rootScope.modalShown = true;
  467. $rootScope.message = (res.mess);
  468. $scope.cartiQuesList();
  469. $scope.selectedIndex = null;
  470. $scope.formLoad = false;
  471. $scope.listFound = true;
  472. } else {
  473. $rootScope.modalShown = true;
  474. $rootScope.message = (res.mess);
  475. }
  476. })
  477. }
  478. $scope.RemoveImage = function (obj) {
  479. current_imageObject = $(obj).parent().parent().find('img');
  480. current_imageObject.attr('src', "");
  481. $rootScope.image = '';
  482. }
  483. });
  484. });
  485. function getMaxID(arr) {
  486. var m = [];
  487. for (var id = 0; id < arr.length; id++) {
  488. m.push(arr[id].optid);
  489. }
  490. var MaxNum = Math.max.apply(null, m);
  491. return (MaxNum + 1);
  492. }
  493. function checkboxStatus() {
  494. var arr = [];
  495. var obj = document.getElementsByClassName("clsiscorrectbox");
  496. for (var id = 0; id < obj.length; id++) {
  497. var ms = obj[id];
  498. if (!ms.checked) {
  499. var index = String(ms.id).split("checkbox_")[1]
  500. arr.push(index);
  501. }
  502. }
  503. return arr;
  504. }
  505. function selectcheckboxStatus(arr, mid) {
  506. var marr = []
  507. var obj = document.getElementsByClassName("clsiscorrectbox");
  508. for (var id = 0; id < obj.length; id++) {
  509. var ms = obj[id];
  510. if (ms.checked) {
  511. marr.push(id);
  512. }
  513. }
  514. var obj = {};
  515. obj.cont = false;
  516. if (marr.length != 0) {
  517. if (mid == 1) {
  518. if (marr.length == 1) {
  519. obj.cont = true;
  520. } else {
  521. obj.cont = false;
  522. obj.mess = arr[2];
  523. }
  524. } else if (mid == 2) {
  525. obj.cont = true;
  526. }
  527. } else {
  528. obj.cont = false;
  529. obj.mess = arr[3];
  530. }
  531. return obj;
  532. }
  533. function onRemoveImage(obj) {
  534. current_imageObject = $(obj).parent().parent().find('img');
  535. // var iEl = angular.element( document.querySelector( '#store_image_1' ) );
  536. // iEl.remove();
  537. current_imageObject.attr('src', "");
  538. }
  539. function onclickimg(num) {
  540. console.log(num);
  541. console.log('#imgclick' + num);
  542. //$('#imgclick'+num).click();
  543. }
  544. function onAddImage(obj) {
  545. //current_imageObject= $(obj).parent().parent().find('img');
  546. //var num = current_imageObject.attr('data-id');
  547. console.log('#imgclick' + obj);
  548. //var element_string="<div><input type='file' id='informationimage"+num+"' data-id='"+num+"' name='informationimage' accept='image/*' onchange='readURL(this);' hidden /></div>";
  549. //$('body').append(element_string);
  550. //$('#imgclick'+obj).click();
  551. }
  552. function readURL(input) {
  553. var num = current_imageObject.attr('data-id');
  554. if (input.files && input.files[0]) {
  555. var reader = new FileReader();
  556. reader.onload = function (e) {
  557. console.log(num);
  558. $('#store_image_' + num)
  559. .attr('src', e.target.result)
  560. .width(119)
  561. .height(112);
  562. }
  563. reader.readAsDataURL(input.files[0]);
  564. }
  565. }