Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var idsub = [];
  2. var namesub = [];
  3. var matiereID = [];
  4.  
  5. var idteacher = [];
  6. var nameteacher = [];
  7. var teacherID = [];
  8.  
  9. var classNAME = [];
  10.  
  11. var count;
  12.  
  13. $(function () {
  14.  
  15.  
  16.     $("#count").change(function () {
  17.         $('#listsub').empty();
  18.         count = $('#count').val();
  19.         console.log(count);
  20.        
  21.         getsub();
  22.     });
  23.  
  24.  
  25.  
  26. });
  27.  
  28. function getsub() {
  29.  
  30.     var Tok = localStorage.getItem("Token")
  31.     $.ajax({
  32.         url: localStorage.getItem("URL") + '/api/subjects',
  33.         type: 'GET',
  34.         dataType: 'json',
  35.         headers: {
  36.             'Authorization': Tok,
  37.         },
  38.         contentType: 'application/json',
  39.         success: function (data) {
  40.             console.log(data.subjects);
  41.  
  42.             idsub = [];
  43.             namesub = [];
  44.             $.each(data.subjects, function (key, ob) {
  45.                 idsub.push(ob.id);
  46.                 namesub.push(ob.name);
  47.             });
  48.  
  49.             console.log(idsub);
  50.             console.log(namesub);
  51.             console.log(matiereID);
  52.  
  53.  
  54.             getteacher();
  55.  
  56.         },
  57.         error: function (XMLHttpRequest, textStatus, errorThrown) {
  58.             console.log(XMLHttpRequest.responseText);
  59.             console.log(XMLHttpRequest.status);
  60.         },
  61.     });
  62. }
  63.  
  64. function getteacher(){
  65.  
  66.     var data = [
  67.         {
  68.           "id": "1",
  69.           "name": "prof1"
  70.         },
  71.         {
  72.           "id": "2",
  73.           "name": "prof2"
  74.         },
  75.         {
  76.           "id": "3",
  77.           "name": "prof3"
  78.         }
  79.     ];
  80.  
  81.     idteacher = [];
  82.     nameteacher = [];
  83.     $.each(data, function (key, ob) {
  84.         idteacher.push(ob.id);
  85.         nameteacher.push(ob.name);
  86.     });
  87.  
  88.     console.log(idteacher);
  89.     console.log(nameteacher);
  90.     console.log(teacherID);
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. listcreate();
  99.  
  100. }
  101.  
  102.  
  103. function listcreate(){
  104.  
  105.     $('#listclass').empty();
  106.     for (var i = 0; i < count; i++) {
  107.        
  108.         $('#listclass').append('<ul data-role="listview" id="listclass'+ i +'"><li id="li' + i + '">' + '<input type="text" name="Nom de la classe" id="classname' + i + '" placeholder="Nom de la classe ' + i + '">' + '</li><select onchange="selectsub(this, ' + i + ');" name="selectsubjec' + i + '" id="subject' + i + '"><option value="none">matiere</option></select> <select onchange="selectteacher(this, ' + i + ');" name="selectteacher' + i + '" id="teacher' + i + '"><option value="none">prof</option></select>')
  109.  
  110.         $.each(namesub, function (index, sub) {
  111.             $('#subject' + i).append('<option value="' + index + '">' + sub + '</option>')
  112.         });
  113.  
  114.         $.each(nameteacher, function (index, sub) {
  115.             $('#teacher' + i).append('<option value="' + index + '">' + sub + '</option>')
  116.         });
  117.  
  118.     }
  119.  
  120. }
  121.  
  122. function selectsub(sel, indexsub) {
  123.  
  124.     matiereID[indexsub] = idsub[sel.value];
  125.     console.log(matiereID);
  126.  
  127. }
  128.  
  129. function selectteacher(sel, indexsub) {
  130.  
  131.     teacherID[indexsub] = idteacher[sel.value];
  132.     console.log(teacherID);
  133.  
  134. }
  135.  
  136. function sendclass(){
  137.  
  138.     for (var e = 0; e < count; e++) {
  139.  
  140.        
  141.  
  142.     }
  143.  
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement