Commit c8c2474f authored by Sven Franck's avatar Sven Franck

offline work-in-progress commit

parent 2a7c34a3
......@@ -52,7 +52,7 @@
{"field": "total_price", "show": true, "persist": true, "sort":false},
{"field": "price_currency", "show": "true", "priority": 4, "merge": "total_price"},
{"field": "translated_simulation_state_title", "show":"true", "priority": 5},
{"custom": true, "show": true, "persist": true, "sort": false, "action_list": [{"class_list": "action translate", "action": "download", "icon":"file-alt", "text": "Download", "text_i18n":"portable_type_dict.invoice_dict.download"}]}
{"custom": true, "show": true, "persist": true, "sort": false, "action_list": [{"class_list": "action translate", "action": "get", "icon":"file-alt", "text": "Download", "text_i18n":"portable_type_dict.invoice_dict.download"}]}
]
}
],
......
This diff is collapsed.
......@@ -23,11 +23,10 @@
this._url = spec.url;
}
ERP5Storage.prototype._getPrivates = function (site_hal, param, options) {
ERP5Storage.prototype._getFile = function (command, site_hal, param, options) {
var fetch, item = (param || {})._id || (site_hal._links.me || {}).href;
if (!item) {
return command.error(401);
command.error(401);
}
fetch = new URI(item);
return this._getSiteDocument(
......@@ -38,7 +37,6 @@
ERP5Storage.prototype._getSiteDocument = function (traverse, expando) {
var url = UriTemplate.parse(traverse || "").expand(expando || {});
console.log(url);
return jIO.util.ajax({
"type": "GET",
"url": url || this._url,
......@@ -46,29 +44,24 @@
"withCredentials": true
}
}).then(function (response) {
var result = JSON.parse(response.target.responseText);
// result._id = param._id;
return result;
return JSON.parse(response.target.responseText);
});
};
ERP5Storage.prototype._get = function (param, options) {
ERP5Storage.prototype._get = function (command, param, options) {
var that = this;
return that._getSiteDocument()
.then(function (site_hal) {
return that._getPrivates(site_hal, param, options);
return that._getFile(command, site_hal, param, options);
})
.then(function (response) {
console.log("GET, response")
console.log(response)
var result = JSON.parse(response.target.responseText);
result._id = param._id;
return result;
response._id = param._id;
return response;
});
};
ERP5Storage.prototype.get = function (command, param, options) {
this._get(param, options)
this._get(command, param, options)
.then(function (response) {
command.success({"data": response});
})
......@@ -87,7 +80,7 @@
var that = this;
return that._getSiteDocument()
.then(function (site_hal) {
return that._getPrivates(site_hal, undefined, options);
return that._getFile(command, site_hal, undefined, options);
})
.then(function(opts) {
var key, custom_action = opts._actions[options.action],
......@@ -164,28 +157,39 @@
"Unable to call put"
);
});
};
ERP5Storage.prototype.allDocs = function (command, param, options) {
var that = this, search_pointer;
return this._getSiteDocument()
.then(function (site_hal) {
return jIO.util.ajax({
"type": "GET",
"url": UriTemplate.parse(site_hal._links.raw_search.href)
.expand({
query: options.query,
search_pointer = site_hal._links.raw_search.href;
return that._getFile(command, site_hal, undefined, options);
})
.then(function (opts) {
var i, len, jump_list, jump;
// HACK: add ERP5 custom jump
if (param._jump && options.query) {
jump_list = opts._links["slapos_jump" || []];
len = jump_list.length;
for (i = 0; i < len; i += 1) {
jump = jump_list[i];
if (jump.name === param._jump) {
options.query = jump._query;
}
}
}
return that._getSiteDocument(
search_pointer,
{
"query": options.query,
// XXX Force erp5 to return embedded document
select_list: options.select_list || ["title", "reference"],
limit: options.limit
}),
"xhrFields": {
withCredentials: true
"select_list": options.select_list || ["title", "reference"],
"limit": options.limit
}
});
})
.then(function (response) {
return JSON.parse(response.target.responseText);
);
})
.then(function (catalog_json) {
var data = catalog_json._embedded.contents,
......
......@@ -251,7 +251,6 @@
var length = promise_list.length;
promise_list = promise_list.slice();
return new Promise(function (resolve, reject, notify) {
var index, trace, conflict_list, count, error_count, tag, doc;
......@@ -344,19 +343,20 @@
sequence([
function () {
// master storage
if (master !== undefined) {
return last(priority_list, master);
}
return {};
},
function (response) {
// slave storages
var method, subindex = 0;
// this is the id issued by the master storage
if (response.id) {
metadata._id = response.id;
method = "put";
} else {
// TODO: error/offline handling
// TODO: master 404/offline handling
}
for (index = 0; index < length; index += 1) {
......@@ -454,7 +454,7 @@
var promise_list = [], index, length = this._storage_list.length;
for (index = 0; index < length; index += 1) {
promise_list[index] =
success(command.storage(this._storage_list[index]).allDocs(option));
success(command.storage(this._storage_list[index]).allDocs(option, param));
}
sequence([function () {
......@@ -463,10 +463,10 @@
var i, j, k, l, record, reply, rows, count, total, base, test, must_add,
len = answers.length;
// loop storage response
// NOTE: every storage may return different records!
for (i = 0; i < len; i += 1) {
reply = answers[i];
if (reply.result === "success") {
total = reply.data.total_rows;
// loop records returned in response
......@@ -509,6 +509,7 @@
}
}
}
}
// if a storage returns rows = 0, make sure all records are labelled
if (total === 0) {
......@@ -517,7 +518,6 @@
rows[l]._missing = true;
}
}
return {"data": {"total_rows": (rows || []).length, "rows": rows || []}};
}, [command.success, command.error]]);
};
......
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