assignment.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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(newassignment){
  57. var obj = new Object();
  58. if(typeof newassignment !== "undefined"){
  59. obj = newassignment;
  60. }
  61. else{
  62. obj.img = $('#addExternalImageAssignment').val();
  63. obj.station = $('#assignmentstation option:selected').text();
  64. obj.parts = {};
  65. abk.forEach(function(item){
  66. if(typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined' && typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined'){
  67. //if($("#FormPatternAssignment_Form_" + item).find(":selected").text() != ""){
  68. obj.parts[item] = $("#FormPatternAssignment_Form_" + item).find(":selected").text();
  69. //}
  70. }
  71. });
  72. obj.assignmentText = $('#assignmentText').val();
  73. }
  74. $.ajax({
  75. type: "Post",
  76. data: JSON.stringify(obj),
  77. headers: {"content-id": "list"},
  78. contentType: "application/json",
  79. url: "../server/assignments/",
  80. success: function(res) {
  81. },
  82. error: function (request, status, error) {
  83. alert(request.responseText + status + error);
  84. }
  85. });
  86. }
  87. function deleteAssignment(assignmentID) { //Delete From DB
  88. if (confirm('Are you really, really, REALLY sure!')) {
  89. $.ajax({
  90. type: "DELETE",
  91. url: "../server/assignments/" + assignmentID,
  92. success: function(res) {
  93. location.reload();
  94. }
  95. });
  96. }
  97. }
  98. function deleteSingleAssignment(assignmentID, patternID) { //Delete From DB
  99. if (confirm('Are you really, really, REALLY sure!')) {
  100. $.ajax({
  101. type: "DELETE",
  102. url: "../server/assignments/" + assignmentID + "/" + patternID,
  103. success: function(res) {
  104. location.reload();
  105. }
  106. });
  107. }
  108. }
  109. function searchAssignmentForm(){
  110. $('#assignmentslist tr').css('background-color', 'white');
  111. $.getJSON( "../server/assignments/search/?pattern=" + $('#searchAssingmentPattern').val() + "&station=" + $('#searchAssingmentStation option:selected').text() + "&text=" + $('#searchAssingmentText').val(), function( data ) {
  112. console.log(data);
  113. $('tr[name="' + data +'"]').css('background-color', '#73d216') // Matches exactly 'tcol1'
  114. });
  115. }
  116. function initAssignment(){
  117. $.getJSON( "../server/assignments/", function( data ) {
  118. $.each( data, function(i, item){
  119. var clonePattern = document.importNode(document.querySelector('#assignmentitem').content,true);
  120. $('[data-class=tr]',clonePattern).attr('name', item);
  121. $('[data-class=image]',clonePattern).attr('src', item);
  122. $('[data-class=item] a',clonePattern).text(item);
  123. $('[data-class=item] a',clonePattern).attr('href','javascript:createAssignmentForm(' + i + ',"' + item + '");');
  124. //$('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');');
  125. $('[data-class=delete] a',clonePattern).attr('href','javascript:deleteAssignment(' + i + ');');
  126. $('#assignmentslist').append(clonePattern);
  127. });
  128. });
  129. $.ajax({
  130. type: "GET",
  131. url: "../server/",
  132. dataType: "xml",
  133. success: function(xml) {
  134. $(xml).find('station').each(function(index){
  135. $('#searchAssingmentStation').append('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
  136. });
  137. }
  138. });
  139. }
  140. function initAssignmentTable(){
  141. $('#assignmentdetaillist').text("");
  142. $('#assignmentdetaillist').append("<tr id='copyAssignmentTable'></tr>");
  143. $('#assignmentdetaillist tr').append("<td data-class='station'>Station</td>");
  144. $.getJSON( "../server/json/ProductCode.json", function( data ) {
  145. $.each( data["pattern"], function(i, item){
  146. $('#assignmentdetaillist tr').append("<td data-class='part"+ item["abk"] +"'>"+ item["abk"] +"</td>");
  147. });
  148. $('#assignmentdetaillist tr').append("<td data-class='partTEXT'>Text</td>");
  149. $('#assignmentdetaillist tr').append("<td data-class='delete'>Delete</td>");
  150. });
  151. }
  152. $(document).ready(function() {
  153. initAssignment();
  154. $(document).on('submit', '#assignmentform', function() { //prevent page reload on form submit
  155. return false;
  156. });
  157. });