summaryrefslogtreecommitdiff
path: root/addons/website/static/src
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2013-11-26 17:01:48 +0100
committerXavier Morel <xmo@openerp.com>2013-11-26 17:01:48 +0100
commit44af6d1e09aa3bec6967ac3eb4e67b3e9215fb08 (patch)
treeedd62496333fd12960b2b3a3a5f111c72b54314a /addons/website/static/src
parentb3061b910357a320aae568efe68fbe7561b7ea3e (diff)
[IMP] significantly improve handling of trying to create a new page which already exists
# Through the menu Rather than output a generic error (500 due to an IntegrityError), return a templated 409 letting the user either visit the page-which-already-exists-with-the-name-he'd-picked or open the page creation dialog again for a second round. An alternative would be to promote the website.prompt use to full-blown dialog as a result of selecting "New Page" and handle the "page already exists" case without even closing the dialog. # Through the link dialog Added an RPC call to check if a page already exists (essentially a cheaper version of opening /page/whatever and checking whether it's a 200 over JSON-RPC), if the page matching the completion term already exists, do *not* add the choice of creating the page, only provide completions from existing pages. bzr revid: xmo@openerp.com-20131126160148-wrk4zvz9istscwa0
Diffstat (limited to 'addons/website/static/src')
-rw-r--r--addons/website/static/src/js/website.editor.js52
-rw-r--r--addons/website/static/src/xml/website.xml13
2 files changed, 43 insertions, 22 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index 52b3f19e1ba..c50ad392887 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -888,7 +888,8 @@
this._super(editor);
this.text = null;
// Store last-performed request to be able to cancel/abort it.
- this.req = null;
+ this.page_exists_req = null;
+ this.search_pages_req = null;
},
start: function () {
var self = this;
@@ -896,15 +897,20 @@
minimumInputLength: 1,
placeholder: _t("New or existing page"),
query: function (q) {
- self.fetch_pages(q.term).then(function (results) {
+ $.when(
+ self.page_exists(q.term),
+ self.fetch_pages(q.term)
+ ).then(function (exists, results) {
var rs = _.map(results, function (r) {
return { id: r.url, text: r.name, };
});
- rs.push({
- create: true,
- id: q.term,
- text: _.str.sprintf(_t("Create page '%s'"), q.term),
- });
+ if (!exists) {
+ rs.push({
+ create: true,
+ id: q.term,
+ text: _.str.sprintf(_t("Create page '%s'"), q.term),
+ });
+ }
q.callback({
more: false,
results: rs
@@ -983,20 +989,30 @@
.siblings().removeClass('active')
.addBack().removeClass('has-error');
},
- fetch_pages: function (term) {
+ call: function (method, args, kwargs) {
var self = this;
- if (this.req) { this.req.abort(); }
- return this.req = openerp.jsonRpc('/web/dataset/call_kw', 'call', {
+ var req = method + '_req';
+
+ if (this[req]) { this[req].abort(); }
+
+ return this[req] = openerp.jsonRpc('/web/dataset/call_kw', 'call', {
model: 'website',
- method: 'search_pages',
- args: [null, term],
- kwargs: {
- limit: 9,
- context: website.get_context()
- },
+ method: method,
+ args: args,
+ kwargs: kwargs,
}).always(function () {
- // request completed -> unstore it
- self.req = null;
+ self[req] = null;
+ });
+ },
+ page_exists: function (term) {
+ return this.call('page_exists', [null, term], {
+ context: website.get_context(),
+ });
+ },
+ fetch_pages: function (term) {
+ return this.call('search_pages', [null, term], {
+ limit: 9,
+ context: website.get_context(),
});
},
});
diff --git a/addons/website/static/src/xml/website.xml b/addons/website/static/src/xml/website.xml
index b35dd8a9cfc..d5368ec7b94 100644
--- a/addons/website/static/src/xml/website.xml
+++ b/addons/website/static/src/xml/website.xml
@@ -72,16 +72,21 @@
<button title="Close" type="button" class="close" data-dismiss="modal">×</button>
<div class="h2"><t t-esc="title"/></div>
</div>
- <div class="modal-body">
+ <div class="modal-body" t-if="message or backend_url">
<section>
<t t-esc="message"/>
</section>
- <section class="mt32">
- You have encountered an error. You can edit in the <a t-att-href="backend_url">backend</a> this data.
+ <section class="mt32" t-if="backend_url">
+ <p>The web site has encountered an error.</p>
+ <p>
+ It might be possible to edit the relevant items
+ or fix the issue in <a t-href="#{backend_url}">
+ the classic OpenERP interface</a>.
+ </p>
</section>
</div>
<div class="modal-footer">
- <button type="button" data-dismiss="modal" href="#" class="close btn btn-default">Close</button>
+ <button type="button" data-dismiss="modal" class="btn btn-primary">Close</button>
</div>
</div>
</div>