Commit 3e3bf820 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs: schema editor: fix developer_mode switcher

parent b6b09964
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<ul data-role="listview" class="ui-listview" data-enhanced="true"></ul> <ul data-role="listview" class="ui-listview" data-enhanced="true"></ul>
<div data-gadget-url="gadget_erp5_field_checkbox.html" <div data-gadget-url="gadget_erp5_field_checkbox.html"
data-gadget-scope="editable_mode" data-gadget-scope="developer_mode"
data-gadget-sandbox="public"></div> data-gadget-sandbox="public"></div>
<dl></dl> <dl></dl>
</div> </div>
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("translate", "translate") .declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter") .declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
...@@ -85,18 +88,27 @@ ...@@ -85,18 +88,27 @@
.push(undefined, function () { .push(undefined, function () {
return "[]"; return "[]";
}), }),
context.getUrlParameter('editable') context.getSetting('developer_mode')
.push(undefined, function () {
return true;
})
]); ]);
}) })
.push(function (ret) { .push(function (ret) {
var schema_list = ret[0], var schema_list = ret[0],
editable = ret[1]; developer_mode = ret[1];
if (developer_mode === undefined) {
developer_mode = true;
}
if (developer_mode === "false") {
developer_mode = false;
}
return context.changeState({ return context.changeState({
workflow_list: workflow_list, workflow_list: workflow_list,
view_list: view_list, view_list: view_list,
schema_list: schema_list, schema_list: schema_list,
global: true, global: true,
editable: options.editable || editable || false developer_mode: developer_mode
}); });
}); });
}) })
...@@ -144,8 +156,8 @@ ...@@ -144,8 +156,8 @@
}) })
.push(function () { .push(function () {
return context.declareGadget('gadget_erp5_field_multicheckbox.html', { return context.declareGadget('gadget_erp5_field_multicheckbox.html', {
scope: "editable_mode", scope: "developer_mode",
element: tmp_element.querySelector('[data-gadget-scope="editable_mode"]') element: tmp_element.querySelector('[data-gadget-scope="developer_mode"]')
}); });
}) })
.push(function () { .push(function () {
...@@ -155,7 +167,7 @@ ...@@ -155,7 +167,7 @@
} }
if (modification_dict.hasOwnProperty("schema_list") || if (modification_dict.hasOwnProperty("schema_list") ||
modification_dict.hasOwnProperty("editable")) { modification_dict.hasOwnProperty("developer_mode")) {
queue queue
.push(function () { .push(function () {
function gen_element(element, title, css, accesskey) { function gen_element(element, title, css, accesskey) {
...@@ -173,24 +185,24 @@ ...@@ -173,24 +185,24 @@
row, row,
tasks = [], tasks = [],
schema_list = JSON.parse(context.state.schema_list); schema_list = JSON.parse(context.state.schema_list);
if (context.state.editable) { if (context.state.developer_mode) {
tasks.push(gen_element({command: 'display', options: {page: "ojs_schema_document_list"}}, tasks.push(gen_element({command: 'display', options: {page: "ojs_schema_document_list"}},
"Schemas", "search", "s")); "Schemas", "search", "s"));
} }
for (i = 0; i < schema_list.length; i += 1) { for (i = 0; i < schema_list.length; i += 1) {
row = schema_list[i]; row = schema_list[i];
tasks.push(gen_element({command: 'display', options: { tasks.push(gen_element({command: 'display', options: {
page: "ojs_schema_document_list", page: "ojs_schema_document_list",
portal_type: "JSON Document", portal_type: "JSON Document",
schema: row.id, schema: row.id,
schema_title: row.value.title schema_title: row.value.title
}}, row.value.title, "search")); }}, row.value.title, "search"));
} }
tasks.push(gen_element({command: 'display', options: {page: "ojs_sync", 'auto_repair': true}}, tasks.push(gen_element({command: 'display', options: {page: "ojs_sync", 'auto_repair': true}},
"Synchronize", "refresh")); "Synchronize", "refresh"));
tasks.push(gen_element({command: 'display', options: {page: "ojs_configurator"}}, tasks.push(gen_element({command: 'display', options: {page: "ojs_configurator"}},
"Storages", "dropbox")); "Storages", "dropbox"));
if (context.state.editable) { if (context.state.developer_mode) {
tasks.push(gen_element({command: 'index', options: {page: "ojs_zip_upload"}}, tasks.push(gen_element({command: 'index', options: {page: "ojs_zip_upload"}},
"Upload", "upload")); "Upload", "upload"));
} }
...@@ -207,25 +219,25 @@ ...@@ -207,25 +219,25 @@
// Update the checkbox field value // Update the checkbox field value
return RSVP.all([ return RSVP.all([
context.getDeclaredGadget("editable_mode"), context.getDeclaredGadget("developer_mode"),
context.translate("Developer Mode") context.translate("Developer Mode")
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
var value = [], var value = [],
search_gadget = result_list[0], developer_mode_gadget = result_list[0],
title = result_list[1]; title = result_list[1];
if (context.state.editable) { if (context.state.developer_mode) {
value = ['editable']; value = ['developer'];
} }
return search_gadget.render({field_json: { return developer_mode_gadget.render({field_json: {
editable: true, editable: true,
name: 'editable', name: 'developer',
key: 'editable', key: 'developer',
hidden: false, hidden: false,
items: [[title, 'editable']], items: [[title, 'developer']],
default: value default: value
}}); }});
}); });
} }
...@@ -336,18 +348,21 @@ ...@@ -336,18 +348,21 @@
}) })
.allowPublicAcquisition('notifyChange', function (argument_list, scope) { .allowPublicAcquisition('notifyChange', function (argument_list, scope) {
if (scope === 'editable_mode') { if (scope === 'developer_mode' && argument_list[0] === "change") {
var context = this; var context = this;
return context.getDeclaredGadget('editable_mode') return context.getDeclaredGadget('developer_mode')
.push(function (gadget) { .push(function (gadget) {
return gadget.getContent(); return gadget.getContent();
}) })
.push(function (result) { .push(function (result) {
var options = {editable: undefined}; var value = "false";
if (result.editable.length === 1) { if (result.developer.length === 1) {
options.editable = true; value = true;
} }
return context.redirect({command: 'change', options: options}); return context.setSetting("developer_mode", value);
})
.push(function () {
return context.updatePanel({});
}); });
} }
// Typing a search query should not modify the header status // Typing a search query should not modify the header status
......
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