assignment.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. function createAssignmentForm(assID, url){
  2. initAssignmentTable();
  3. $('#assignmentstation').find('option').remove()
  4. $.ajax({
  5. type: "GET",
  6. url: "../server/",
  7. dataType: "xml",
  8. success: function(xml) {
  9. $(xml).find('station').each(function(index){
  10. $('#assignmentstation').append('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
  11. });
  12. }
  13. });
  14. if (assID == null){
  15. $('#storedassignments').css("display", "none");
  16. $('#assignmentLupe').css("display", "block");
  17. $('#addExternalImageAssignment').removeAttr('disabled');
  18. $('#addExternalImageAssignment').val("");
  19. }
  20. else{
  21. $('#storedassignments').css("display", "block");
  22. $('#assignmentLupe').css("display", "none");
  23. $('#addExternalImageAssignment').attr('disabled','disabled');
  24. $('#addExternalImageAssignment').val(url);
  25. //Show Assignments
  26. $.getJSON( "../server/assignments/" + assID, function( data ) {
  27. console.log(data);
  28. $.each( data, function(i, alldata){
  29. var clonePattern = $("#copyAssignmentTable").clone();
  30. $('td',clonePattern).text("");
  31. $('[data-class=station]',clonePattern).text(i);
  32. $('#assignmentdetaillist').append(clonePattern);
  33. $('#assignmentdetaillist').append(clonePattern);
  34. $.each( alldata, function(i, pattern){
  35. var clonePattern = $("#copyAssignmentTable").clone();
  36. $('td',clonePattern).text("");
  37. $.each( pattern, function(i, item){
  38. console.log(i);
  39. $('[data-class=part' + i + ']',clonePattern).text(item);
  40. });
  41. $('[data-class=delete]',clonePattern).html('<a href="javascript:deleteSingleAssignment(' + assID +', ' + i + ');">[⨯]</a>');
  42. $('#assignmentdetaillist').append(clonePattern);
  43. });
  44. });
  45. });
  46. }
  47. $('#assignment_details').css("display", "block");
  48. }
  49. //called when new image is selected
  50. function getImgText(imgtext){
  51. var result = /[^;]*$/.exec(imgtext)[0];
  52. if(result != imgtext){
  53. $('#assignmentText').val(result.replace(/\.[^/.]+$/, ""))
  54. }
  55. }
  56. function submitAssignment(){
  57. var obj = new Object();
  58. obj.img = $('#addExternalImageAssignment').val();
  59. obj.station = $('#assignmentstation option:selected').text();
  60. obj.parts = {};
  61. abk.forEach(function(item){
  62. if(typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined' && typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined'){
  63. //if($("#FormPatternAssignment_Form_" + item).find(":selected").text() != ""){
  64. obj.parts[item] = $("#FormPatternAssignment_Form_" + item).find(":selected").text();
  65. //}
  66. }
  67. });
  68. obj.assignmentText = $('#assignmentText').val();
  69. $.ajax({
  70. type: "Post",
  71. data: JSON.stringify(obj),
  72. headers: {"content-id": "list"},
  73. contentType: "application/json",
  74. url: "../server/assignments/",
  75. success: function(res) {
  76. },
  77. error: function (request, status, error) {
  78. alert(request.responseText + status + error);
  79. }
  80. });
  81. }
  82. function deleteAssignment(assignmentID) { //Delete From DB
  83. if (confirm('Are you really, really, REALLY sure!')) {
  84. $.ajax({
  85. type: "DELETE",
  86. url: "../server/assignments/" + assignmentID,
  87. success: function(res) {
  88. location.reload();
  89. }
  90. });
  91. }
  92. }
  93. function deleteSingleAssignment(assignmentID, patternID) { //Delete From DB
  94. if (confirm('Are you really, really, REALLY sure!')) {
  95. $.ajax({
  96. type: "DELETE",
  97. url: "../server/assignments/" + assignmentID + "/" + patternID,
  98. success: function(res) {
  99. location.reload();
  100. }
  101. });
  102. }
  103. }
  104. function searchAssignmentForm(){
  105. $('#assignmentslist tr').css('background-color', 'white');
  106. $.getJSON( "../server/assignments/search/?pattern=" + $('#searchAssingmentPattern').val() + "&station=" + $('#searchAssingmentStation option:selected').text() + "&text=" + $('#searchAssingmentText').val(), function( data ) {
  107. console.log(data);
  108. $('tr[name="' + data +'"]').css('background-color', '#73d216') // Matches exactly 'tcol1'
  109. });
  110. }
  111. function initAssignment(){
  112. $.getJSON( "../server/assignments/", function( data ) {
  113. $.each( data, function(i, item){
  114. var clonePattern = document.importNode(document.querySelector('#assignmentitem').content,true);
  115. $('[data-class=tr]',clonePattern).attr('name', item);
  116. $('[data-class=image]',clonePattern).attr('src', item);
  117. $('[data-class=item] a',clonePattern).text(item);
  118. $('[data-class=item] a',clonePattern).attr('href','javascript:createAssignmentForm(' + i + ',"' + item + '");');
  119. //$('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');');
  120. $('[data-class=delete] a',clonePattern).attr('href','javascript:deleteAssignment(' + i + ');');
  121. $('#assignmentslist').append(clonePattern);
  122. });
  123. });
  124. $.ajax({
  125. type: "GET",
  126. url: "../server/",
  127. dataType: "xml",
  128. success: function(xml) {
  129. $(xml).find('station').each(function(index){
  130. $('#searchAssingmentStation').append('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
  131. });
  132. }
  133. });
  134. }
  135. function initAssignmentTable(){
  136. $('#assignmentdetaillist').text("");
  137. $('#assignmentdetaillist').append("<tr id='copyAssignmentTable'></tr>");
  138. $('#assignmentdetaillist tr').append("<td data-class='station'>Station</td>");
  139. $.getJSON( "../server/json/ProductCode.json", function( data ) {
  140. $.each( data["pattern"], function(i, item){
  141. $('#assignmentdetaillist tr').append("<td data-class='part"+ item["abk"] +"'>"+ item["abk"] +"</td>");
  142. });
  143. $('#assignmentdetaillist tr').append("<td data-class='partTEXT'>Text</td>");
  144. $('#assignmentdetaillist tr').append("<td data-class='delete'>Delete</td>");
  145. });
  146. }
  147. $(document).ready(function() {
  148. initAssignment();
  149. $(document).on('submit', '#assignmentform', function() { //prevent page reload on form submit
  150. return false;
  151. });
  152. });