123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 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('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
- });
- }
- });
-
- 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('<a href="javascript:deleteSingleAssignment(' + assID +', ' + i + ');">[⨯]</a>');
-
- $('#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();
- if(typeof newassignment !== "undefined"){
- 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) {
- },
- 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('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
- });
- }
- });
- }
- function initAssignmentTable(){
- $('#assignmentdetaillist').text("");
- $('#assignmentdetaillist').append("<tr id='copyAssignmentTable'></tr>");
- $('#assignmentdetaillist tr').append("<td data-class='station'>Station</td>");
- $.getJSON( "../server/json/ProductCode.json", function( data ) {
- $.each( data["pattern"], function(i, item){
- $('#assignmentdetaillist tr').append("<td data-class='part"+ item["abk"] +"'>"+ item["abk"] +"</td>");
- });
- $('#assignmentdetaillist tr').append("<td data-class='partTEXT'>Text</td>");
- $('#assignmentdetaillist tr').append("<td data-class='delete'>Delete</td>");
- });
-
- }
- $(document).ready(function() {
- initAssignment();
- $(document).on('submit', '#assignmentform', function() { //prevent page reload on form submit
- return false;
- });
-
- });
|