Commit f53cd933 authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Integrate Linshare with officejs

parent 9d82f3f3
...@@ -65,6 +65,12 @@ ...@@ -65,6 +65,12 @@
}); });
}, },
"name": "Dropbox" "name": "Dropbox"
},
"linshare": {
"name": "Linshare",
"setConfiguration": function (gadget) {
return gadget.redirect({command: "change", options: {page: 'ojs_linshare_configurator'}});
}
} }
}; };
...@@ -108,7 +114,8 @@ ...@@ -108,7 +114,8 @@
}) })
.push(function () { .push(function () {
return gadget.changeState({ return gadget.changeState({
type: options.type || "" type: options.type || "",
url: options.url
}); });
}); });
}) })
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.10686.10882.5973</string> </value> <value> <string>972.27141.2695.3276</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1501771018.12</float> <float>1545233718.42</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS jIO Linshare Configurator Page</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_ojs_linshare_configurator.js"></script>
</head>
<body>
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-database">&nbsp;</span>
Your Connection parameters
</h3>
</section>
<br>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
<br>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_linshare_configurator.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_page_ojs_linshare_configurator_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>OfficeJS jIO Linshare Configurator Page</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1545233814.39</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.27118.13776.47906</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1545232594.38</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1545232082.86</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP) {
"use strict";
//"https://softinst89769.host.vifib.net/erp5/portal_skins/erp5_http_proxy/ERP5Site_getHTTPResource?url="
function setjIOLinshareConfiguration(gadget, options) {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting("portal_type"),
gadget.getSetting("erp5_attachment_synchro", "")
]);
})
.push(function (setting) {
var configuration = {},
attachment_synchro = setting[1] !== "";
configuration = {
type: "replicate",
query: {
query: 'portal_type:"' + setting[0] + '" ',
limit: [0, 200],
sort_on: [["modification_date", "descending"]]
},
use_remote_post: false,
conflict_handling: 2,
check_local_attachment_modification: attachment_synchro,
check_local_attachment_creation: attachment_synchro,
check_remote_attachment_creation: attachment_synchro,
check_local_modification: true,
check_local_creation: true,
check_local_deletion: false,
check_remote_modification: false,
check_remote_creation: true,
check_remote_deletion: false,
signature_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "ojs_linshare_hash"
}
}
},
local_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "ojs_linshare"
}
}
},
remote_sub_storage: {
type: "query",
sub_storage: {
type: "linshare",
url: options.url,
credential_token: window.btoa(
options.username + ':' + options.password
)
}
}
};
return gadget.setSetting('jio_storage_description', configuration);
})
.push(function () {
return gadget.setSetting('jio_storage_name', options.name);
})
.push(function () {
return gadget.setSetting('sync_reload', true);
})
.push(function () {
return gadget.setSetting('linshare_url', options.url);
})
.push(function () {
return gadget.redirect({
command: "display",
options: {page: 'ojs_sync', auto_repair: 'true'}
});
});
}
rJS(window)
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("reload", "reload")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareMethod("render", function (options) {
var gadget = this;
if (options.url) {
return gadget.changeState({
url: options.url || ""
});
}
return gadget.getSetting('linshare_storage', "")
.push(function (url) {
return gadget.changeState({
url: url
});
});
})
/////////////////////////////////////////
// Form submit
/////////////////////////////////////////
.onEvent('submit', function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (content) {
return setjIOLinshareConfiguration(gadget, content);
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.onStateChange(function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {"_embedded": {"_view": {
"my_url": {
"description": "",
"title": "Connection Url",
"default": gadget.state.url,
"css_class": "",
"required": 1,
"editable": 1,
"key": "url",
"hidden": 0,
"type": "StringField"
},
"my_username": {
"description": "",
"title": "Username",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "username",
"hidden": 0,
"type": "StringField"
},
"my_password": {
"description": "",
"title": "Password",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "password",
"hidden": 0,
"type": "PasswordField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}},
form_definition: {
group_list: [[
"top",
[["my_url"], ["my_username"], ["my_password"]]
]]
}
});
})
.push(function () {
return gadget.getUrlFor({
command: 'display',
options: {page: 'ojs_configurator'}
});
})
.push(function (url) {
return gadget.updateHeader({
page_title: "Connect To Linshare",
back_url: url,
panel_action: false,
submit_action: true
});
});
});
}(window, rJS, RSVP));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_linshare_configurator.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_page_ojs_linshare_configurator_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>OfficeJS jIO Linshare Configurator Page JS</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1545233812.51</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.28224.36389.16861</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1545298746.61</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1545232088.73</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
...@@ -805,3 +805,282 @@ ...@@ -805,3 +805,282 @@
jIO.addStorage('saferepair', SafeRepairStorage); jIO.addStorage('saferepair', SafeRepairStorage);
}(jIO)); }(jIO));
/*
* Copyright 2013, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/**
* JIO Linshare Storage. Type = "linshare".
* Linshare "database" storage.
* http://download.linshare.org/components/linshare-core/2.2.2/
* Can't set up id, implied can't put new document
*/
/*global Blob, jIO, RSVP, UriTemplate*/
/*jslint nomen: true*/
(function (jIO, RSVP, Blob, UriTemplate) {
"use strict";
function makeRequest(storage, options) {
var ajax_param = {
type: options.type,
url: storage._url_template.expand({uuid: options.uuid || ""}),
headers : {
"Authorization": "Basic " + storage._credential_token,
"Accept": "application/json"
}
};
if (options.type === 'PUT') {
ajax_param.dataType = options.dataType;
ajax_param.headers['Content-Type'] = "application/json";
}
if (options.data) {
ajax_param.data = options.data;
}
if (options.download) {
ajax_param.url += '/download';
ajax_param.dataType = 'blob';
}
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax(ajax_param);
})
.push(function (event) {
if (options.type === "PUT") {
return event.target.response.uuid;
}
if (options.download) {
return event.target.response;
}
return JSON.parse(event.target.response);
});
}
function checkAttachmentMap(storage, id, name) {
checkDocumentMap(storage, id);
if (!storage._id_map[id].attachment.hasOwnProperty(name)) {
throw new jIO.util.jIOError(
"Can't find attachment with name :" + name,
404
);
}
}
function checkDocumentMap(storage, id) {
if (!storage._id_map.hasOwnProperty(id)) {
throw new jIO.util.jIOError(
"Can't find document with id : " + id,
404
);
}
}
/**
* The JIO Linshare Storage extension
*
* @class LinshareStorage
* @constructor
*/
function LinshareStorage(spec) {
this._url_template = UriTemplate.parse(
spec.url + '/linshare/webservice/rest/user/v2/documents/{uuid}'
);
this._credential_token = spec.credential_token;
this._id_map = {};
}
LinshareStorage.prototype.put = function (id, doc) {
var storage = this,
data = new FormData();
data.append('file', new Blob());
data.append('filename', doc.title);
data.append('filesize', 0);
data.append('description', 'jio/document');
data.append('metadata', jIO.util.stringify({
doc: doc,
id: id
}));
return makeRequest(this, {
data: data,
type: "POST"
})
.push(function (result) {
if (storage._id_map.hasOwnProperty(id)) {
storage._id_map[id].uuid = result.uuid;
} else {
storage._id_map[id] = {'uuid': result.uuid, attachment: {}};
}
return id;
});
};
LinshareStorage.prototype.remove = function (id) {
var storage = this;
if (storage._id_map.hasOwnProperty(id)) {
return makeRequest(storage, {
type: "DELETE",
uuid: storage._id_map[id].uuid
})
.push(function () {
var promise_list = [],
name;
for (name in storage._id_map[id].attachment) {
if (storage._id_map[id].attachment.hasOwnProperty(name)) {
promise_list.push(storage.removeAttachment(id, name));
}
}
return RSVP.all(promise_list);
})
.push(function () {
delete storage._id_map[id];
return id;
});
}
};
LinshareStorage.prototype.get = function (id) {
checkDocumentMap(this, id);
return makeRequest(this, {
type: "GET",
uuid: this._id_map[id].uuid
})
.push(function (result) {
return JSON.parse(result.metaData).doc;
});
};
LinshareStorage.prototype.hasCapacity = function (name) {
return name === "list";
};
LinshareStorage.prototype.buildQuery = function () {
return makeRequest(this, {
type: "GET"
})
.push(function (result) {
var rows = [],
len = result.length,
i;
for (i = 0 ; i < len ; i += 1) {
if (result[i].hasOwnProperty('type')) {
if (result[i].description === 'jio/document') {
rows.push({id: JSON.parse(result[i].metaData).id, value: {}});
}
}
}
return rows;
});
};
// Attachments link by field "description" - Dict
LinshareStorage.prototype.allAttachments = function (id) {
return this._id_map[id].attachment;
};
LinshareStorage.prototype.putAttachment = function (id, name, blob) {
var storage = this,
data = new FormData(),
uuid;
if (!storage._id_map.hasOwnProperty(id)) {
throw new jIO.util.JIOError(
"Can't find document with id :" + id,
404
);
}
data.append('file', blob);
data.append('filename', blob.name);
data.append('filesize', blob.size);
data.append('metadata', jIO.util.stringify({
'id': id,
'name': name
}));
data.append('description', 'jio/attachment');
return makeRequest(storage, {
data: data,
type: "POST"
})
.push(function (result) {
storage._id_map[id].attachment[name] = result.uuid;
return result.uuid;
});
};
LinshareStorage.prototype.getAttachment = function (id, name) {
checkAttachmentMap(this, id, name);
return makeRequest(this, {
type: "GET",
uuid: this._id_map[id].attachment[name],
download: true
});
};
LinshareStorage.prototype.removeAttachment = function (id, name) {
if (this._id_map.hasOwnProperty(id) &&
this._id_map[id].attachment.hasOwnProperty(name)) {
return makeRequest(this, {
type: "DELETE",
uuid: this._id_map[id].attachment[name]
})
.push(function () {
delete this._id_map[id].attachment[name];
return id;
});
}
};
LinshareStorage.prototype.repair = function () {
var storage = this;
return makeRequest(this, {
type: "GET"
})
.push(function (result) {
var rows = [],
len = result.length,
i,
metadata,
row,
id;
for (i = 0 ; i < len ; i += 1) {
row = result[i];
if (row.hasOwnProperty('description')) {
if (row.description === 'jio/document') {
id = JSON.parse(row.metaData).id;
if (storage._id_map.hasOwnProperty(id)) {
storage._id_map[id].uuid = row.uuid;
} else {
storage._id_map[id] = {'uuid': row.uuid, attachment: {}};
}
} else if (row.description === 'jio/attachment') {
metadata = JSON.parse(row.metaData);
id = metadata.id;
if (!storage._id_map.hasOwnProperty(id)) {
storage._id_map[id] = {'uuid': undefined, attachment: {}};
}
storage._id_map[id].attachment[metadata.name] = row.uuid;
}
}
}
});
};
jIO.addStorage('linshare', LinshareStorage);
}(jIO, RSVP, Blob, UriTemplate));
\ No newline at end of file
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>vincent</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.45923.44376.29252</string> </value> <value> <string>972.27209.55180.16196</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1507730215.96</float> <float>1545237720.18</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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