training.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. define(['app'], function (app) {
  2. app.controller('TrainingCtrl', function ($scope,$rootScope,AppData,$location) {
  3. $rootScope.menucont = true;
  4. $rootScope.pageLoadComp = false;
  5. $scope.formLoad = false;
  6. $scope.listFound = false;
  7. $scope.pageData = trainingData[$rootScope.selLanguage];
  8. $scope.itemdetail = [];
  9. $scope.stateList = [];
  10. $scope.cityList = [];
  11. $scope.dealerList = [];
  12. $scope.stateVisible = false;
  13. $scope.cityVisible = false;
  14. $scope.dealerVisible = false;
  15. $scope.url = "../senddata/log/";
  16. $scope.pageurl = "../senddata/training/";
  17. $scope.exporturl = "../senddata/export/";
  18. $scope.commonurl = "../senddata/common/";
  19. $scope.search_box = true;
  20. $scope.submenu = $scope.pageData.sidemenu;
  21. $rootScope.sideselect = $scope.pageData.sidemenu[0];
  22. $scope.tblheading = $rootScope.sideselect.headingText;
  23. //pagination
  24. $scope.viewby = '10';
  25. $scope.currentPage = 1;
  26. $scope.itemsPerPage = $scope.viewby;
  27. $scope.maxSize = 5; //Number of pager buttons to show
  28. //Check Session//
  29. $scope.formData = {}
  30. $scope.formData.ismenuload = "Yes";
  31. if($rootScope.items == undefined || $rootScope.items == null){
  32. $scope.formData.ismenuload = "No";
  33. }
  34. $scope.formData.funName = "checksession";
  35. $scope.formData.lang = $rootScope.selLanguage;
  36. $scope.formData.start = 2;
  37. $scope.formData.limit = 5;
  38. //this page Variable//
  39. //$scope.roleitem = null;
  40. // delete the below
  41. $scope.cateitem = null;
  42. $scope.questionitem = null;
  43. $scope.assignquestionitem = [];
  44. $scope.assignquestionnum = [];
  45. $scope.mergecity = [];
  46. // delete end
  47. $scope.selectedLevel = 0;
  48. $scope.traininglevels = [];
  49. $scope.trainerlists = [];
  50. $scope.filterAvailable = false;
  51. $scope.dealerAvailable = false;
  52. $scope.participantAvailable = false;
  53. $scope.selectedtrainercity = [];
  54. $scope.filter_regions = [];
  55. $scope.selectedCityList = [];
  56. $scope.selectedCityDealer = [];
  57. $scope.filter_dealers = [];
  58. $scope.selectedcity_new=[];
  59. // $scope.trainerParticipantList = [];
  60. $scope.participant = [];
  61. $scope.selectedDealerParticipants = [];
  62. $scope.finalDealerParticipant = [];
  63. $scope.date =new Date();
  64. $scope.fullyear = $scope.date.getFullYear();
  65. $scope.curyear = $scope.date.getFullYear();
  66. $scope.curnmonth = $scope.date.getMonth();
  67. $scope.curnmonth = $scope.curnmonth + 1;
  68. $scope.minDate = $scope.date + 4;
  69. $scope.trainingduration = [{"day":1, "dur":"1 day"}, {"day":2, "dur":"2 day"}, {"day":3, "dur":"3 day"}, {"day":4, "dur":"4 day"}, {"day":5, "dur":"5 day"}];
  70. // $scope.tstart_time = [{"val":10, "time":"10:00"},{"val":11, "time":"11:00"},{"val":12, "time":"12:00"},{"val":13, "time":"13:00"},{"val":14, "time":"14:00"},{"val":15, "time":"15:00"}];
  71. $scope.tstart_time = $scope.pageData.training_time;
  72. $scope.trend_time = 16;
  73. $scope.notificationdate = [5, 4, 3, 2, 1];
  74. $scope.bufferdate = [5, 4, 3, 2, 1];
  75. // $scope.ass_duration = [15, 30, 45, 60, 75, 90, 105, 120];
  76. $scope.ass_duration = [
  77. {"value":"10","title":"10"},
  78. {"value":"15","title":"15"},
  79. {"value":"20","title":"20"},
  80. {"value":"25","title":"25"},
  81. {"value":"30","title":"30"},
  82. ]
  83. $scope.ass_type = [{"val":0, "txt":"Normal"}, {"val":1, "txt":"Random"}];
  84. AppData.sendData($scope.url,$scope.formData,function(res){
  85. if(res.cont){
  86. if($rootScope.items == undefined || $rootScope.items == null){
  87. $rootScope.items = res.item.control;
  88. }
  89. for(var i = 0; i < $rootScope.items.length; i++){
  90. if($location.path() == $rootScope.items[i].modulepath){
  91. $rootScope.modulename = $rootScope.items[i].modulename;
  92. $scope.usercontrol = String($rootScope.items[i].permission).split("|");
  93. }
  94. }
  95. $scope.statusobj = res.item.status;
  96. $rootScope.username = res.item.username;
  97. $scope.listFound = true;
  98. $scope.start_time = $scope.pageData.assessment_publish_time;
  99. $scope.end_time = $scope.pageData.assessment_publish_time;
  100. //$rootScope.role = res.item.role;
  101. $scope.trainingList();
  102. //$scope.moduleData();
  103. }else{
  104. $location.path("/login");
  105. }
  106. });
  107. $scope.trainingList = function(){
  108. $scope.search_show = true;
  109. $scope.searchvalue = ($scope.formData.mymodel!='')?$scope.formData.mymodel : "";
  110. var fobj = {};
  111. fobj.funName = "traininglist";
  112. if($rootScope.sideselect.id == 1){
  113. fobj.pn = $scope.currentPage;
  114. fobj.nr = $scope.itemsPerPage;
  115. }else{
  116. fobj.pn = '';
  117. fobj.nr = '';
  118. }
  119. fobj.month = $scope.curnmonth;
  120. fobj.year = $scope.curyear;
  121. fobj.lang = $rootScope.selLanguage;
  122. fobj.key = $scope.searchvalue;
  123. $rootScope.pageLoadComp = true;
  124. AppData.sendData($scope.pageurl,fobj,function(res){
  125. $rootScope.pageLoadComp = true;
  126. // if(res.cont && res.item.total_records>0){
  127. if(res.cont){
  128. if(res.item!= undefined){
  129. $scope.itemdetail = res.item.training;
  130. $scope.totalItems = res.item.total_records;
  131. $scope.listFound = true;
  132. $scope.formLoad = false;
  133. $scope.search_box = true;
  134. }
  135. }else{
  136. $scope.listFound = false;
  137. $scope.errorMsg = res.mess;
  138. }
  139. //$scope.roleitem=res.item.roleitem;
  140. })
  141. }
  142. $scope.setPage = function (pageNo) {
  143. $scope.currentPage = pageNo;
  144. };
  145. $scope.pageChanged = function() {
  146. $scope.trainingList();
  147. };
  148. $scope.setItemsPerPage = function(num) {
  149. $scope.itemsPerPage = num;
  150. $scope.currentPage = 1; //reset to first page
  151. $scope.trainingList();
  152. }
  153. $scope.filterData = function() {
  154. $scope.trainingList();
  155. }
  156. $scope.onSearchChange = function(){
  157. $scope.trainingList();
  158. }
  159. $scope.listClick = function(obj){
  160. $scope.searchtext='';
  161. $scope.formData={};
  162. $scope.currentPage = 1;
  163. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  164. $scope.formLoad = false;
  165. $rootScope.sideselect = obj;
  166. $scope.selectedIndex = null;
  167. $scope.tblheading = obj.headingText;
  168. $scope.trainingList();
  169. }
  170. $scope.deleterow = function(obj, i){
  171. $scope.formData = obj;
  172. $scope.selectedIndex = i;
  173. $scope.deleteFun();
  174. }
  175. $scope.exportrow = function(obj, i){
  176. $scope.formData = obj;
  177. $scope.selectedIndex = i;
  178. $scope.exportFun();
  179. }
  180. $scope.viewTiprow = function(obj, i){
  181. $scope.formData = obj;
  182. $scope.selectedIndex = i;
  183. $scope.viewTipFun();
  184. }
  185. $scope.viewrow = function(obj, i){
  186. $scope.formData = obj;
  187. $scope.selectedIndex = i;
  188. $scope.viewFun();
  189. }
  190. $scope.deleteFun = function(){
  191. if($scope.selectedIndex != null){
  192. $rootScope.cofirmWindow = true;
  193. $rootScope.modalShown =true;
  194. $rootScope.message=$scope.pageData.errorMsg[1];
  195. }else{
  196. $rootScope.modalShown =true;
  197. $rootScope.message=$scope.pageData.errorMsg[0];
  198. }
  199. }
  200. $scope.$on("confirmDelete",function(){
  201. if($scope.sideselect.id==1){
  202. $scope.formData.funName = "deletetraining";
  203. }else{
  204. $scope.formData.funName = "deleteassessmentuser";
  205. }
  206. AppData.sendData($scope.pageurl,$scope.formData,function(res){
  207. if(res.cont){
  208. if($scope.sideselect.id==1){
  209. var index = $scope.itemdetail.indexOf($scope.formData);
  210. if(index != -1){
  211. $scope.itemdetail.splice(index,1);
  212. }
  213. }else if($scope.sideselect.id==2){
  214. var index = $scope.participantdetail.indexOf($scope.formData);
  215. if(index != -1){
  216. $scope.participantdetail.splice(index,1);
  217. }
  218. }
  219. $rootScope.modalShown =true;
  220. $rootScope.cofirmWindow = false;
  221. $rootScope.message=(res.mess);
  222. }else{
  223. $rootScope.modalShown =true;
  224. $rootScope.message=(res.mess);
  225. }
  226. })
  227. })
  228. $scope.editrow = function(obj, i){
  229. var fobj = {};
  230. fobj.lang = $rootScope.selLanguage;
  231. fobj.funName="trainingdetails";
  232. fobj.schedule_id = obj.schedule_id
  233. AppData.sendData($scope.pageurl,fobj,function(res){
  234. $scope.formData = {};
  235. if(res.cont){
  236. if(res.item != undefined){
  237. $scope.formData = res.item[0];
  238. $scope.selectedIndex = i;
  239. $scope.search_box = false;
  240. $scope.formLoad = true;
  241. $scope.listFound = false;
  242. $scope.formData.ques_count = Number($scope.formData.ques_count);
  243. $scope.formData.startdate = $scope.formData.start_date;
  244. $scope.formData.enddate = $scope.formData.end_date;
  245. // $scope.formData.endtime =
  246. $scope.editFun();
  247. // $scope.formData.randomcond =
  248. }else{
  249. }
  250. }
  251. });
  252. }
  253. $scope.editFun = function(){
  254. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  255. if($scope.selectedIndex != null){
  256. $scope.selectedLevel = $scope.formData.lvl_id;
  257. $scope.formLoad = true;
  258. $scope.formAction = 'Edit';
  259. $scope.formTitle = "Edit Training";
  260. // $scope.tstart_time = [{"val":10, "time":"10:00"},{"val":11, "time":"11:00"},{"val":12, "time":"12:00"},{"val":13, "time":"13:00"},{"val":14, "time":"14:00"},{"val":15, "time":"15:00"}];
  261. // $scope.questionList();
  262. $scope.getTrainingLevel();
  263. $scope.getTrainerList();
  264. $scope.loadtrainerregion();
  265. var region_arr = JSON.parse($scope.formData.filter_region);
  266. var dealer_arr = JSON.parse($scope.formData.filter_dealer);
  267. var participant_arr = ($scope.formData.participant_id);
  268. $scope.formData.filter_regions = {};
  269. $scope.formData.filter_dealers = {};
  270. $scope.formData.trainerParticipantList = {};
  271. // $scope.selectedCityList=region_arr;
  272. angular.forEach(region_arr,function(item, i) {
  273. $scope.formData.filter_regions[item] = true;
  274. var tmp = {};
  275. tmp.city = item;
  276. $scope.trainerCityChange(tmp, i);
  277. })
  278. angular.forEach(dealer_arr,function(item, j) {
  279. $scope.formData.filter_dealers[item] = true;
  280. $scope.filter_dealers.push(item);
  281. var dobj = {};
  282. dobj.dealer_code = item;
  283. $scope.trainerDealerChange(item, j);
  284. })
  285. angular.forEach(participant_arr,function(item, k) {
  286. $scope.formData.trainerParticipantList[item] = true;
  287. })
  288. }else{
  289. $rootScope.modalShown =true;
  290. $rootScope.message=$scope.pageData.errorMsg[0];
  291. }
  292. }
  293. $scope.addFun = function(){
  294. $scope.formData = {}
  295. $scope.search_box = false;
  296. $scope.formLoad = true;
  297. $scope.listFound = false;
  298. $scope.filterAvailable = false;
  299. $scope.dealerAvailable = false;
  300. $scope.participantAvailable = false;
  301. $scope.selectedtrainercity=[];
  302. $scope.filter_regions = [];
  303. $scope.selectedCityList = [];
  304. $scope.selectedCityDealer = [];
  305. $scope.filter_dealers = [];
  306. $scope.formData.participant = [];
  307. $("input#myCheck").attr("disabled", true);
  308. $(".clsbuttoncont .clsbutton").addClass("disable_btn");
  309. $scope.formAction = 'Add';
  310. $scope.formData.funName = "addtraining";
  311. $scope.formTitle = "Add Training";
  312. // $scope.tstart_time = [{"val":10, "time":"10:00"},{"val":11, "time":"11:00"},{"val":12, "time":"12:00"},{"val":13, "time":"13:00"},{"val":14, "time":"14:00"},{"val":15, "time":"15:00"}];
  313. // $scope.questionList();
  314. $scope.getTrainingLevel();
  315. $scope.getTrainerList();
  316. $scope.formData.assessment_type="0";
  317. $(".datepick").datepicker({dateFormat:'yy-mm-dd',minDate:'2018-06-10' ,maxDate:'2018-07-10'});
  318. }
  319. // get the Training Level list Basic, Bronze, Silver, Gold
  320. $scope.getTrainingLevel = function(){
  321. var fobj = {};
  322. fobj.lang = $rootScope.selLanguage;
  323. fobj.funName="certificate_level";
  324. AppData.sendData($scope.commonurl,fobj,function(res){
  325. if(res.cont){
  326. if(res.item != undefined){
  327. $scope.topicVisible = true;
  328. if(res.item.length>0)
  329. {
  330. $scope.traininglevels = res.item;
  331. }
  332. }else{
  333. }
  334. }
  335. });
  336. }
  337. // Trainer List
  338. $scope.getTrainerList = function(){
  339. var fobj = {};
  340. fobj.lang = $rootScope.selLanguage;
  341. fobj.funName="trainerlist";
  342. AppData.sendData($scope.pageurl,fobj,function(res){
  343. if(res.cont){
  344. if(res.item != undefined){
  345. $scope.topicVisible = true;
  346. if(res.item.length>0)
  347. {
  348. $scope.trainerlists = res.item;
  349. }
  350. }else{
  351. }
  352. }
  353. });
  354. }
  355. $scope.selectedTrainingLevel = function(){
  356. $scope.selectedLevel = $scope.formData.lvl_id;
  357. $scope.formData.trainer_id = '';
  358. $scope.selectedtrainercity = [];
  359. $scope.selectedCityDealer = [];
  360. $scope.dealerParticipant = [];
  361. $scope.selectedCityList = [];
  362. $scope.finalDealerParticipant = [];
  363. $scope.filterAvailable = false;
  364. $scope.formData.filter_regions = {};
  365. $scope.formData.filter_dealers = {};
  366. $scope.formData.trainerParticipantList = {};
  367. }
  368. $scope.selectedstartTime = function(){
  369. $scope.tend_time = [];
  370. for(var i=$scope.formData.starttime; i<=$scope.trend_time; i++){
  371. var sval = Number(i)+1;
  372. var obj = {};
  373. obj.val = sval;
  374. obj.time = sval+":00";
  375. $scope.tend_time.push(obj);
  376. }
  377. $(".endtime").prop( "disabled", false );
  378. }
  379. $scope.loadtrainerregion = function(){
  380. $scope.selectedtrainercity = [];
  381. $scope.selectedCityDealer = [];
  382. $scope.dealerParticipant = [];
  383. $scope.selectedCityList = [];
  384. $scope.finalDealerParticipant = [];
  385. var fobj = {};
  386. fobj.lang = $rootScope.selLanguage;
  387. fobj.funName="city";
  388. fobj.trainer_id=$scope.formData.trainer_id;
  389. AppData.sendData($scope.commonurl,fobj,function(res){
  390. if(res.cont){
  391. $scope.filterAvailable = true;
  392. if(res.item != undefined){
  393. $scope.topicVisible = true;
  394. if(res.item.length>0)
  395. {
  396. $scope.selectedtrainercity = res.item;
  397. }
  398. }else{
  399. }
  400. }
  401. });
  402. }
  403. $scope.trainerCityChange = function(item, i,event){
  404. if ($scope.selectedcity_new.indexOf(item) === -1) {
  405. $scope.selectedcity_new.push(item);
  406. }
  407. else {
  408. $scope.selectedcity_new.splice($scope.selectedcity_new.indexOf(item), 1);
  409. }
  410. var fobj = {};
  411. fobj.lang = $rootScope.selLanguage;
  412. // fobj.funName="dealer";
  413. fobj.funName="dealer_v2";
  414. var index = $scope.selectedCityList.indexOf(item.city);
  415. angular.forEach($scope.selectedCityDealer,function(scdealer,i) {
  416. var sindex = item.city.indexOf(scdealer.city);
  417. if(sindex==0){
  418. $scope.selectedCityDealer.splice(i,1);
  419. if($scope.formData.filter_dealers!=undefined){
  420. $scope.formData.filter_dealers[scdealer.dealer_code] = false;
  421. }
  422. var dealerindex = $scope.filter_dealers.indexOf(scdealer.dealer_code);
  423. if(dealerindex>=0){
  424. $scope.filter_dealers.splice(dealerindex,1);
  425. // $scope.selectedDealerParticipants.splice(dealerindex,1);
  426. angular.forEach($scope.dealerParticipant,function(sdlpart,i) {
  427. var sindex = scdealer.dealer_code.indexOf(sdlpart.dealer_code);
  428. if(sindex==0){
  429. angular.forEach(sdlpart.user, function(usr, j){
  430. $scope.formData.trainerParticipantList[usr.userid] = false;
  431. })
  432. $scope.selectedDealerParticipants.splice(i,1);
  433. $scope.dealerParticipant.splice(i,1);
  434. }
  435. });
  436. // $scope.dealerParticipant.splice(dealerindex,1);
  437. }
  438. }
  439. })
  440. if(index != -1){
  441. $scope.selectedCityList.splice(index,1);
  442. // $scope.selectedcity_new.splice(index,1)
  443. }else{
  444. $scope.selectedCityList.push(item.city);
  445. fobj.city=item.city;
  446. AppData.sendData($scope.commonurl,fobj,function(res){
  447. if(res.cont){
  448. console.log(res)
  449. if(res.item != undefined){
  450. $scope.dealerAvailable = true;
  451. for(var j=0;j<res.item.length;j++){
  452. res.item[j].city = item.city;
  453. $scope.selectedCityDealer.push(res.item[j]);
  454. }
  455. // if(res.item.length>0)
  456. // {
  457. // for(var j=0;j<res.item.length;j++){
  458. // res.item[j].city = item.city;
  459. // $scope.selectedCityDealer.push(res.item[j]);
  460. // // $scope.selectedcity_new.push(res.item[j])
  461. // }
  462. // console.log($scope.selectedCityDealer)
  463. // }
  464. }else{
  465. }
  466. }
  467. });
  468. }
  469. var citylist = $scope.selectedCityList.toString();
  470. if(citylist==""){
  471. $scope.dealerAvailable = false;
  472. $scope.selectedCityDealer = [];
  473. $scope.participantAvailable = false;
  474. $scope.selectedDealerParticipants = [];
  475. $scope.dealerParticipant = [];
  476. $scope.formData.filter_dealers = [];
  477. $scope.filter_dealers = [];
  478. }
  479. // setTimeout(()=>{
  480. // console.log($scope.selectedCityDealer);
  481. // console.log($scope.selectedcity_new);
  482. // var a=[];
  483. // for(let i=0;i<$scope.selectedcity_new.length;i++){
  484. // for(let j=0;j<$scope.selectedCityDealer.length;j++){
  485. // if($scope.selectedcity_new[i].city == $scope.selectedCityDealer[j].city){
  486. // $scope.mergecity.push(Object.assign($scope.selectedcity_new[i],[$scope.selectedCityDealer[j]]));
  487. // }else{
  488. // console.log('else')
  489. // }
  490. // }
  491. // }
  492. // console.log($scope.mergecity)
  493. // },1000)
  494. // $scope.mergecity = $scope.selectedCityDealer.concat($scope.selectedcity_new);
  495. // console.log($scope.selectedcity_new)
  496. }
  497. $scope.trainerDealerChange = function(item, i){
  498. if($scope.selectedLevel==0){
  499. alert($scope.pageData.errorMsg[0]);
  500. $scope.formData.filter_dealers[item.dealer_code] = false;
  501. return;
  502. }
  503. var fobj = {};
  504. fobj.lang = $rootScope.selLanguage;
  505. fobj.funName="participantlist";
  506. fobj.lvl_id = $scope.selectedLevel;
  507. if($scope.formAction == 'Edit'){
  508. fobj.schedule_id = $scope.formData.schedule_id;
  509. $scope.selectedDealerParticipants = [];
  510. }
  511. angular.forEach($scope.dealerParticipant,function(sdlpart,i) {
  512. var sindex = item.dealer_code.indexOf(sdlpart.dealer_code);
  513. if(sindex==0){
  514. angular.forEach(sdlpart.user, function(usr, j){
  515. $scope.formData.trainerParticipantList[usr.userid] = false;
  516. })
  517. $scope.selectedDealerParticipants.splice(i,1);
  518. $scope.dealerParticipant.splice(i,1);
  519. }
  520. });
  521. // $scope.formData.trainerParticipantList[item] = true;
  522. var index = $scope.filter_dealers.indexOf(item.dealer_code);
  523. if(index >= 0){
  524. $scope.filter_dealers.splice(index,1);
  525. }else{
  526. $scope.filter_dealers.push(item.dealer_code);
  527. fobj.dealer=item.dealer_code;
  528. AppData.sendData($scope.pageurl,fobj,function(res){
  529. if(res.cont){
  530. if(res.item != undefined){
  531. $scope.participantAvailable = true;
  532. $scope.participantAvailable1 = false;
  533. if(res.item.length>0)
  534. {
  535. for(var j=0;j<res.item.length;j++){
  536. $scope.dealerParticipant.push(res.item[j]);
  537. if($scope.formAction=="Edit"){
  538. // for(var k=0; k< $scope.dealerParticipant.length; k++){
  539. // }
  540. if(res.item[j].user.length>0){
  541. angular.forEach(res.item[j].user, function(userdetail,k){
  542. var indexpart = $scope.formData.participant_id.indexOf(userdetail.userid);
  543. if(indexpart>=0){
  544. $scope.readytoAddParticipants(res.item[j], userdetail,indexpart);
  545. }
  546. })
  547. }
  548. }
  549. }
  550. }
  551. }else{
  552. $scope.participantAvailable1 = true;
  553. }
  554. }
  555. console.log($scope.dealerParticipant)
  556. });
  557. }
  558. var dealerlist = $scope.filter_dealers.toString();
  559. if(dealerlist==""){
  560. $scope.participantAvailable = false;
  561. if($scope.formAction != 'Edit'){
  562. $scope.selectedDealerParticipants = [];
  563. }
  564. $scope.dealerParticipant = [];
  565. }
  566. }
  567. $scope.readytoAddParticipant = function(dcode, dname, puserid, pname, i){
  568. // [{"day":1, "dur":"1 day"}, {"day":2, "dur":"2 day"}, {"day":3, "dur":"3 day"}, {"day":4, "dur":"4 day"}, {"day":5, "dur":"5 day"}];
  569. // var slist = $scope.selectedDealerParticipant;
  570. // if(slist.length>0){
  571. // for(var i=0; i<slist.length; i++){
  572. // for(var j=0; j<slist[i].user.length; j++){
  573. // return person.userid==puserid;
  574. // }))
  575. // // if(slist[i].user[j].userid.indexOf)
  576. // var pid = slist[i].user[j].userid.indexOf(puserid);
  577. // if(pid != -1){
  578. // // $scope.selectedDealerParticipant.user[j].userid.splice(pid,1);
  579. // // delete $scope.selectedDealerParticipant.user[j].
  580. // }else{
  581. // // $scope.filter_dealer.push(item.dealer_code);
  582. // $scope.selectedDealerParticipant.user[j].push({"userid":puserid, "name":pname});
  583. // }
  584. // }
  585. // }
  586. // }else{
  587. // $scope.selectedDealerParticipant.push({"dealer_code":dcode, "dealer_name":dname, "user":[{"userid":puserid, "name":pname}]});
  588. // }
  589. }
  590. $scope.readytoAddParticipants = function(dealer_data, user_data, i){
  591. var dindex = -1;
  592. var pindex = -1;
  593. var indx = -1;
  594. var dindx = -1;
  595. if($scope.selectedDealerParticipants.length>0){
  596. for(var i=0; i<$scope.selectedDealerParticipants.length; i++){
  597. if($scope.selectedDealerParticipants[i].dealer_code == dealer_data.dealer_code){
  598. if($scope.selectedDealerParticipants[i].user.length>0){
  599. indx=-1;
  600. for(var j=0; j<$scope.selectedDealerParticipants[i].user.length; j++){
  601. pindex = $scope.selectedDealerParticipants[i].user[j].userid.indexOf(user_data.userid);
  602. if(pindex>=0){
  603. indx = j;
  604. }
  605. }
  606. if(indx != -1){
  607. $scope.selectedDealerParticipants[i].user.splice(indx,1);
  608. }else{
  609. var udata = {};
  610. udata = user_data;
  611. $scope.selectedDealerParticipants[i].user.push(user_data);
  612. }
  613. }else{
  614. $scope.selectedDealerParticipants[i].user[0].push(user_data);
  615. }
  616. }
  617. dindex = $scope.selectedDealerParticipants[i].dealer_code.indexOf(dealer_data.dealer_code);
  618. if(dindex>=0){
  619. dindx = i;
  620. }
  621. }
  622. // if(dindex != -1){
  623. if(dindx != -1){
  624. for(var k=0; k<$scope.selectedDealerParticipants.length; k++){
  625. if($scope.selectedDealerParticipants[k].user.length==0){
  626. $scope.selectedDealerParticipants.splice(dindx,1);
  627. }
  628. }
  629. }else{
  630. // }else{
  631. var ddata = {};
  632. ddata.dealer_code = dealer_data.dealer_code;
  633. ddata.dealer_name = dealer_data.dealer_name;
  634. ddata.user = [];
  635. var udata = {};
  636. udata = user_data;
  637. ddata.user[0] = udata;
  638. $scope.selectedDealerParticipants.push(ddata);
  639. }
  640. }else{
  641. var ddata = {};
  642. ddata.dealer_code = dealer_data.dealer_code;
  643. ddata.dealer_name = dealer_data.dealer_name;
  644. ddata.user = [];
  645. var udata = {};
  646. udata = user_data;
  647. ddata.user[0] = udata;
  648. $scope.selectedDealerParticipants.push(ddata);
  649. }
  650. }
  651. $scope.addParticipant = function(){
  652. $scope.finalDealerParticipant = $scope.selectedDealerParticipants;
  653. }
  654. $scope.closeForm = function(){
  655. $scope.formLoad = false;
  656. $scope.formData = {};
  657. $scope.selectedIndex = null;
  658. $scope.search_box = true;
  659. $scope.listFound = true;
  660. $(".clsbuttoncont .clsbutton").removeClass("disable_btn");
  661. $scope.trainingList();
  662. }
  663. $scope.trainingSubmit = function(){
  664. sdate = new Date($scope.formData.start_date);
  665. edate = new Date($scope.formData.enddate);
  666. var diff_date = edate - sdate;
  667. var years = Math.floor(diff_date/31536000000);
  668. var months = Math.floor((diff_date % 31536000000)/2628000000);
  669. var days = Math.floor(((diff_date % 31536000000) % 2628000000)/86400000);
  670. if(days<0){
  671. $rootScope.modalShown =true;
  672. $rootScope.message=("Please select the date is greater than start date..");
  673. return;
  674. }
  675. // if($scope.formData.courseduration!=(days+1))
  676. // {
  677. // $rootScope.modalShown =true;
  678. // $rootScope.message=("Please select the correct date...");
  679. // return;
  680. // }
  681. if($scope.formAction == "Add"){
  682. $scope.formData.funName = "addtraining";
  683. }else{
  684. $scope.formData.funName = "edittraining";
  685. $scope.formData.schedule_id = $scope.formData.schedule_id;
  686. }
  687. $scope.formData.lang = $rootScope.selLanguage;
  688. $scope.formData.participant = [];
  689. var cnt=0;
  690. for(var i=0; i<$scope.selectedDealerParticipants.length;i++){
  691. for(var j=0; j<$scope.selectedDealerParticipants[i].user.length;j++){
  692. $scope.formData.participant[cnt]=$scope.selectedDealerParticipants[i].user[j].userid;
  693. cnt++;
  694. }
  695. }
  696. $scope.formData.filter_dealer = [];
  697. angular.forEach($scope.formData.filter_dealers,function(item,i) {
  698. $scope.formData.filter_dealer.push(i);
  699. })
  700. $scope.formData.filter_region = [];
  701. angular.forEach($scope.formData.filter_regions,function(item,j) {
  702. $scope.formData.filter_region.push(j);
  703. })
  704. if($scope.formData.participant.length==0){
  705. $rootScope.modalShown =true;
  706. $rootScope.message=("Please select any participant to schedule the training");
  707. return;
  708. }
  709. $scope.formData.filter_dealer = JSON.stringify($scope.formData.filter_dealer);
  710. $scope.formData.filter_region = JSON.stringify($scope.formData.filter_region);
  711. $scope.formData.participant = JSON.stringify($scope.formData.participant);
  712. $rootScope.modalShown =true;
  713. $rootScope.message=("Training ready to submit");
  714. AppData.sendData($scope.pageurl,$scope.formData,function(res){
  715. if(res.cont){
  716. $scope.trainingList();
  717. }else{
  718. $rootScope.modalShown =true;
  719. $rootScope.message=(res.mess);
  720. }
  721. })
  722. }
  723. //==
  724. });
  725. });