Commit ea8f4516 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web_renderjs_ui: handle user's manually query and don't crash for unsupported query

parent 4a27ce80
......@@ -529,6 +529,7 @@
})\n
.push(function (result) {\n
var query_list,\n
query_item_list,\n
domain_tree_map = result._embedded._view.listbox.domain_tree_map,\n
domain_tree_query_list;\n
gadget.props.column_list = result._embedded._view.listbox.column_list;\n
......@@ -542,16 +543,17 @@
and.checked = true;\n
and.parentElement.children[0].setAttribute("class", "ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-radio-on");\n
}\n
if (or.checked) {\n
query_list = query_list.query_list[0].query_list || [];\n
//OR built by itself\n
if (or.checked && query_list.operator === "NOT") {\n
query_item_list = query_list.query_list[0].query_list || [];\n
} else {\n
query_list = query_list.query_list || [query_list];\n
query_item_list = query_list.query_list || [query_list];\n
}\n
for (i = 0; i < query_list.length; i += 1) {\n
if (or.checked) {\n
item = createFilterItem(gadget, query_list[i].query_list[0]);\n
for (i = 0; i < query_item_list.length; i += 1) {\n
if (or.checked && query_list.operator === "NOT") {\n
item = createFilterItem(gadget, query_item_list[i].query_list[0]);\n
} else {\n
item = createFilterItem(gadget, query_list[i]);\n
item = createFilterItem(gadget, query_item_list[i]);\n
}\n
container.insertBefore(item, container.lastChild);\n
}\n
......@@ -753,7 +755,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>946.4083.26515.61815</string> </value>
<value> <string>946.4378.65397.6826</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -771,7 +773,7 @@
</tuple>
<state>
<tuple>
<float>1443514871.92</float>
<float>1443533150.45</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -145,6 +145,7 @@
.declareAcquiredMethod("redirect", "redirect")\n
.declareAcquiredMethod("getFieldTypeGadgetUrl", "getFieldTypeGadgetUrl")\n
.declareAcquiredMethod("triggerSortEditor", "triggerSortEditor")\n
.declareAcquiredMethod("showQueryError", "showQueryError")\n
//////////////////////////////////////////////\n
// initialize the gadget content\n
//////////////////////////////////////////////\n
......@@ -497,6 +498,12 @@
var temp = document.createElement("tfoot");\n
temp.innerHTML = my_translated_html;\n
table.appendChild(temp);\n
})\n
.fail(function (error) {\n
if (error.target.status === 500) {\n
return gadget.showQueryError(" Unsupportred Query");\n
}\n
throw error;\n
});\n
})\n
.declareService(function () {\n
......@@ -782,7 +789,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>946.4319.25695.31351</string> </value>
<value> <string>946.4415.55526.9147</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -800,7 +807,7 @@
</tuple>
<state>
<tuple>
<float>1443529209.21</float>
<float>1443535241.5</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -152,6 +152,17 @@
return sortEditor.toggle();\n
});\n
})\n
.allowPublicAcquisition("showQueryError", function (param) {\n
var gadget = this;\n
return new RSVP.Queue()\n
.push(function () {\n
return gadget.getDeclaredGadget("erp5_searchfield");\n
})\n
.push(function (searchField) {\n
return searchField.showQueryError(param);\n
});\n
})\n
\n
\n
.declareMethod(\'render\', function (options) {\n
var gadget = this,\n
......@@ -160,6 +171,7 @@
\n
form_options.erp5_document = options.erp5_document;\n
form_options.form_definition = options.form_definition;\n
search_options.jio_key = options.jio_key;\n
// XXX not generic, fix later\n
if (options.extended_search) {\n
form_options.form_definition.extended_search = options.extended_search;\n
......@@ -385,7 +397,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.64053.62550.18722</string> </value>
<value> <string>946.4412.4475.4949</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -403,7 +415,7 @@
</tuple>
<state>
<tuple>
<float>1443185583.96</float>
<float>1443534607.25</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -99,7 +99,9 @@
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>/*global window, rJS, RSVP, loopEventListener, Handlebars */\n
<value> <string encoding="cdata"><![CDATA[
/*global window, rJS, RSVP, loopEventListener, Handlebars */\n
/*jslint nomen: true, indent: 2, maxerr: 3 */\n
(function (window, rJS, RSVP, loopEventListener, Handlebars) {\n
"use strict";\n
......@@ -135,8 +137,7 @@
// acquired method\n
//////////////////////////////////////////////\n
.declareAcquiredMethod("translateHtml", "translateHtml")\n
.declareAcquiredMethod("pleasePublishMyState", "pleasePublishMyState")\n
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")\n
.declareAcquiredMethod("redirect", "redirect")\n
.declareAcquiredMethod("triggerFilterEditor", "triggerFilterEditor")\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
......@@ -149,7 +150,7 @@
hide_value,\n
is_disabled = option_dict.disabled,\n
search_gadget = this;\n
\n
search_gadget.props.jio_key = option_dict.jio_key;\n
if (is_disabled) {\n
append_class = " ui-disabled";\n
append_attribute = \' disabled="disabled\';\n
......@@ -173,7 +174,10 @@
return search_gadget;\n
});\n
})\n
\n
.declareMethod("showQueryError", function (param) {\n
var input = this.props.element.querySelector(\'input[name="search"]\');\n
input.value += param;\n
})\n
.declareMethod(\'getContent\', function () {\n
var input = this.props.element.querySelector(\'input\'),\n
result = {};\n
......@@ -183,7 +187,12 @@
})\n
\n
.declareService(function () {\n
var gadget = this;\n
var gadget = this,\n
i,\n
query_list,\n
tmp,\n
hide_query,\n
search_query;\n
\n
function filterSubmit(evt) {\n
return gadget.triggerFilterEditor();\n
......@@ -195,12 +204,41 @@
return gadget.getContent();\n
})\n
.push(function (data) {\n
return gadget.pleasePublishMyState({\n
"extended_search": data.search\n
if (data.search) {\n
query_list = [];\n
search_query = QueryFactory.create(data.search);\n
if (search_query instanceof SimpleQuery) {\n
tmp = [search_query];\n
} else {\n
tmp = search_query.query_list;\n
}\n
for (i = 0; i < tmp.length; i += 1) {\n
if (tmp[i] instanceof SimpleQuery) {\n
if (tmp[i].key !== "catalog.uid") {\n
query_list.push(tmp[i]);\n
} else {\n
hide_query = new ComplexQuery({\n
operator: "AND",\n
query_list: [tmp[i]],\n
type: "complex"\n
});\n
})\n
.push(function (url) {\n
return gadget.pleaseRedirectMyHash(url);\n
}\n
} else {\n
//only have one complex query\n
hide_query = search_query.query_list[i];\n
}\n
}\n
\n
return gadget.redirect({jio_key: gadget.props.jio_key,\n
"extended_search": Query.objectToSearchText(new ComplexQuery({\n
operator: search_query.operator || "AND",\n
query_list: query_list,\n
type: "complex"\n
})),\n
"hide_item": hide_query ? Query.objectToSearchText(hide_query) : ""});\n
}\n
return gadget.redirect({jio_key: gadget.props.jio_key,\n
"extended_search": "", "hide_item": ""});\n
});\n
}\n
// Listen to form submit\n
......@@ -218,7 +256,9 @@
);\n
});\n
\n
}(window, rJS, RSVP, loopEventListener, Handlebars));</string> </value>
}(window, rJS, RSVP, loopEventListener, Handlebars));
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
......@@ -353,7 +393,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.64076.531.55330</string> </value>
<value> <string>946.4406.57134.42359</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -371,7 +411,7 @@
</tuple>
<state>
<tuple>
<float>1443183688.67</float>
<float>1443534489.37</float>
<string>UTC</string>
</tuple>
</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