var productcodestructure = {}; 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 ) { $.each( data, function(curstation, alldata){ var clonePattern = $("#copyAssignmentTable").clone(); $('td',clonePattern).text(""); $('[data-class=station]',clonePattern).text(curstation); $('#assignmentdetaillist').append(clonePattern); $.each( alldata, function(i, pattern){ var clonePattern = $("#copyAssignmentTable").clone(); $('td',clonePattern).text(""); var searchpattern = productcodestructure; $.each( pattern, function(i, item){ $('[data-class=part' + i + ']',clonePattern).text(item); if(i != "TEXT"){ searchpattern[i] = item; } }); $('[data-class=delete]',clonePattern).html('[тип]'); arr = jQuery.map( searchpattern, function( n, i ) { return ( n + "." ); }); $('[data-class=search]',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(newassignment){ var obj = new Object(); var skipasscreationform = false; if(typeof newassignment !== "undefined"){ skipasscreationform = true; obj = newassignment; } else{ 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) { if(!skipasscreationform){ createAssignmentForm(res.id, $('#addExternalImageAssignment').val()) } }, 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) { initAssignment(); } }); } } 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) { initAssignment(); createAssignmentForm(assignmentID, $('#addExternalImageAssignment').val()) } }); } } function newSearchAssignment(station, pattern, searchtext){ console.log(station + pattern + searchtext); $('#searchAssingmentStation').val(station); $('#searchAssingmentPattern').val(pattern); $('#searchAssingmentText').val(searchtext); searchAssignmentForm(); } 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 ) { $.each( data, function(i, item){ $('tr[name="' + item +'"]').css('background-color', '#73d216') // Matches exactly 'tcol1' }); }); } function initAssignment(){ $('#assignmentslist').text(""); $.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); }); }); $('#searchAssingmentStation').find('option').remove() $.ajax({ type: "GET", url: "../server/", dataType: "xml", success: function(xml) { $(xml).find('station').each(function(index){ $('#searchAssingmentStation').append(''); }); } }); } function initAssignmentTable(){ $('#assignmentdetaillist').text(""); $('#assignmentdetaillist').append("