diff --git a/fields/search.py b/fields/search.py index 8645094..91c1be4 100644 --- a/fields/search.py +++ b/fields/search.py @@ -162,6 +162,7 @@ class UiSearch: # Default values for request parameters defining query sort and filter sortFilterDefaults = {'sortKey': '', 'sortOrder': 'asc', 'filterKey': '', 'filterValue': ''} + pxByMode = {'list': 'pxResultList', 'grid': 'pxResultGrid'} # Rendering a search pxView = Px(''' @@ -175,55 +176,46 @@ class UiSearch: # Search results, as a list (used by pxResult below) pxResultList = Px(''' - - - - - - - - +
- - - ::ztool.truncateText(_(field.labelId)) - :tool.pxSortAndFilter - :tool.pxShowDetails -
+ + + + + - - - - - :zobj.appy().pxViewAsResult -
+ + + ::ztool.truncateText(_(field.labelId)) + :tool.pxSortAndFilter + :tool.pxShowDetails +
:_('query_no_result')
- -
- -
- - -
''') + + + :_('query_no_result') + + :zobj.appy().pxViewAsResult + + +
+ +
+ + + ''') # Search results, as a grid (used by pxResult below) pxResultGrid = Px(''' @@ -246,8 +238,12 @@ class UiSearch: pxResult = Px('''
+ :uiSearch.translatedDescr
- +
:tool.pxNavigate:tool.pxNavigate
- + - :uiSearch.pxResultList - :uiSearch.pxResultGrid - + currentNumber=0">:uiSearch.getPx(resultMode, klass)
- :tool.pxNavigate + :tool.pxNavigate @@ -373,10 +376,22 @@ class UiSearch: Else, simply return the name of the search.''' return getattr(self, 'initiatorHook', self.name) - def getResultMode(self, klass): - '''Must we show, on pxResult, instances of p_klass as a list or - as a grid?''' - return getattr(klass, 'resultMode', 'list') + def getAllResultModes(self, klass): + '''How must we show the result? As a list, grid, or a custom px?''' + return getattr(klass, 'resultModes', ('list',)) + + def getResultMode(self, klass, req): + '''Get the current result mode''' + res = req.get('resultMode') + if not res: res = self.getAllResultModes(klass)[0] + return res + + def getPx(self, mode, klass): + '''What is the PX to show, according to the current result p_mode?''' + if mode in UiSearch.pxByMode: + return getattr(UiSearch, UiSearch.pxByMode[mode]) + # It must be a custom PX on p_klass + return getattr(klass, mode) def showCheckboxes(self): '''If checkboxes are enabled for this search (and if an initiator field @@ -420,4 +435,9 @@ class UiSearch: return "new AjaxData('%s', 'pxViewAsResultFromAjax', %s, '%s', '%s')"% \ (hook, sutils.getStringDict(params), parentHook, zobj.absolute_url()) + + def getModeText(self, mode, _): + '''Gets the i18n text corresponding to p_mode''' + if mode in UiSearch.pxByMode: return _('result_mode_%s' % mode) + return _('custom_%s' % mode) # ------------------------------------------------------------------------------ diff --git a/gen/tr/Appy.pot b/gen/tr/Appy.pot index 5241818..b1988c8 100644 --- a/gen/tr/Appy.pot +++ b/gen/tr/Appy.pot @@ -794,3 +794,11 @@ msgstr "" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "" + +#. Default: "List" +msgid "result_mode_list" +msgstr "" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "" diff --git a/gen/tr/ar.po b/gen/tr/ar.po index 2e5be2f..4d01a6f 100644 --- a/gen/tr/ar.po +++ b/gen/tr/ar.po @@ -794,3 +794,11 @@ msgstr "" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "" + +#. Default: "List" +msgid "result_mode_list" +msgstr "" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "" diff --git a/gen/tr/de.po b/gen/tr/de.po index 7a04182..c396326 100644 --- a/gen/tr/de.po +++ b/gen/tr/de.po @@ -794,3 +794,11 @@ msgstr "" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "" + +#. Default: "List" +msgid "result_mode_list" +msgstr "" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "" diff --git a/gen/tr/en.po b/gen/tr/en.po index a6c8431..c46b498 100644 --- a/gen/tr/en.po +++ b/gen/tr/en.po @@ -795,3 +795,11 @@ msgstr "${site} - ${title} - ${template}" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." + +#. Default: "List" +msgid "result_mode_list" +msgstr "List" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "Grid" diff --git a/gen/tr/es.po b/gen/tr/es.po index 5f78dd6..d539996 100644 --- a/gen/tr/es.po +++ b/gen/tr/es.po @@ -794,3 +794,11 @@ msgstr "" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "" + +#. Default: "List" +msgid "result_mode_list" +msgstr "" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "" diff --git a/gen/tr/fr.po b/gen/tr/fr.po index 73072f1..1b257a4 100644 --- a/gen/tr/fr.po +++ b/gen/tr/fr.po @@ -795,3 +795,11 @@ msgstr "${site} - ${title} - ${template}" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "Bonjour, cet email vous est envoyé depuis ${site}. Veuillez consulter le(s) fichier(s) joint(s)." + +#. Default: "List" +msgid "result_mode_list" +msgstr "Liste" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "Grille" diff --git a/gen/tr/it.po b/gen/tr/it.po index 7d04fc2..25e76e7 100644 --- a/gen/tr/it.po +++ b/gen/tr/it.po @@ -794,3 +794,11 @@ msgstr "" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "" + +#. Default: "List" +msgid "result_mode_list" +msgstr "" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "" diff --git a/gen/tr/nl.po b/gen/tr/nl.po index 11e6e4c..291d2f0 100644 --- a/gen/tr/nl.po +++ b/gen/tr/nl.po @@ -794,3 +794,11 @@ msgstr "" #. Default: "Hello, this email that was sent to you via ${site}. Please consult the attached file(s)." msgid "podmail_body" msgstr "" + +#. Default: "List" +msgid "result_mode_list" +msgstr "" + +#. Default: "Grid" +msgid "result_mode_grid" +msgstr "" diff --git a/gen/ui/appy.js b/gen/ui/appy.js index d6ec271..fc34b1d 100644 --- a/gen/ui/appy.js +++ b/gen/ui/appy.js @@ -56,11 +56,16 @@ function len(dict) { return res; } -function switchLanguage(selectWidget, siteUrl) { - var language = selectWidget.options[selectWidget.selectedIndex].value; +function switchLanguage(select, siteUrl) { + var language = select.options[select.selectedIndex].value; goto(siteUrl + '/config/changeLanguage?language=' + language); } +function switchResultMode(select, hook) { + var mode = select.options[select.selectedIndex].value; + askAjax(hook, null, {'resultMode': mode}); +} + var isIe = (navigator.appName == "Microsoft Internet Explorer"); function getElementsHavingName(tag, name) { @@ -308,11 +313,14 @@ function askAjax(hook, form, params, waiting) { } else var mode = d.mode; // Get p_params if given. Note that they override anything else. - if (params && ('mode' in params)) { - mode = params['mode']; delete params['mode'] } - if (params) { for (var key in params) d.params[key] = params[key]; } - askAjaxChunk(hook, mode, d.url, d.px, d.params, d.beforeSend, - evalInnerScripts, waiting); + var px = d.px; + if (params) { + if ('mode' in params) { mode = params['mode']; delete params['mode'] }; + if ('px' in params) { px = params['px']; delete params['px'] }; + for (var key in params) d.params[key] = params[key]; + } + askAjaxChunk(hook, mode, d.url, px, d.params, d.beforeSend, evalInnerScripts, + waiting); } function askBunch(hookId, startNumber) { diff --git a/gen/wrappers/ToolWrapper.py b/gen/wrappers/ToolWrapper.py index b965bde..87d7646 100644 --- a/gen/wrappers/ToolWrapper.py +++ b/gen/wrappers/ToolWrapper.py @@ -344,11 +344,21 @@ class ToolWrapper(AbstractWrapper):
- :tool.pxPagePrologue:uiSearch.pxResult + :tool.pxPagePrologue +
+ +
+ :uiSearch.pxResult
''', template=AbstractWrapper.pxTemplate, hook='content') pxSearch = Px('''