| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- define(['app'], function (app) {
- app.controller('QuestionCtrl', function ($scope, $rootScope, AppData, $location) {
- //Every module Set Same Variable//
- $rootScope.menucont = true;
- $rootScope.pageLoadComp = false;
- $scope.formLoad = false;
- $scope.listFound = false;
- $scope.pageData = questionData[$rootScope.selLanguage];
- $scope.formAction = "Add";
- $rootScope.sideselect = $scope.pageData.sidemenu[0];
- console.log($rootScope.sideselect)
- $scope.itemdetail = [];
- $scope.selectedIndex = null;
- $rootScope.cofirmWindow = false;
- $scope.submenu = $scope.pageData.sidemenu;
- $scope.title = $rootScope.sideselect.name;
- $scope.tblheading = $rootScope.sideselect.headingText;
- $scope.url = "../senddata/log/";
- $scope.pageurl = "../senddata/question/";
- $scope.commonurl = "../senddata/common/";
- $rootScope.imageFormat = ["image/jpeg", "image/png", "video/mp4"];
- $rootScope.qimage = '';
- $scope.search_box = true;
- //pagination
- $scope.viewby = '10';
- $scope.currentPage = 1;
- $scope.itemsPerPage = $scope.viewby;
- $scope.maxSize = 5; //Number of pager buttons to show
- $scope.pageSize = 10;
- //Check Session//
- $scope.formData = {}
- $scope.formData.ismenuload = "Yes";
- if ($rootScope.items == undefined || $rootScope.items == null) {
- $scope.formData.ismenuload = "No";
- }
- $scope.formData.funName = "checksession";
- $scope.formData.lang = $rootScope.selLanguage;
- $scope.formData.start = 0;
- $scope.formData.limit = 2;
- //this page Variable//
- $scope.catearray = [];
- $scope.typearray = [];
- $scope.optdetail = [];
- AppData.sendData($scope.url, $scope.formData, function (res) {
- if (res.cont) {
- if ($rootScope.items == undefined || $rootScope.items == null) {
- $rootScope.items = res.item.control;
- }
- for (var i = 0; i < $rootScope.items.length; i++) {
- if ($location.path() == $rootScope.items[i].modulepath) {
- $rootScope.modulename = $rootScope.items[i].modulename;
- $scope.usercontrol = String($rootScope.items[i].permission).split("|");
- }
- }
- $scope.statusobj = res.item.status;
- $rootScope.username = res.item.username;
- $scope.questionList = function () {
- $scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
- var fobj = {};
- fobj.funName = "questionlist";
- fobj.lang = $rootScope.selLanguage;
- fobj.pn = $scope.currentPage;
- fobj.nr = $scope.itemsPerPage;
- fobj.lang = $rootScope.selLanguage;
- fobj.key = $scope.searchvalue;
- fobj.tag = ($scope.formData.tag!=undefined || $scope.formData.tag!='')?$scope.formData.tag:'';
- // fobj.cateid = 0;
- $rootScope.pageLoadComp = true;
- AppData.sendData($scope.pageurl, fobj, function (res) {
- $rootScope.pageLoadComp = true;
- if (res.cont) {
- if (res.item != undefined) {
- $scope.question_data = res.item.questions;
- $scope.totalItems = res.item.total_records;
- $scope.listFound = true;
- $scope.search_box = true;
- }
- } else {
- $scope.listFound = false;
- $scope.errorMsg = res.mess;
- }
- })
- }
- $scope.getTag = function () {
- var obj = {};
- obj.funName = "allquestiontag";
- obj.lang = $rootScope.selLanguage;
- obj.certified = "0";
- obj.is_survey = "0";
- obj.questiontypeid = "";
- AppData.sendData($scope.commonurl, obj, function (res) {
- $rootScope.pageLoadComp = true;
- if (res.cont) {
- if (res.item != undefined) {
- console.log(res.item)
- $scope.tagList = res.item;
-
- } else {
-
- }
- }
- });
- }
- $scope.changeTag = function(){
- $scope.questionList();
- $scope.getTag()
- }
- $scope.getTag()
- $scope.questionList();
- $scope.setPage = function (pageNo) {
- $scope.currentPage = pageNo;
- };
- $scope.pageChanged = function () {
- console.log('Page changed to: ' + $scope.currentPage);
- console.log('ItemPage : ' + $scope.viewby);
- $scope.questionList();
- };
- $scope.setItemsPerPage = function (num) {
- $scope.itemsPerPage = num;
- $scope.currentPage = 1; //reset to first page
- console.log('ItemPage : ' + $scope.itemsPerPage);
- $scope.questionList();
- }
- $scope.filterData = function () {
- console.log($scope.searchtext)
- $scope.questionList();
- }
- } else {
- $location.path("/login");
- }
- })
- $scope.onSearchChange = function () {
- console.log($scope.formData.mymodel)
- $scope.questionList();
- }
- $scope.cartiQuesList = function () {
- var fobj = {};
- fobj.funName = "questionlist";
- fobj.lang = $rootScope.selLanguage;
- fobj.pn = $scope.currentPage;
- fobj.nr = $scope.itemsPerPage;
- fobj.lang = $rootScope.selLanguage;
- fobj.key = $scope.searchtext;
- fobj.certified = 1;
- $rootScope.pageLoadComp = true;
- AppData.sendData($scope.pageurl, fobj, function (res) {
- $rootScope.pageLoadComp = true;
- if (res.cont) {
- if (res.item != undefined) {
- $scope.cert_ques_data = res.item.questions;
- $scope.totalItems = res.item.total_records;
- $scope.listFound = true;
- $scope.search_box = true;
- }
- $scope.formData = {}
- } else {
- $scope.listFound = false;
- $scope.errorMsg = res.mess;
- }
- })
- }
- $scope.listClick = function (obj) {
- $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
- $scope.formLoad = false;
- $rootScope.sideselect = obj;
- $scope.itemdetail = [];
- $scope.selectedIndex = null;
- var fobj = {};
- fobj.lang = $rootScope.selLanguage;
- fobj.funName = "questionlist";
- $scope.title = obj.name;
- if (obj.id == 1) {
- $scope.tblheading = obj.headingText;
- $scope.questionList();
- } else if (obj.id == 2) {
- $scope.tblheading = obj.headingText;
- $scope.cartiQuesList();
- }
- }
- $scope.changeRemarks = function () {
- if ($scope.formData.rtype == 2 || $scope.formData.rtype == 3) {
- $scope.optdetail = [];
- $scope.optdetail.push({ optid: 1, iscorrect: 0, opttext: "", score: "" });
- $scope.optdetail.push({ optid: 2, iscorrect: 0, opttext: "", score: "" });
- console.log($scope.optdetail)
- }
- }
- /*$scope.curRowClick = function(obj,e){
- $scope.formData = obj
- $scope.selectedIndex = e;
- }*/
- $scope.deleterow = function (obj, i) {
- $scope.formData = obj;
- $scope.selectedIndex = i;
- $scope.deleteFun();
- }
-
- $scope.editrow = function (obj, i) {
- console.log(obj)
- $scope.formData = obj;
- $scope.selectedIndex = i;
- console.log($scope.formData);
- $scope.search_box = false;
- $scope.formLoad = true;
- $scope.listFound = false;
- $rootScope.qimage = '';
- if ($scope.formData.qtype == 3) {
- $scope.formData.rtype = $scope.formData.surveyqtype;
- $scope.category = $scope.surveycatearray;
- } else {
- $scope.category = $scope.catearray;
- $scope.formData.cattype = $scope.formData.cattype;
- }
- $scope.editFun();
- }
- $scope.viewTiprow = function (obj, i) {
- $scope.formData = obj;
- $scope.selectedIndex = i;
- $scope.viewTipFun();
- }
- $scope.viewrow = function (item, i) {
- var obj = {};
- obj.id = item.id;
- obj.funName = "questiondetails";
- AppData.sendData($scope.pageurl, obj, function (res) {
- if (res.cont) {
- $scope.view_question = res.item;
- //console.log($scope.view_question)
- // console.log($scope.view_question[0].options)
-
- // $scope.optdetail = res.item;
- }
- })
- // angular.forEach($scope.question_data,function(element) {
- // if(element.id==obj.id){
- // console.log(element)
- // $scope.view_question = element;
- // }
- // });
- }
- $scope.editFun = function () {
- $scope.questypeList();
- $scope.getTrainingLevel();
- if ($scope.optdetail != undefined && $scope.optdetail != '') {
- if ($scope.optdetail.length < 0) {
- $scope.formData.child = [];
- }
- } else {
- $scope.formData.child = [];
- }
- console.log($scope.optdetail)
- $scope.formtitle = "Edit Question";
- $scope.formData.funName = "editquestion";
- $(".clsbuttoncont .clsbutton").addClass("disable_btn");
- $scope.formData.lvl_id = $scope.formData.cateid
- if ($scope.selectedIndex != null) {
- if ($scope.formData.questiontypeid == '1' || $scope.formData.questiontypeid == '2' || $scope.formData.questiontypeid == '5' || $scope.formData.questiontypeid == '6') {
- console.log($scope.formData.qtype)
- var obj = {};
- obj.id = $scope.formData.id;
- obj.funName = "questionoptionlist";
- AppData.sendData($scope.pageurl, obj, function (res) {
- if (res.cont) {
- $scope.formData.child = res.item;
- console.log($scope.formData.child)
- $scope.optdetail = res.item;
-
- }
- })
- }
- $scope.formLoad = true;
- $scope.formAction = "Edit";
- // $scope.title = $rootScope.sideselect.title[1];
-
- } else {
- $rootScope.modalShown = true;
- $rootScope.message = $scope.pageData.errorMsg[0];
- }
- }
- $scope.deleteFun = function () {
- if ($scope.selectedIndex != null) {
- $rootScope.cofirmWindow = true;
- $rootScope.modalShown = true;
- $rootScope.message = $scope.pageData.errorMsg[1];
- } else {
- $rootScope.modalShown = true;
- $rootScope.message = $scope.pageData.errorMsg[0];
- }
- }
- $scope.$on("confirmDelete", function () {
- $scope.formData.funName = "deletequestion";
- AppData.sendData($scope.pageurl, $scope.formData, function (res) {
- if (res.cont) {
- if ($rootScope.sideselect.id == 1) {
- var index = $scope.question_data.indexOf($scope.formData);
- if (index != -1) {
- $scope.question_data.splice(index, 1);
- }
- } else if ($rootScope.sideselect.id == 2) {
- var index = $scope.cert_ques_data.indexOf($scope.formData);
- if (index != -1) {
- $scope.cert_ques_data.splice(index, 1);
- }
- }
- $rootScope.modalShown = true;
- $rootScope.cofirmWindow = false;
- $rootScope.message = (res.mess);
- } else {
- $rootScope.modalShown = true;
- $rootScope.message = (res.mess);
- }
- })
- })
- //$scope.optionshow = false;
- $scope.changeQuestype = function () {
- if ($scope.formData.questiontypeid == 1 || $scope.formData.questiontypeid == 2 || $scope.formData.questiontypeid == 5 || $scope.formData.questiontypeid == 6) {
- //$scope.optionshow = true;
- $scope.optdetail = [];
- $scope.optdetail.push({ optid: 1, iscorrect: 0, opttext: "", score: "" });
- $scope.optdetail.push({ optid: 2, iscorrect: 0, opttext: "", score: "" });
- console.log($scope.optdetail)
- } else {
- //$scope.optionshow = false;
- $scope.optdetail = [];
- }
- }
- $scope.changetype = function () {
- if ($scope.formData.type == 1) {
- $scope.questypeList();
- $scope.getTrainingLevel()
- } else {
- $scope.questypeList();
- }
- }
- // get the Training Level list Basic, Bronze, Silver, Gold
- $scope.getTrainingLevel = function () {
- var fobj = {};
- fobj.lang = $rootScope.selLanguage;
- fobj.type = '1';
- fobj.funName = "certificate_level";
- AppData.sendData($scope.commonurl, fobj, function (res) {
- if (res.cont) {
- if (res.item != undefined) {
- $scope.topicVisible = true;
- if (res.item.length > 0) {
- $scope.traininglevels = res.item;
- }
- } else {
- }
- }
- });
- }
- $scope.questypeList = function () {
- var qobj = {};
- qobj.funName = "questiontype";
- qobj.type = $scope.formData.type;
- qobj.lang = $rootScope.selLanguage;
- AppData.sendData($scope.commonurl, qobj, function (res) {
- if (res.cont) {
- $scope.questype = res.item;
- } else {
- $rootScope.modalShown = true;
- $rootScope.message = (res.mess);
- }
- })
- }
- $scope.addFun = function () {
- $scope.formLoad = true;
- $scope.listFound = false;
- $scope.search_box = false;
- $scope.formAction = "Add";
- $scope.formtitle = "Add Question";
- $scope.title = $rootScope.sideselect.title[0];
- $scope.selectedIndex = null;
- $(".supplieredit").prop('disabled', false);
- // $scope.questypeList();
- $(".clsbuttoncont .clsbutton").addClass("disable_btn");
- $scope.formData = {};
- $scope.formData.funName = "addquestion";
- $scope.formData.child = [];
- $scope.optdetail = []
- $scope.category = [];
- $scope.optdetail.push({ optid: 1, iscorrect: 0, opttext: "", score: "" });
- $scope.optdetail.push({ optid: 2, iscorrect: 0, opttext: "", score: "" });
- console.log($scope.optdetail)
- }
- $scope.addChoice = function () {
- var len = getMaxID($scope.optdetail);
- $scope.optdetail.push({ optid: len, iscorrect: 0, opttext: "", score: "" });
- console.log($scope.optdetail)
- }
- $scope.deleteChioce = function (index, item) {
- console.log(index, item)
- if ($scope.optdetail.length > 2) {
- if ($scope.optdetail != undefined) {
- var num = $scope.optdetail.indexOf(index);
- if (num != -1) {
- $scope.optdetail.splice(num, 1);
- console.log($scope.optdetail);
- }
- }
- if ($scope.formAction == "Add") {
- if ($scope.formData.child != undefined) {
- var num2 = $scope.formData.child.indexOf(item);
- if (num2 != -1) {
- $scope.formData.child.splice(num2, 1);
- }
- }
- }
- console.log($scope.optdetail, $scope.formData.child);
- }
- }
- $scope.closeForm = function () {
- $scope.formLoad = false;
- $scope.formData = {};
- $scope.selectedIndex = null;
- $scope.search_box = true;
- $scope.listFound = true;
- $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
- $scope.questionList();
- }
- $scope.questionSubmit = function () {
- $scope.formData.lang = $rootScope.selLanguage;
- $scope.formData.cateid = $scope.formData.lvl_id;
- // $scope.formData.tag=$scope.formData.tag;
- console.log($scope.formData.tag)
- var obj = selectcheckboxStatus($scope.pageData.errorMsg, $scope.formData.qtype);
- var arr = checkboxStatus();
- //console.log(arr)
- for (id = 0; id < arr.length; id++) {
- $scope.formData.child[arr[id]].iscorrect = 0;
- }
- var str = JSON.stringify($scope.formData.child);
- $scope.formData.child = str;
- // $scope.formData.tag=" ";
- console.log($scope.formData)
- AppData.sendData($scope.pageurl, $scope.formData, function (res) {
- if (res.cont) {
- $rootScope.modalShown = true;
- $rootScope.message = (res.mess);
- // $scope.formData.tag=''
- $scope.questionList();
- $scope.getTag();
-
- $scope.selectedIndex = null;
- $scope.formLoad = false;
- $scope.listFound = true;
- } else {
- $rootScope.modalShown = true;
- $rootScope.message = (res.mess);
- }
- })
-
- }
- // $scope.fieldValidation = function(){
- // $scope.type_error = ($scope.formData.type == undefined || $scope.formData.type == '') ? 'Please select the type' : '';
- // $scope.qtype_error = ($scope.formData.questiontypeid == undefined || $scope.formData.questiontypeid == '') ? 'Please select the Question type' : '';
- // $scope.ctype_error = ($scope.formData.lvl_id == undefined || $scope.formData.lvl_id == '') ? 'Please select the Category type' : '';
- // $scope.tag_error = ($scope.formData.tag == undefined || $scope.formData.tag == '') ? 'Please enter the tag' : '';
-
- // }
- $scope.certiQuestionSub = function () {
- $scope.formData.lang = $rootScope.selLanguage;
- var obj = selectcheckboxStatus($scope.pageData.errorMsg, $scope.formData.qtype);
- var arr = checkboxStatus();
- console.log(arr)
- for (id = 0; id < arr.length; id++) {
- $scope.formData.child[arr[id]].iscorrect = 0;
- }
- var str = JSON.stringify($scope.formData.child);
- $scope.formData.child = str;
- console.log(str)
- AppData.sendData($scope.pageurl, $scope.formData, function (res) {
- if (res.cont) {
- $rootScope.modalShown = true;
- $rootScope.message = (res.mess);
- $scope.cartiQuesList();
- $scope.selectedIndex = null;
- $scope.formLoad = false;
- $scope.listFound = true;
- } else {
- $rootScope.modalShown = true;
- $rootScope.message = (res.mess);
- }
- })
- }
- $scope.RemoveImage = function (obj) {
- current_imageObject = $(obj).parent().parent().find('img');
- current_imageObject.attr('src', "");
- $rootScope.image = '';
- }
- });
- });
- function getMaxID(arr) {
- var m = [];
- for (var id = 0; id < arr.length; id++) {
- m.push(arr[id].optid);
- }
- var MaxNum = Math.max.apply(null, m);
- return (MaxNum + 1);
- }
- function checkboxStatus() {
- var arr = [];
- var obj = document.getElementsByClassName("clsiscorrectbox");
- for (var id = 0; id < obj.length; id++) {
- var ms = obj[id];
- if (!ms.checked) {
- var index = String(ms.id).split("checkbox_")[1]
- arr.push(index);
- }
- }
- return arr;
- }
- function selectcheckboxStatus(arr, mid) {
- var marr = []
- var obj = document.getElementsByClassName("clsiscorrectbox");
- for (var id = 0; id < obj.length; id++) {
- var ms = obj[id];
- if (ms.checked) {
- marr.push(id);
- }
- }
- var obj = {};
- obj.cont = false;
- if (marr.length != 0) {
- if (mid == 1) {
- if (marr.length == 1) {
- obj.cont = true;
- } else {
- obj.cont = false;
- obj.mess = arr[2];
- }
- } else if (mid == 2) {
- obj.cont = true;
- }
- } else {
- obj.cont = false;
- obj.mess = arr[3];
- }
- return obj;
- }
- function onRemoveImage(obj) {
- current_imageObject = $(obj).parent().parent().find('img');
- // var iEl = angular.element( document.querySelector( '#store_image_1' ) );
- // iEl.remove();
- current_imageObject.attr('src', "");
- }
- function onclickimg(num) {
- console.log(num);
- console.log('#imgclick' + num);
- //$('#imgclick'+num).click();
- }
- function onAddImage(obj) {
- //current_imageObject= $(obj).parent().parent().find('img');
- //var num = current_imageObject.attr('data-id');
- console.log('#imgclick' + obj);
- //var element_string="<div><input type='file' id='informationimage"+num+"' data-id='"+num+"' name='informationimage' accept='image/*' onchange='readURL(this);' hidden /></div>";
- //$('body').append(element_string);
- //$('#imgclick'+obj).click();
- }
- function readURL(input) {
- var num = current_imageObject.attr('data-id');
- if (input.files && input.files[0]) {
- var reader = new FileReader();
- reader.onload = function (e) {
- console.log(num);
- $('#store_image_' + num)
- .attr('src', e.target.result)
- .width(119)
- .height(112);
- }
- reader.readAsDataURL(input.files[0]);
- }
- }
|