Skip to content

Commit

Permalink
Merged in JulianKniephoff/annotation-tool/simplify-sync (pull request o…
Browse files Browse the repository at this point in the history
…pencast#13)

Refactor the server synchronization layer
  • Loading branch information
JulianKniephoff authored and rrolf committed May 5, 2017
2 parents d85c205 + d9a4773 commit 2028ea0
Show file tree
Hide file tree
Showing 24 changed files with 1,175 additions and 1,508 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ define(["jquery",
localStorage: false,


localStorageOnlyModel: [],


plugins: {
Loop: function () {
require(["views/loop"], function (Loop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ define(["jquery",
*/
localStorage: true,

/**
* List of models using only the localStory sync module
* @type {Array}
* @readOnly
*/
localStorageOnlyModel: [],


/**
* List of plugins to load,
Expand Down
63 changes: 63 additions & 0 deletions frontend/js/annotation-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2017, ELAN e.V., Germany
* Licensed under the Educational Community License, Version 2.0
* (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*
*/

/**
* The synchronization module for the annotation tool
* @module annotation-sync
* @requires underscore
* @requires backbone
* @requires localstorage
*/
define(["underscore", "backbone", "localstorage"], function (_, Backbone) {
"use strict";

/**
* Synchronize models with an annotation tool backend
* @alias module:annotation-sync.annotationSync
*/
var annotationSync = function (method, model, options) {
if (annotationsTool.localStorage) {
return Backbone.localSync.call(this, method, model, options);
}

options = _.extend({
headers: {},
processData: true
}, options);

if (model.localStorageOnly) {
return Backbone.localSync.call(this, method, model, options);
}

options.data = options.attrs || model.toJSON(options);

if (annotationsTool.user) {
options.headers["X-ANNOTATIONS-USER-ID"] = annotationsTool.user.id;
}
var authToken = _.result(annotationsTool, 'getUserAuthToken');
if (authToken) {
options.headers["X-ANNOTATIONS-USER-AUTH-TOKEN"] = authToken;
}

if (model.noPOST && method === "create") {
method = "update";
}

return Backbone.ajaxSync.call(this, method, model, options);
};

return annotationSync;
});
7 changes: 0 additions & 7 deletions frontend/js/annotations-tool-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ define(["jquery",
*/
localStorage: true,

/**
* List of models using only the localStory sync module
* @type {Array}
* @readOnly
*/
localStorageOnlyModel: [],


/**
* List of plugins to load,
Expand Down
Loading

0 comments on commit 2028ea0

Please sign in to comment.