Commit 96f5d5bc authored by Sven Franck's avatar Sven Franck Committed by Sebastien Robin

Added search field on gadget wrapping a listbox

parent d2a9980e
......@@ -140,6 +140,7 @@
group_list = form_definition.group_list,\n
queue = new RSVP.Queue(),\n
form_gadget = this,\n
suboption_dict = {},\n
parent_element = document.createElement("div");\n
\n
delete options.erp5_document;\n
......@@ -147,6 +148,10 @@
\n
// options = options.form_gadget || {};\n
form_gadget.state_parameter_dict = options.form_gadget || {};\n
// XXX Hardcoded for searchfield - remove later!\n
if (form_definition.extended_search) {\n
suboption_dict.extended_search = form_definition.extended_search;\n
}\n
\n
form_gadget.props.gadget_list = [];\n
form_gadget.props.id = erp5_document._id;\n
......@@ -203,7 +208,7 @@
})\n
.push(function (field_gadget) {\n
form_gadget.props.gadget_list.push(field_gadget);\n
var suboptions = options[renderered_field.key] || {};\n
var suboptions = options[renderered_field.key] || suboption_dict;\n
suboptions.field_json = renderered_field;\n
return field_gadget.render(suboptions);\n
});\n
......
......@@ -138,6 +138,7 @@
\n
gadget.props.field_json = field_json;\n
gadget.props.begin_from = parseInt(options.begin_from, 10) || 0;\n
gadget.props.extended_search = options.extended_search;\n
\n
for (i = 0; i < field_json.column_list.length; i += 1) {\n
th = document.createElement("th");\n
......@@ -152,22 +153,34 @@
//////////////////////////////////////////////\n
.declareService(function () {\n
var gadget = this,\n
field_json = gadget.props.field_json,\n
begin_from = gadget.props.begin_from,\n
table = gadget.props.element.querySelector(\'table\'),\n
props = gadget.props,\n
field_json = props.field_json,\n
begin_from = props.begin_from,\n
table = props.element.querySelector(\'table\'),\n
tbody = document.createElement("tbody"),\n
url_query = props.extended_search,\n
query_string = "",\n
lines = field_json.lines,\n
select_list = [],\n
dataset,\n
counter,\n
i;\n
\n
// function buildQueryString(previous, next) {\n
// return previous + next[0] + \':= "\' + url_query + \'" OR \';\n
// }\n
\n
if (url_query) {\n
//query_string = field_json.column_list.reduce(buildQueryString, \' AND (\').replace(new RegExp("OR " + \'$\'), \')\');\n
query_string = \' AND \' + url_query;\n
}\n
\n
for (i = 0; i < field_json.column_list.length; i += 1) {\n
select_list.push(field_json.column_list[i][0]);\n
}\n
\n
return gadget.jio_allDocs({\n
"query": new URI(field_json.query).query(true).query,\n
"query": new URI(field_json.query).query(true).query + query_string,\n
"limit": [begin_from, begin_from + lines + 1],\n
"select_list": select_list\n
}).push(function (result) {\n
......@@ -239,7 +252,7 @@
paging_wrap = document.createElement("div"),\n
len;\n
\n
th.colspan = lines;\n
th.setAttribute("colspan", field_json.column_list.length);\n
\n
paging_menu.className = "ui-controlgroup ui-controlgroup-horizontal ui-corner-all";\n
paging_wrap.className = "ui-controlgroup-controls";\n
......
......@@ -118,10 +118,13 @@
\n
</head>\n
<body>\n
\n
<div data-gadget-url="gadget_erp5_searchfield.html"\n
data-gadget-scope="erp5_searchfield"\n
data-gadget-sandbox="public"></div>\n
\n
<div data-gadget-url="gadget_erp5_form.html"\n
data-gadget-scope="erp5_form"\n
data-gadget-sandbox="public">\n
data-gadget-sandbox="public"></div>\n
\n
</body>\n
</html>
......
......@@ -97,7 +97,6 @@
<key> <string>text_content</string> </key>
<value> <string>/*global rJS, RSVP, jQuery, Handlebars,\n
promiseEventListener, console */\n
/*jslint nomen: true */\n
/*global window, rJS, RSVP, StatelessJS, alert, FormData, document, console */\n
/*jslint maxlen:200, nomen: true */\n
(function (window, rJS, RSVP) {\n
......@@ -108,16 +107,31 @@
// declared methods\n
/////////////////////////////////////////////////////////////////\n
.declareMethod(\'render\', function (options) {\n
\n
var gadget = this;\n
var form_options = options.erp5_form || {};\n
var search_options = {};\n
\n
form_options.erp5_document = options.erp5_document;\n
form_options.form_definition = options.form_definition;\n
// XXX not generic, fix later\n
if (options.erp5_searchfield) {\n
form_options.form_definition.extended_search = options.erp5_searchfield.extended_search;\n
search_options.extended_search = options.erp5_searchfield.extended_search;\n
}\n
form_options.view = options.view;\n
\n
return this.getDeclaredGadget("erp5_form")\n
.push(function (erp5_form) {\n
return erp5_form.render(form_options);\n
return new RSVP.Queue()\n
.push(function () {\n
return RSVP.all([\n
gadget.getDeclaredGadget("erp5_searchfield"),\n
gadget.getDeclaredGadget("erp5_form")\n
]);\n
})\n
.push(function (all_gadget) {\n
return RSVP.all([\n
all_gadget[0].render(search_options),\n
all_gadget[1].render(form_options)\n
]);\n
});\n
\n
});\n
......
<?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>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
<string>Owner</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>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
<string>Owner</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_searchfield.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_erp5_searchfield_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </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>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[
<!DOCTYPE html>\n
<html>\n
<head>\n
<meta charset="utf-8" />\n
<meta name="viewport" content="width=device-width, user-scalable=no" />\n
<title>ERP5 Search Field</title>\n
\n
<!-- renderjs -->\n
<script src="RSVP.js"></script>\n
<script src="renderjs.js"></script>\n
<!-- <script src="handlebars.js"></script> -->\n
\n
<!-- custom script -->\n
<script src="gadget_erp5_searchfield.js"></script>\n
\n
</head>\n
<body>\n
\n
<fieldset class="center">\n
<form class="search_form">\n
<div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset ui-input-has-clear">\n
<input type="text" data-enhanced="true" value="" name="search" />\n
<div class="ui-btn ui-input-clear ui-input-btn ui-corner-all ui-icon-search ui-btn-icon-notext">\n
Submit<input data-enhanced="true" type="submit" value="Submit">\n
</div>\n
</div>\n
</form>\n
</fieldset>\n
\n
</body>\n
</html>
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget ERP5 Search Field</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
<string>Owner</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>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Manager</string>
<string>Owner</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_searchfield.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_erp5_searchfield_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </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>text_content</string> </key>
<value> <string>/*global rJS, RSVP, jQuery, Handlebars,\n
promiseEventListener, console */\n
/*global window, rJS, RSVP, StatelessJS, alert, FormData, document, console */\n
/*jslint maxlen:200, nomen: true */\n
(function (window, rJS, RSVP, $) {\n
"use strict";\n
\n
rJS(window)\n
/////////////////////////////////////////////////////////////////\n
// ready\n
/////////////////////////////////////////////////////////////////\n
// Init local properties\n
.ready(function (g) {\n
g.props = {};\n
})\n
\n
// Assign the element to a variable\n
.ready(function (g) {\n
return g.getElement()\n
.push(function (element) {\n
g.props.element = element;\n
});\n
})\n
\n
.declareAcquiredMethod("pleasePublishMyState", "pleasePublishMyState")\n
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
/////////////////////////////////////////////////////////////////\n
.declareMethod(\'render\', function (options) {\n
this.props.element.querySelector("input").value = options.extended_search || "";\n
})\n
\n
.declareMethod(\'getContent\', function () {\n
var input = this.__element.querySelector(\'input\'),\n
result = {};\n
\n
result[input.getAttribute(\'name\')] = input.value;\n
return result;\n
})\n
\n
.declareService(function () {\n
var search_form = this;\n
\n
function formSubmit() {\n
var form_data;\n
\n
return new RSVP.Queue()\n
.push(function () {\n
return search_form.getContent();\n
})\n
.push(function (data) {\n
console.log(data);\n
return search_form.pleasePublishMyState({\n
"extended_search": data.search\n
});\n
})\n
.push(function (url) {\n
console.log(url);\n
return search_form.pleaseRedirectMyHash(url);\n
});\n
}\n
\n
// Listen to form submit\n
return loopEventListener(\n
search_form.props.element.querySelector(\'form\'),\n
\'submit\',\n
false,\n
formSubmit\n
);\n
});\n
\n
}(window, rJS, RSVP, jQuery));</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget ERP5 Search Field JS</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
18
\ No newline at end of file
19
\ No newline at end of file
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