public/javascripts/extractors/extractors.js
// Saves a new or existing label
Saves a new or existing label
Saves a new or existing label
function saveExtractorsLabel(label) {
    let request;
    if (label.id) {    
        console.log('Saving label updates:', label);
        request = jsRoutes.api.Extractions.updateExtractorsLabel(label.id).ajax({
            data: JSON.stringify(label),
            type: 'PUT',
            contentType: 'application/json',
            dataType: 'json'
        });
    } else {    
        console.log("Creating new label:", label);
        request = jsRoutes.api.Extractions.createExtractorsLabel().ajax({
            data: JSON.stringify(label),
            type: 'POST',
            contentType: 'application/json',
            dataType: 'json'
        });
    }
    request.done(function (response, textStatus, jqXHR){
        notify("Label has been updated", "success");
    });
    request.fail(function (jqXHR, textStatus, errorThrown){
        console.error("The following error occurred: " + textStatus, errorThrown);
        var operation = label.id ? "update" : "create";
        var specificError = jqXHR.responseText;
        var msg = "Failed to " + operation + " label: " + specificError;
        notify(msg, "error");
    });
    return request;
}
function saveExtractorsLabel ( label ) { let request ; if ( label . id ) { console . log ( 'Saving label updates:' , label ) ; request = jsRoutes . api . Extractions . updateExtractorsLabel ( label . id ) . ajax ( { data : JSON . stringify ( label ) , type : 'PUT' , contentType : 'application/json' , dataType : 'json' } ) ; } else { console . log ( "Creating new label:" , label ) ; request = jsRoutes . api . Extractions . createExtractorsLabel ( ) . ajax ( { data : JSON . stringify ( label ) , type : 'POST' , contentType : 'application/json' , dataType : 'json' } ) ; } request . done ( function ( response , textStatus , jqXHR ) { notify ( "Label has been updated" , "success" ) ; } ) ; request . fail ( function ( jqXHR , textStatus , errorThrown ) { console . error ( "The following error occurred: " + textStatus , errorThrown ) ; var operation = label . id ? "update" : "create" ; var specificError = jqXHR . responseText ; var msg = "Failed to " + operation + " label: " + specificError ; notify ( msg , "error" ) ; } ) ; return request ; }
Saves a new or existing label
Saves a new or existing label
// Update existing label // Create new label