Changeset 3339


Ignore:
Timestamp:
08/09/13 09:42:57 (11 years ago)
Author:
olof
Message:

get default-functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/annotator-service/annotation-service.js

    r3187 r3339  
    11var annotationFramework = (function() {
    22    // default value for REST service
    3     var backend = "http://pelle.ssd.gu.se:8080/exist/rest/db/annotation-framework/api/annotations.xql";
    4     var selected_state = nsPreferences.copyUnicharPref("wiredmarker.marker.initdata.url","");
    5     // selected_state values: "" (empty value as long as Settings Dialog has not been opened) OR "WM_REST_DEFAULT" OR "WM_REST_UserDefined"
    6     // user-specified value for REST service
    7     if (selected_state === "WM_REST_UserDefined") {
    8         var backend = nsPreferences.copyUnicharPref("wiredmarker.marker.initdata.url_format","");
    9     }
    10     // alert("The following backend is used: " + backend);
    11     // TODO: The above code is executed only when restarting the application (or when a new window is opened),
    12     // however the settings will be changed without calling for a restart (or opening a new window).
    13     // Solution to get the correct backend URL at any time?
    14    
     3    var default_backend = "http://pelle.ssd.gu.se:8080/exist/rest/db/annotation-framework/api/annotations.xql";
     4       
    155    return {
     6        getDefaultBackend: function(){
     7            return default_backend;
     8        },
     9               
     10        getBackend: function(){
     11            // selected_state values: "" (empty value as long as Settings Dialog has not been opened) OR "WM_REST_DEFAULT" OR "WM_REST_UserDefined"
     12            // user-specified value for REST service
     13            var selected_state = nsPreferences.copyUnicharPref("wiredmarker.marker.initdata.url","");
     14            if (selected_state === "WM_REST_UserDefined") {
     15                return nsPreferences.copyUnicharPref("wiredmarker.marker.initdata.url_format","");
     16            }else{
     17                return default_backend;
     18            }
     19        },
     20       
    1621        getAnnotations: function(params, callback) {
    1722            $.ajax({
    1823                type: "GET",
    19                 url: this.backend,
     24                url: this.getBackend()+'/annotations',
    2025                data:params,
    2126                dataType: "xml",
     
    3540            });
    3641        },
    37         putAnnotation: function() {
     42        getAnnotation: function(aid, callback){
     43            $.ajax({
     44                type: "GET",
     45                url: this.getBackend()+'/'+aid,
     46                dataType: "xml",
     47                success: function(xml) {
     48                   
     49                    $xml.find('annotation').each(function(){             
     50                        var annotation = $.xml2json(this);
     51                    });
     52
     53                    callback.call(undefined, annotation);
     54                }
     55            });
     56        },
     57        putAnnotation: function(annotation) {
    3858            $.ajax({
    3959                type: "POST",
    40                 url: this.backend,
    41                 dataType: "xml"
     60                url: this.getBackend()+'?store=true',
     61                dataType: "xml",
     62                data:annotation
    4263            });
    4364        },
Note: See TracChangeset for help on using the changeset viewer.