Commit effc66a8 authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage.js amd compatible now

parent b56a8a06
/* /*
* Copyright 2013, Nexedi SA * Copyright 2013, Nexedi SA
* Released under the LGPL license. * Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html * http://www.gnu.org/licenses/lgpl.html
*/ */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */ /*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global jIO: true, localStorage: true, setTimeout: true, /*global jIO: true, localStorage: true, setTimeout: true,
complex_queries: true */ complex_queries, define */
/** /**
* JIO Local Storage. Type = 'local'. * JIO Local Storage. Type = 'local'.
...@@ -43,7 +43,18 @@ ...@@ -43,7 +43,18 @@
* *
* @class LocalStorage * @class LocalStorage
*/ */
jIO.addStorageType('local', function (spec, my) {
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
module(jIO, complex_queries);
}(['jio', 'complex_queries'], function (jIO, complex_queries) {
"use strict";
jIO.addStorageType('local', function (spec, my) {
spec = spec || {}; spec = spec || {};
var that, priv, localstorage; var that, priv, localstorage;
...@@ -240,7 +251,9 @@ jIO.addStorageType('local', function (spec, my) { ...@@ -240,7 +251,9 @@ jIO.addStorageType('local', function (spec, my) {
*/ */
that.get = function (command) { that.get = function (command) {
setTimeout(function () { setTimeout(function () {
var doc = localstorage.getItem(priv.localpath + "/" + command.getDocId()); var doc = localstorage.getItem(
priv.localpath + "/" + command.getDocId()
);
if (doc !== null) { if (doc !== null) {
that.success(doc); that.success(doc);
} else { } else {
...@@ -262,8 +275,10 @@ jIO.addStorageType('local', function (spec, my) { ...@@ -262,8 +275,10 @@ jIO.addStorageType('local', function (spec, my) {
*/ */
that.getAttachment = function (command) { that.getAttachment = function (command) {
setTimeout(function () { setTimeout(function () {
var doc = localstorage.getItem(priv.localpath + "/" + command.getDocId() + var doc = localstorage.getItem(
"/" + command.getAttachmentId()); priv.localpath + "/" + command.getDocId() +
"/" + command.getAttachmentId()
);
if (doc !== null) { if (doc !== null) {
that.success(doc); that.success(doc);
} else { } else {
...@@ -370,7 +385,9 @@ jIO.addStorageType('local', function (spec, my) { ...@@ -370,7 +385,9 @@ jIO.addStorageType('local', function (spec, my) {
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.allDocs = function (command) { that.allDocs = function (command) {
var i, row, path_re, rows = [], document_list = [], option, document_object; var i, row, path_re, rows, document_list, option, document_object;
rows = [];
document_list = [];
path_re = new RegExp( path_re = new RegExp(
"^" + complex_queries.stringEscapeRegexpCharacters(priv.localpath) + "^" + complex_queries.stringEscapeRegexpCharacters(priv.localpath) +
"/[^/]+$" "/[^/]+$"
...@@ -434,4 +451,5 @@ jIO.addStorageType('local', function (spec, my) { ...@@ -434,4 +451,5 @@ jIO.addStorageType('local', function (spec, my) {
}; };
return that; return that;
}); });
}));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment