function createAssignmentForm(assID, url){ initAssignmentTable(); $('#assignmentstation').find('option').remove() $.ajax({ type: "GET", url: "../server/", dataType: "xml", success: function(xml) { $(xml).find('station').each(function(index){ $('#assignmentstation').append(''); }); } }); if (assID == null){ $('#storedassignments').css("display", "none"); $('#assignmentLupe').css("display", "block"); $('#addExternalImageAssignment').removeAttr('disabled'); $('#addExternalImageAssignment').val(""); } else{ $('#storedassignments').css("display", "block"); $('#assignmentLupe').css("display", "none"); $('#addExternalImageAssignment').attr('disabled','disabled'); $('#addExternalImageAssignment').val(url); //Show Assignments $.getJSON( "../server/assignments/" + assID, function( data ) { console.log(data); $.each( data, function(i, alldata){ var clonePattern = $("#copyAssignmentTable").clone(); $('td',clonePattern).text(""); $('[data-class=station]',clonePattern).text(i); $('#assignmentdetaillist').append(clonePattern); $('#assignmentdetaillist').append(clonePattern); $.each( alldata, function(i, pattern){ var clonePattern = $("#copyAssignmentTable").clone(); $('td',clonePattern).text(""); $.each( pattern, function(i, item){ console.log(i); $('[data-class=part' + i + ']',clonePattern).text(item); }); $('[data-class=delete]',clonePattern).html('[тип]'); $('#assignmentdetaillist').append(clonePattern); }); }); }); } $('#assignment_details').css("display", "block"); } //called when new image is selected function getImgText(imgtext){ var result = /[^;]*$/.exec(imgtext)[0]; if(result != imgtext){ $('#assignmentText').val(result.replace(/\.[^/.]+$/, "")) } } function submitAssignment(){ var obj = new Object(); obj.img = $('#addExternalImageAssignment').val(); obj.station = $('#assignmentstation option:selected').text(); obj.parts = {}; abk.forEach(function(item){ if(typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined' && typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined'){ //if($("#FormPatternAssignment_Form_" + item).find(":selected").text() != ""){ obj.parts[item] = $("#FormPatternAssignment_Form_" + item).find(":selected").text(); //} } }); obj.assignmentText = $('#assignmentText').val(); $.ajax({ type: "Post", data: JSON.stringify(obj), headers: {"content-id": "list"}, contentType: "application/json", url: "../server/assignments/", success: function(res) { }, error: function (request, status, error) { alert(request.responseText + status + error); } }); } function deleteAssignment(assignmentID) { //Delete From DB if (confirm('Are you really, really, REALLY sure!')) { $.ajax({ type: "DELETE", url: "../server/assignments/" + assignmentID, success: function(res) { location.reload(); } }); } } function deleteSingleAssignment(assignmentID, patternID) { //Delete From DB if (confirm('Are you really, really, REALLY sure!')) { $.ajax({ type: "DELETE", url: "../server/assignments/" + assignmentID + "/" + patternID, success: function(res) { location.reload(); } }); } } function searchAssignmentForm(){ $('#assignmentslist tr').css('background-color', 'white'); $.getJSON( "../server/assignments/search/?pattern=" + $('#searchAssingmentPattern').val() + "&station=" + $('#searchAssingmentStation option:selected').text() + "&text=" + $('#searchAssingmentText').val(), function( data ) { console.log(data); $('tr[name="' + data +'"]').css('background-color', '#73d216') // Matches exactly 'tcol1' }); } function initAssignment(){ $.getJSON( "../server/assignments/", function( data ) { $.each( data, function(i, item){ var clonePattern = document.importNode(document.querySelector('#assignmentitem').content,true); $('[data-class=tr]',clonePattern).attr('name', item); $('[data-class=image]',clonePattern).attr('src', item); $('[data-class=item] a',clonePattern).text(item); $('[data-class=item] a',clonePattern).attr('href','javascript:createAssignmentForm(' + i + ',"' + item + '");'); //$('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');'); $('[data-class=delete] a',clonePattern).attr('href','javascript:deleteAssignment(' + i + ');'); $('#assignmentslist').append(clonePattern); }); }); $.ajax({ type: "GET", url: "../server/", dataType: "xml", success: function(xml) { $(xml).find('station').each(function(index){ $('#searchAssingmentStation').append(''); }); } }); } function initAssignmentTable(){ $('#assignmentdetaillist').text(""); $('#assignmentdetaillist').append(""); $('#assignmentdetaillist tr').append("Station"); $.getJSON( "../server/json/ProductCode.json", function( data ) { $.each( data["pattern"], function(i, item){ $('#assignmentdetaillist tr').append(""+ item["abk"] +""); }); $('#assignmentdetaillist tr').append("Text"); $('#assignmentdetaillist tr').append("Delete"); }); } $(document).ready(function() { initAssignment(); $(document).on('submit', '#assignmentform', function() { //prevent page reload on form submit return false; }); });