question - old.js 18 KB

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