semantics_coupling.js 4.03 KB
function schemaGotAssignedSemantics(element_id) {
  var semanticsAssigned = true;
  var id_map = parseId(element_id);
  var schema_id = id_map['frame_id'];
  if(schema_id < 0) {
	  semanticsAssigned = false;
  }
  else {
	  jQuery.ajax({
			type: 'get',
		    url: ajax_schema_got_assigned_semantics,
		    data: {lemma_id: window.lemma_id,
		    	   schema_id: schema_id},
		    success: function(result) {
		    	semanticsAssigned = result['got_assigned_semantics'];
		    },
		    async: false
	  });
  }
  return semanticsAssigned;
}

function semanticsAssignedAlert() {
	error_alert('Działaj rozważnie, element jest wykorzystywany w ramach semantycznych.');
}

function exampleGotAssignedSemantics(example_tab_id)
{
  var semanticsAssigned = true;
  var example_id = example_tab_id.replace('nkjp_', '');
  if (example_id < 0) {
	  semanticsAssigned = false;
  }
  else {
	  jQuery.ajax({
			type: 'get',
		    url: ajax_example_got_assigned_semantics,
		    data: {lemma_id: window.lemma_id,
		    	   example_id: example_id},
		    success: function(result) {
		    	semanticsAssigned = result['got_assigned_semantics'];
		    },
		    async: false
	  });
  }
  return semanticsAssigned;
}

function semanticsAssignedExampleAlert() {
	error_alert('Działaj rozważnie, przykład jest wykorzystywany w ramach semantycznych.');
}

function semanticsChanged() {
	if(window.frames_operations.length > 0) {
		return true;
	}
	return false;
}

function checkIfSemChangedAndAlert() {
	if(semanticsChanged()) {
		alert('Przed dokonaniem zmiany zapisz semantykę.');
		return true;
	}
	return false;
}

function clearSemanticConnections(type, schemaElement) {
	if(type == 'frame') {
		clearSchemaConnections(schemaElement);
	}
	else if(type == 'position') {
		clearPositionConnections(schemaElement);
	}
	else if(type == 'argument') {
		clearPhraseTypeConnections(schemaElement);
	}
}

function clearSchemaConnections(schema) {
	for(var i=0; i<schema.positions.length; i++) {
		clearPositionConnections(schema.positions[i]);
	}
}

function clearPositionConnections(position) {
	for(var i=0; i<position.arguments.length; i++) {
		clearPhraseTypeConnections(position.arguments[i]);
	}
}

function clearPhraseTypeConnections(phraseType) {
	phraseType.connections = [];
}

function updateSchemataConnections() {
	$('#new-frame-tables').empty();
	$("#show_nkjp_table").empty();
    $.ajaxJSON({
        method: 'get',
        url: ajax_get_schemata,
        data: {
          lemma_id: window.lemma_id
        },

        callback: function(result) {
    	  window.schemas = serializedObjToObj(result['schemata']);
    	  resetLemmaVersions();
    	  var frame_class = 'InactiveFrameTable';
    	  if(result['can_modify']) {
    	      frame_class = 'ActiveFrameTable';
    	  }
    	  draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', 
    			  			   'frame_filter', window.nkjp_examples, frame_class, 
    			  			   window.lemma_entry, window.lemma_entry);
        },
        error_callback: function(xhr, status, error) {
          error_alert(status + ': ' + error);
        },
        bad_data_callback: function(result) {
          return true;
        },
    });
}

function updateExamplesConnections() {
	$('#new-frame-tables').empty();
	$("#show_nkjp_table").empty();
    $.ajaxJSON({
        method: 'get',
        url: ajax_get_examples,
        data: {
          lemma_id: window.lemma_id
        },

        callback: function(result) {
    	  window.nkjp_examples = serializedNkjpToObj(result['examples']);
    	  resetLemmaVersions();
    	  var frame_class = 'InactiveFrameTable';
    	  if(result['can_modify']) {
    	      frame_class = 'ActiveFrameTable';
    	  }
    	  draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', 
    			  			   'frame_filter', window.nkjp_examples, frame_class, 
    			  			   window.lemma_entry, window.lemma_entry);
        },
        error_callback: function(xhr, status, error) {
          error_alert(status + ': ' + error);
        },
        bad_data_callback: function(result) {
          return true;
        },
    });
}