loco.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. body.on('change','#series',function(){requestSections(this);});
  2. body.on('change','#sections',function(){requestSectionContent(this);});
  3. body.on('change','#projecttypes',function(){showSeries(this);});
  4. body.on('change','#letter_tasktype',function(){changeTaskTypeLetter(this);});
  5. body.on('click','#delete_section',function(){requestDeleteSection();});
  6. body.on('click','#add_new_section',function(){showAddSectionDialog();});
  7. body.on('click','#write_section',function(){requestAddSection();});
  8. body.on('click','#getsectionlist',function(){getSectionList();});
  9. body.on('click','#addseriestopt',function(){addSeriesToProjecttype();});
  10. body.on('click','#write_project_to_twx',function(){writeProjectTWX();});
  11. body.on('click','#project_complete',function(){projectComplete();});
  12. body.on('click','#project_limit',function(){projectLimit();});
  13. body.on('click','#get_sections_from_twx',function(){getSectionsFromTWX(this);});
  14. var activeproj = $("#activeproj").val();
  15. // body.on('click','#add_new_series',function(){requestAddSeries();});
  16. var chosen_section_id = 0;
  17. var chosen_series = '';
  18. var chosen_projecttype = -1;
  19. $(function() {
  20. if (page != 'projects')
  21. GetSeries();
  22. if (page == 'project_types')
  23. showSeries(null);
  24. });
  25. function checkAnswerTWX()
  26. {
  27. var text = $("#result").html();
  28. var yes = text.includes("error");
  29. if (!yes)
  30. Reload();
  31. }
  32. function getSectionsFromTWX(button) {
  33. // alert("activeproj "+activeproj);
  34. var dict = new Object(); //or Map()
  35. dict['get_sections_from_twx'] = activeproj;
  36. sendAjax('result', dict, checkAnswerTWX, 'loco_response.php');
  37. }
  38. function changeTaskTypeLetter(select) {
  39. var letter = select.options[select.selectedIndex].value;
  40. var dict = new Object(); //or Map()
  41. var activett = $("#active_task_type").val();
  42. dict['letter'] = letter;
  43. dict['letter_tasktype'] = activett;
  44. sendAjax('result', dict, Reload, 'loco_response.php');
  45. }
  46. function projectLimit()
  47. {
  48. var current = $("#project_limit").val();
  49. var activeproj = $("#activeproj").val();
  50. if (current == 'Все')
  51. $("#project_limit").val('20');
  52. else
  53. $("#project_limit").val('Все');
  54. SelectProject(activeproj);
  55. // window.location.reload();
  56. }
  57. function projectComplete()
  58. {
  59. var dict = new Object(); //or Map()
  60. var activeproj = $("#activeproj").val();
  61. dict['project_complete'] = activeproj;
  62. dict['userId'] = $("#userId").val();
  63. sendAjax('result', dict, Reload, 'loco_response.php');
  64. }
  65. function writeProjectTWX()
  66. {
  67. var activeproj = $("#activeproj").val();
  68. msgWindow=window.open("writeproject.php?id="+activeproj,"displayWindow",'width=750,height=600,screenX=100,resizable=yes,scrollbars=yes');
  69. // var dict = new Object(); //or Map()
  70. //
  71. // dict['write_project_to_twx'] = activeproj;
  72. // sendAjax('result', dict, null, 'loco_response.php');
  73. }
  74. function addSeriesToProjecttype()
  75. {
  76. var activept = $("#activeptid").val();
  77. var select = $("#loco_type")[0];
  78. series = select.options[select.selectedIndex].value;
  79. var dict = new Object(); //or Map()
  80. dict['pt_addseries'] = activept;
  81. dict['series'] = series;
  82. sendAjax('result', dict, Reload, 'loco_response.php');
  83. }
  84. function showSeries(select) {
  85. var series = $("#activeptid").val();
  86. if (select != null) {
  87. series = select.options[select.selectedIndex].value;
  88. }
  89. chosen_projecttype = series;
  90. var dict = new Object(); //or Map()
  91. dict['showseries'] = series;
  92. sendAjax('chooseseries', dict, null, 'loco_response.php');
  93. GetSeries();
  94. }
  95. function getSectionList() {
  96. var dict = new Object(); //or Map()
  97. dict['getsectionlist'] = 1;
  98. sendAjax('result', dict, null, 'loco_response.php');
  99. }
  100. function showAddSectionDialog() {
  101. $("#section_content").html('');
  102. $("#add_section_container").css("display", "inline-block");
  103. }
  104. function requestAddSection() {
  105. var number = $("#number").val();
  106. var subnumber = $("#subnumber").val();
  107. var section_letter = $("#section_letter").val();
  108. $("#section_content").html('');
  109. var dict = new Object(); //or Map()
  110. dict['addsections'] = chosen_series;
  111. dict['number'] = number;
  112. dict['subnumber'] = subnumber;
  113. dict['section_letter'] = section_letter;
  114. sendAjax('result', dict, null, 'loco_response.php');
  115. GetSeries();
  116. var seriesSelect = $("#series")[0];
  117. requestSections(seriesSelect);
  118. // alert("chosen_series "+chosen_series);
  119. }
  120. function requestDeleteSection() {
  121. if (chosen_section_id > 0) {
  122. var dict = new Object(); //or Map()
  123. dict['delsection'] = chosen_section_id;
  124. sendAjax('result', dict, DeleteSection, 'loco_response.php');
  125. return true;
  126. }
  127. return false;
  128. }
  129. function DeleteSection() {
  130. var seriesSelect = $("#series")[0];
  131. requestSections(seriesSelect);
  132. $("#section_content").html('');
  133. GetSeries();
  134. return true;
  135. }
  136. function GetSeries() {
  137. var dict = new Object(); //or Map()
  138. dict[ 'getseries' ] = -1;//chosen_projecttype;
  139. sendAjax('', dict, ReceiveSeries, 'loco_response.php');
  140. return true;
  141. }
  142. function ReceiveSeries(data) {
  143. // $("#result").html(data);
  144. // alert("page "+page);
  145. data = JSON.parse(data);
  146. var htm = "<option value='0'><Выберите серию локомотива></option>";
  147. Object.keys(data).forEach(function(id, i, arr) {
  148. var serie = data[id][0];
  149. var uuids = data[id][1];
  150. var all = data[id][2];
  151. var numproj = data[id][3];
  152. if (page == 'project_types' || page == 'projects')
  153. htm += "<option value='"+serie+"'>"+serie+"</option>";
  154. else
  155. htm += "<option value='"+serie+"'>"+serie+" [Секций из АСУ СГ: "+uuids+", всего секций: "+all+", проектов: "+numproj+"]</option>";
  156. });
  157. $("#series").html(htm);
  158. if (chosen_series != '')
  159. $('#series option[value="'+chosen_series+'"]').prop('selected', true);
  160. // $('#series option:contains("'+chosen_series+'")').prop('selected', true);
  161. if (page == 'projects'){
  162. $("#sections_load").css("display", "none");
  163. $("#add_new_section").css("display", "none");
  164. }
  165. }
  166. function requestSections(select) {
  167. if (page == 'projects')
  168. return;
  169. var series = select.options[select.selectedIndex];
  170. if (series.value == 0)
  171. {
  172. $("#sections_container").css("display", "none");
  173. }
  174. else {
  175. $("#sections_container").css("display", "block");
  176. }
  177. chosen_series = series.value;
  178. var dict = new Object(); //or Map()
  179. $("#result").html('');
  180. dict[ 'getsections' ] = series.value;
  181. sendAjax('', dict, ReceiveSections, 'loco_response.php');
  182. return true;
  183. }
  184. function ReceiveSections(data) {
  185. var select = $("#series")[0];
  186. var series = select.options[select.selectedIndex].value;
  187. // if (page != 'projects')
  188. $("#add_new_section").val('Добавить новую секцию серии: '+series);
  189. // else {
  190. //
  191. // $("#sections_load").css("display", "none");
  192. // $("#add_new_section").css("display", "none");
  193. // }
  194. $("#chosenserie").html('Список секций серии '+series);
  195. data = JSON.parse(data);
  196. if (data.length > 0) {
  197. var htm = "<option value='0'><Выберите секцию></option>";
  198. data.forEach(function(section, i, arr) {
  199. var uuid = "";
  200. if (section.uuid != null)
  201. {
  202. uuid = ' [АСУ СГ]';
  203. }
  204. htm += "<option value='"+section.id+"'>"+section.section_number+" "+section.section_subnumber+uuid+" Проектов: "+section.projectsAmount+" </option>";
  205. });
  206. $("#sections").html(htm);
  207. }
  208. else
  209. $("#sections").html("<option value='0'>--Нет секций--</option>");
  210. }
  211. function requestSectionContent(select) {
  212. if (page != 'projects') {
  213. var section = select.options[select.selectedIndex];
  214. $("#add_section_container").css("display", "none");
  215. if (section.value == 0) {
  216. $("#section_container").css("display", "none");
  217. }
  218. else
  219. $("#section_container").css("display", "block");
  220. var dict = new Object(); //or Map()
  221. dict['getsectioncontent'] = section.value;
  222. $("#result").html('');
  223. sendAjax('', dict, ReceiveSectionContent, 'loco_response.php');
  224. return true;
  225. }
  226. }
  227. function ReceiveSectionContent(data) {
  228. // $("#result").html(data);
  229. data = JSON.parse(data);
  230. var section = data[0];
  231. if (section.id > 0) {
  232. chosen_section_id = section.id;
  233. var DKs = data[1];
  234. var projects = data[2];
  235. $("#section_content").html(
  236. "<strong>["+section.id+"] "+section.section_number +" "+section.section_subnumber+"</strong><br><b>UUID:</b> "
  237. +section.uuid
  238. +"<br><b>Диагностическая карта: </b>"+section.diagnostic_map
  239. +"<br><b>Проекты:</b> "+projects.length
  240. +"<br><b>DKLen: </b>"+DKs.length
  241. );
  242. for (var i=0; i < DKs.length; i++ ) {
  243. $("#section_content").append("<br><b>Диагностическая карта "+(i+1)+":</b> "+DKs[i].uuid);
  244. }
  245. }
  246. else
  247. $("#section_content").html("Нет данных");
  248. }