From f2ab286d0cd4775b46a9ce3df72445c7ca790f8c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 27 Jan 2011 22:57:06 +0100 Subject: jqGrid integration (v3.8.2) --- static/media/ui.jqgrid.css | 139 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 static/media/ui.jqgrid.css (limited to 'static/media') diff --git a/static/media/ui.jqgrid.css b/static/media/ui.jqgrid.css new file mode 100644 index 000000000..e69018909 --- /dev/null +++ b/static/media/ui.jqgrid.css @@ -0,0 +1,139 @@ +/*Grid*/ +.ui-jqgrid {position: relative; font-size:11px;} +.ui-jqgrid .ui-jqgrid-view {position: relative;left:0px; top: 0px; padding: .0em;} +/* caption*/ +.ui-jqgrid .ui-jqgrid-titlebar {padding: .3em .2em .2em .3em; position: relative; border-left: 0px none;border-right: 0px none; border-top: 0px none;} +.ui-jqgrid .ui-jqgrid-title { float: left; margin: .1em 0 .2em; } +.ui-jqgrid .ui-jqgrid-titlebar-close { position: absolute;top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height:18px;}.ui-jqgrid .ui-jqgrid-titlebar-close span { display: block; margin: 1px; } +.ui-jqgrid .ui-jqgrid-titlebar-close:hover { padding: 0; } +/* header*/ +.ui-jqgrid .ui-jqgrid-hdiv {position: relative; margin: 0em;padding: 0em; overflow-x: hidden; overflow-y: auto; border-left: 0px none !important; border-top : 0px none !important; border-right : 0px none !important;} +.ui-jqgrid .ui-jqgrid-hbox {float: left; padding-right: 20px;} +.ui-jqgrid .ui-jqgrid-htable {table-layout:fixed;margin:0em;} +.ui-jqgrid .ui-jqgrid-htable th {height:22px;padding: 0 2px 0 2px;} +.ui-jqgrid .ui-jqgrid-htable th div {overflow: hidden; position:relative; height:17px;} +.ui-th-column, .ui-jqgrid .ui-jqgrid-htable th.ui-th-column {overflow: hidden;white-space: nowrap;text-align:center;border-top : 0px none;border-bottom : 0px none;} +.ui-th-ltr, .ui-jqgrid .ui-jqgrid-htable th.ui-th-ltr {border-left : 0px none;} +.ui-th-rtl, .ui-jqgrid .ui-jqgrid-htable th.ui-th-rtl {border-right : 0px none;} +.ui-jqgrid .ui-th-div-ie {white-space: nowrap; zoom :1; height:17px;} +.ui-jqgrid .ui-jqgrid-resize {height:20px !important;position: relative; cursor :e-resize;display: inline;overflow: hidden;} +.ui-jqgrid .ui-grid-ico-sort {overflow:hidden;position:absolute;display:inline; cursor: pointer !important;} +.ui-jqgrid .ui-icon-asc {margin-top:-3px; height:12px;} +.ui-jqgrid .ui-icon-desc {margin-top:3px;height:12px;} +.ui-jqgrid .ui-i-asc {margin-top:0px;height:16px;} +.ui-jqgrid .ui-i-desc {margin-top:0px;margin-left:13px;height:16px;} +.ui-jqgrid .ui-jqgrid-sortable {cursor:pointer;} +.ui-jqgrid tr.ui-search-toolbar th { border-top-width: 1px !important; border-top-color: inherit !important; border-top-style: ridge !important } +tr.ui-search-toolbar input {margin: 1px 0px 0px 0px} +tr.ui-search-toolbar select {margin: 1px 0px 0px 0px} +/* body */ +.ui-jqgrid .ui-jqgrid-bdiv {position: relative; margin: 0em; padding:0; overflow: auto; text-align:left;} +.ui-jqgrid .ui-jqgrid-btable {table-layout:fixed; margin:0em;} +.ui-jqgrid tr.jqgrow td {font-weight: normal; overflow: hidden; white-space: pre; height: 22px;padding: 0 2px 0 2px;border-bottom-width: 1px; border-bottom-color: inherit; border-bottom-style: solid;} +.ui-jqgrid tr.jqgfirstrow td {padding: 0 2px 0 2px;border-right-width: 1px; border-right-style: solid;} +.ui-jqgrid tr.jqgroup td {font-weight: normal; overflow: hidden; white-space: pre; height: 22px;padding: 0 2px 0 2px;border-bottom-width: 1px; border-bottom-color: inherit; border-bottom-style: solid;} +.ui-jqgrid tr.jqfoot td {font-weight: bold; overflow: hidden; white-space: pre; height: 22px;padding: 0 2px 0 2px;border-bottom-width: 1px; border-bottom-color: inherit; border-bottom-style: solid;} +.ui-jqgrid tr.ui-row-ltr td {text-align:left;border-right-width: 1px; border-right-color: inherit; border-right-style: solid;} +.ui-jqgrid tr.ui-row-rtl td {text-align:right;border-left-width: 1px; border-left-color: inherit; border-left-style: solid;} +.ui-jqgrid td.jqgrid-rownum { padding: 0 2px 0 2px; margin: 0px; border: 0px none;} +.ui-jqgrid .ui-jqgrid-resize-mark { width:2px; left:0; background-color:#777; cursor: e-resize; cursor: col-resize; position:absolute; top:0; height:100px; overflow:hidden; display:none; border:0 none;} +/* footer */ +.ui-jqgrid .ui-jqgrid-sdiv {position: relative; margin: 0em;padding: 0em; overflow: hidden; border-left: 0px none !important; border-top : 0px none !important; border-right : 0px none !important;} +.ui-jqgrid .ui-jqgrid-ftable {table-layout:fixed; margin-bottom:0em;} +.ui-jqgrid tr.footrow td {font-weight: bold; overflow: hidden; white-space:nowrap; height: 21px;padding: 0 2px 0 2px;border-top-width: 1px; border-top-color: inherit; border-top-style: solid;} +.ui-jqgrid tr.footrow-ltr td {text-align:left;border-right-width: 1px; border-right-color: inherit; border-right-style: solid;} +.ui-jqgrid tr.footrow-rtl td {text-align:right;border-left-width: 1px; border-left-color: inherit; border-left-style: solid;} +/* Pager*/ +.ui-jqgrid .ui-jqgrid-pager { border-left: 0px none !important;border-right: 0px none !important; border-bottom: 0px none !important; margin: 0px !important; padding: 0px !important; position: relative; height: 25px;white-space: nowrap;overflow: hidden;} +.ui-jqgrid .ui-pager-control {position: relative;} +.ui-jqgrid .ui-pg-table {position: relative; padding-bottom:2px; width:auto; margin: 0em;} +.ui-jqgrid .ui-pg-table td {font-weight:normal; vertical-align:middle; padding:1px;} +.ui-jqgrid .ui-pg-button { height:19px !important;} +.ui-jqgrid .ui-pg-button span { display: block; margin: 1px; float:left;} +.ui-jqgrid .ui-pg-button:hover { padding: 0px; } +.ui-jqgrid .ui-state-disabled:hover {padding:1px;} +.ui-jqgrid .ui-pg-input { height:13px;font-size:.8em; margin: 0em;} +.ui-jqgrid .ui-pg-selbox {font-size:.8em; line-height:18px; display:block; height:18px; margin: 0em;} +.ui-jqgrid .ui-separator {height: 18px; border-left: 1px solid #ccc ; border-right: 1px solid #ccc ; margin: 1px; float: right;} +.ui-jqgrid .ui-paging-info {font-weight: normal;height:19px; margin-top:3px;margin-right:4px;} +.ui-jqgrid .ui-jqgrid-pager .ui-pg-div {padding:1px 0;float:left;list-style-image:none;list-style-position:outside;list-style-type:none;position:relative;} +.ui-jqgrid .ui-jqgrid-pager .ui-pg-button { cursor:pointer; } +.ui-jqgrid .ui-jqgrid-pager .ui-pg-div span.ui-icon {float:left;margin:0 2px;} +.ui-jqgrid td input, .ui-jqgrid td select .ui-jqgrid td textarea { margin: 0em;} +.ui-jqgrid td textarea {width:auto;height:auto;} +.ui-jqgrid .ui-jqgrid-toppager {border-left: 0px none !important;border-right: 0px none !important; border-top: 0px none !important; margin: 0px !important; padding: 0px !important; position: relative; height: 25px !important;white-space: nowrap;overflow: hidden;} +/*subgrid*/ +.ui-jqgrid .ui-jqgrid-btable .ui-sgcollapsed span {display: block;} +.ui-jqgrid .ui-subgrid {margin:0em;padding:0em; width:100%;} +.ui-jqgrid .ui-subgrid table {table-layout: fixed;} +.ui-jqgrid .ui-subgrid tr.ui-subtblcell td {height:18px;border-right-width: 1px; border-right-color: inherit; border-right-style: solid;border-bottom-width: 1px; border-bottom-color: inherit; border-bottom-style: solid;} +.ui-jqgrid .ui-subgrid td.subgrid-data {border-top: 0px none !important;} +.ui-jqgrid .ui-subgrid td.subgrid-cell {border-width: 0px 0px 1px 0px;} +.ui-jqgrid .ui-th-subgrid {height:20px;} +/* loading */ +.ui-jqgrid .loading {position: absolute; top: 45%;left: 45%;width: auto;z-index:101;padding: 6px; margin: 5px;text-align: center;font-weight: bold;display: none;border-width: 2px !important;} +.ui-jqgrid .jqgrid-overlay {display:none;z-index:100;} +* html .jqgrid-overlay {width: expression(this.parentNode.offsetWidth+'px');height: expression(this.parentNode.offsetHeight+'px');} +* .jqgrid-overlay iframe {position:absolute;top:0;left:0;z-index:-1;width: expression(this.parentNode.offsetWidth+'px');height: expression(this.parentNode.offsetHeight+'px');} +/* end loading div */ +/* toolbar */ +.ui-jqgrid .ui-userdata {border-left: 0px none; border-right: 0px none; height : 21px;overflow: hidden; } +/*Modal Window */ +.ui-jqdialog { display: none; width: 300px; position: absolute; padding: .2em; font-size:11px; overflow:visible;} +.ui-jqdialog .ui-jqdialog-titlebar { padding: .3em .2em; position: relative; } +.ui-jqdialog .ui-jqdialog-title { margin: .1em 0 .2em; } +.ui-jqdialog .ui-jqdialog-titlebar-close { position: absolute; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; } + +.ui-jqdialog .ui-jqdialog-titlebar-close span { display: block; margin: 1px; } +.ui-jqdialog .ui-jqdialog-titlebar-close:hover, .ui-jqdialog .ui-jqdialog-titlebar-close:focus { padding: 0; } +.ui-jqdialog-content, .ui-jqdialog .ui-jqdialog-content { border: 0; padding: .3em .2em; background: none; height:auto;} +.ui-jqdialog .ui-jqconfirm {padding: .4em 1em; border-width:3px;position:absolute;bottom:10px;right:10px;overflow:visible;display:none;height:80px;width:220px;text-align:center;} +/* end Modal window*/ +/* Form edit */ +.ui-jqdialog-content .FormGrid {margin: 0px;} +.ui-jqdialog-content .EditTable { width: 100%; margin-bottom:0em;} +.ui-jqdialog-content .DelTable { width: 100%; margin-bottom:0em;} +.EditTable td input, .EditTable td select, .EditTable td textarea {margin: 0em;} +.EditTable td textarea { width:auto; height:auto;} +.ui-jqdialog-content td.EditButton {text-align: right;border-top: 0px none;border-left: 0px none;border-right: 0px none; padding-bottom:5px; padding-top:5px;} +.ui-jqdialog-content td.navButton {text-align: center; border-left: 0px none;border-top: 0px none;border-right: 0px none; padding-bottom:5px; padding-top:5px;} +.ui-jqdialog-content input.FormElement {padding:.3em} +.ui-jqdialog-content .data-line {padding-top:.1em;border: 0px none;} + +.ui-jqdialog-content .CaptionTD {text-align: left; vertical-align: middle;border: 0px none; padding: 2px;white-space: nowrap;} +.ui-jqdialog-content .DataTD {padding: 2px; border: 0px none; vertical-align: top;} +.ui-jqdialog-content .form-view-data {white-space:pre} +.fm-button { display: inline-block; margin:0 4px 0 0; padding: .4em .5em; text-decoration:none !important; cursor:pointer; position: relative; text-align: center; zoom: 1; } +.fm-button-icon-left { padding-left: 1.9em; } +.fm-button-icon-right { padding-right: 1.9em; } +.fm-button-icon-left .ui-icon { right: auto; left: .2em; margin-left: 0; position: absolute; top: 50%; margin-top: -8px; } +.fm-button-icon-right .ui-icon { left: auto; right: .2em; margin-left: 0; position: absolute; top: 50%; margin-top: -8px;} +#nData, #pData { float: left; margin:3px;padding: 0; width: 15px; } +/* End Eorm edit */ +/*.ui-jqgrid .edit-cell {}*/ +.ui-jqgrid .selected-row, div.ui-jqgrid .selected-row td {font-style : normal;border-left: 0px none;} +/* Tree Grid */ +.ui-jqgrid .tree-wrap {float: left; position: relative;height: 18px;white-space: nowrap;overflow: hidden;} +.ui-jqgrid .tree-minus {position: absolute; height: 18px; width: 18px; overflow: hidden;} +.ui-jqgrid .tree-plus {position: absolute; height: 18px; width: 18px; overflow: hidden;} +.ui-jqgrid .tree-leaf {position: absolute; height: 18px; width: 18px;overflow: hidden;} +.ui-jqgrid .treeclick {cursor: pointer;} +/* moda dialog */ +.jqmOverlay { background-color: #000; } +* iframe.jqm {position:absolute;top:0;left:0;z-index:-1;width: expression(this.parentNode.offsetWidth+'px');height: expression(this.parentNode.offsetHeight+'px');} +.ui-jqgrid-dnd tr td {border-right-width: 1px; border-right-color: inherit; border-right-style: solid; height:20px} +/* RTL Support */ +.ui-jqgrid .ui-jqgrid-title-rtl {float:right;margin: .1em 0 .2em; } +.ui-jqgrid .ui-jqgrid-hbox-rtl {float: right; padding-left: 20px;} +.ui-jqgrid .ui-jqgrid-resize-ltr {float: right;margin: -2px -2px -2px 0px;} +.ui-jqgrid .ui-jqgrid-resize-rtl {float: left;margin: -2px 0px -1px -3px;} +.ui-jqgrid .ui-sort-rtl {left:0px;} +.ui-jqgrid .tree-wrap-ltr {float: left;} +.ui-jqgrid .tree-wrap-rtl {float: right;} +.ui-jqgrid .ui-ellipsis {text-overflow:ellipsis; -moz-binding:url('ellipsis-xbl.xml#ellipsis');} +.ui-searchFilter { display: none; position: absolute; z-index: 770; overflow: visible;} +.ui-searchFilter table {position:relative; margin:0em; width:auto} +.ui-searchFilter table td {margin: 0em; padding: 1px;} +.ui-searchFilter table td input, .ui-searchFilter table td select {margin: 0.1em;} +.ui-searchFilter .ui-state-default { cursor: pointer; } +.ui-searchFilter .divider hr {margin: 1px; } \ No newline at end of file -- cgit v1.2.3 From 327c22fb70db76186c3765c168a7654102c59177 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 28 Jan 2011 04:31:54 +0100 Subject: Implement a file search mecanism (refs #142) --- ishtar/furnitures/forms.py | 23 ++++++++- ishtar/furnitures/urls.py | 2 + ishtar/furnitures/views.py | 37 +++++++++++++++ ishtar/furnitures/widgets.py | 92 +++++++++++++++++++++++++++++++++++- ishtar/templates/base.html | 2 + ishtar/templates/default_wizard.html | 5 +- static/js/jquery.jqGrid.min.js | 26 +++++++++- static/media/style.css | 3 +- 8 files changed, 185 insertions(+), 5 deletions(-) (limited to 'static/media') diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 82bfcb88e..2725815b4 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -1066,15 +1066,36 @@ class OperationWizard(Wizard): + datas return datas +class OperationSelect(forms.Form): + town = forms.IntegerField(label=_(u"Town"), + widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \ + 'autocomplete-town', associated_model=models.Town), + validators=[models.valid_id(models.Town)]) + operation_type = forms.ChoiceField(label=_("Operation type"), + choices=models.OperationType.get_types()) + year = forms.IntegerField(label=_("Year")) + class OperationFormSelection(forms.Form): form_label = _("Operation") associated_models = {'pk':models.Operation} currents = {'pk':models.Operation} + pk = forms.IntegerField(label=_("Operation"), required=False, + widget=widgets.JQueryJqGrid(reverse_lazy('json-operation'), + OperationSelect(), ['operation_type', 'year']), + validators=[models.valid_id(models.Operation)]) + + def clean(self): + cleaned_data = self.cleaned_data + if 'pk' not in cleaned_data or not cleaned_data['pk']: + raise forms.ValidationError(_(u"You should select an operation.")) + return cleaned_data + + """ pk = forms.IntegerField(label=_("Operation"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-operation'), associated_model=models.Operation), validators=[models.valid_id(models.Operation)]) - +""" class OperationFormGeneral(forms.Form): form_label = _("General") diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index 08af1cd42..aafe0b3dd 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -71,6 +71,8 @@ urlpatterns += patterns('ishtar.furnitures.views', name='autocomplete-file'), url(BASE_URL + r'autocomplete-operation/$', 'autocomplete_operation', name='autocomplete-operation'), + url(BASE_URL + r'json-operation/$', 'json_operation', + name='json-operation'), url(BASE_URL + r'update-current-item/$', 'update_current_item', name='update-current-item'), ) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index c9ea7a0fd..811618449 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -141,6 +141,43 @@ def autocomplete_operation(request, non_closed=True): for operation in operations]) return HttpResponse(data, mimetype='text/plain') +def json_operation(request, non_closed=True): + if not request.GET: + return HttpResponse(mimetype='text/plain') + request_keys = {'town':'towns__pk', + 'operation_type':'operation_type__pk', + 'operation_code':'operation_code', + 'year':'year', + 'value':'name', + } + dct = {} + for k in request_keys: + q = request.GET.get(k) + if not q: + continue + dct[request_keys[k]] = q + if not dct: + return HttpResponse(mimetype='text/plain') + query = Q(**dct) + operations = models.Operation.objects.filter(query) + q = request.GET.get('sidx') + if q and q in request_keys: + k = request_keys[q] + if k.endswith("__pk"): + k = k[:-len("__pk")] + "__label" + q = request.GET.get('sord') + if q and q == u'desc': + k = "-" + k + operations.order_by(k) + data = json.dumps({ + "records":len(operations), + "rows":[{"id":unicode(operation.pk), + "cell":(unicode(operation.pk), unicode(operation), + unicode(operation.operation_type), unicode(operation.year))} + for operation in operations] + }) + return HttpResponse(data, mimetype='text/plain') + def autocomplete_organization(request, orga_type=None): if not request.GET.get('term'): return HttpResponse(mimetype='text/plain') diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index dc00f8676..b1d49f660 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -48,7 +48,6 @@ class JQueryDate(forms.TextInput): """ % (name, settings.COUNTRY) return rendered - class JQueryAutoComplete(forms.TextInput): def __init__(self, source, associated_model=None, options={}, attrs={}): """ @@ -121,3 +120,94 @@ objects.get(pk=value)) 'js' : self.render_js(name), } +class JQueryJqGrid(forms.RadioSelect): + COL_TPL = "{name:'%(idx)s', index:'%(idx)s', sortable:true}" + class Media: + js = ['%s/js/i18n/grid.locale-%s.js' % (settings.MEDIA_URL, + settings.COUNTRY), + '%s/js/jquery.jqGrid.min.js' % settings.MEDIA_URL, + ] + css = {'all':['%s/media/ui.jqgrid.css' % settings.MEDIA_URL]} + + def __init__(self, source, form, cols, attrs={}): + self.source = source + self.form = form + self.attrs = attrs + self.cols = cols + + def render(self, name, value=None, attrs=None): + rendered = unicode(self.form) + """ + for k in self.form.fields: + field = self.form.fields[k] + print unicode(field) + print field.label_tag + rendered += u"%s%s" % (field.label_tag, + unicode(field)) + """ + rendered += """ + + +""" % (name, unicode(_("Search"))) + extra_cols = [] + col_names, col_idx = [], [] + for k in self.form.fields: + field = self.form.fields[k] + col_idx.append(u'"%s"' % k) + if k in self.cols: + col_names.append(u'"%s"' % field.label) + extra_cols.append(self.COL_TPL % {'idx':k}) + col_names = col_names and ",".join([""]+col_names) or "" + col_idx = col_idx and ",".join(col_idx) or "" + extra_cols = extra_cols and ",".join([""]+extra_cols) or "" + rendered += """
+""" % (name, name, name) + rendered += """ + +""" % {'name':name, 'col_names':col_names, 'extra_cols':extra_cols, + 'name_label':unicode(_("Name")), 'source':unicode(self.source), + 'col_idx':col_idx} + return rendered + diff --git a/ishtar/templates/base.html b/ishtar/templates/base.html index e726cf782..22e6d4239 100644 --- a/ishtar/templates/base.html +++ b/ishtar/templates/base.html @@ -16,6 +16,8 @@ + {% block extra_head %} + {% endblock %} {% endblock %} diff --git a/static/js/jquery.jqGrid.min.js b/static/js/jquery.jqGrid.min.js index 5348e1ff0..e265989b5 100644 --- a/static/js/jquery.jqGrid.min.js +++ b/static/js/jquery.jqGrid.min.js @@ -5,7 +5,7 @@ * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl-2.0.html * Date:2010-12-14 -* Modules: grid.base.js; grid.custom.js; grid.postext.js; grid.jqueryui.js; +* Modules: grid.base.js; jquery.fmatter.js; grid.custom.js; grid.postext.js; grid.jqueryui.js; */ (function(b){b.jgrid=b.jgrid||{};b.extend(b.jgrid,{htmlDecode:function(f){if(f==" "||f==" "||f.length==1&&f.charCodeAt(0)==160)return"";return!f?f:String(f).replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<").replace(/"/g,'"')},htmlEncode:function(f){return!f?f:String(f).replace(/&/g,"&").replace(/>/g,">").replace(/])*>/gi;if(f)return(f=f.replace(j,""))&&f!==" "&&f!==" "?f.replace(/\"/g,"'"):"";else return f},stringToDoc:function(f){var j;if(typeof f!=="string")return f;try{j=(new DOMParser).parseFromString(f,"text/xml")}catch(i){j=new ActiveXObject("Microsoft.XMLDOM"); @@ -140,6 +140,30 @@ b(B).attr(e)}}})},getCell:function(f,j){var i=false;this.each(function(){var c=t this,a=-1;if(n.grid){if(isNaN(f))b(n.p.colModel).each(function(F){if(this.name===f){a=F;return false}});else a=parseInt(f,10);if(a>=0){var r=n.rows.length,t=0;if(r&&r>0){for(;t0){if(a<0){f+=e;a=f.length-1}else if(e!==".")f=f.replace(".",e);for(;f.length-1-a-1?a:f.length;e=f.substring(a);for(var g=-1,h=a;h>0;h--){g++;if(g%3===0&&h!==a&&(!d||h>1))e=i+e;e=f.charAt(h-1)+e}f=e}f=b.prefix?b.prefix+f:f;return f=b.suffix?f+b.suffix:f}else return a},DateFormat:function(a,b,d,f){var e=b.match(/^\/Date((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?)\/$/), +i=function(m,r){m=String(m);for(r=parseInt(r,10)||2;m.length11)b[e]=h+1-12}if(b[e])g[a[e].toLowerCase()]=parseInt(b[e],10)}if(g.f)g.m=g.f;if(g.m===0&&g.y===0&&g.d===0)return" ";g.m=parseInt(g.m,10)-1;h=g.y;if(h>=70&&h<=99)g.y=1900+g.y;else if(h>=0&&h<=69)g.y=2E3+g.y;h=new Date(g.y,g.m,g.d,g.h,g.i,g.s,g.u)}if(d in f.masks)d=f.masks[d];else d||(d="Y-m-d");g=h.getHours();a=h.getMinutes();b= +h.getDate();e=h.getMonth()+1;j=h.getTimezoneOffset();var l=h.getSeconds(),o=h.getMilliseconds(),n=h.getDay(),p=h.getFullYear(),q=(n+6)%7+1,s=(new Date(p,e-1,b)-new Date(p,0,1))/864E5,t={d:i(b),D:k.i18n.dayNames[n],j:b,l:k.i18n.dayNames[n+7],N:q,S:f.S(b),w:n,z:s,W:q<5?Math.floor((s+q-1)/7)+1:Math.floor((s+q-1)/7)||(((new Date(p-1,0,1)).getDay()+6)%7<4?53:52),F:k.i18n.monthNames[e-1+12],m:i(e),M:k.i18n.monthNames[e-1],n:e,t:"?",L:"?",o:"?",Y:p,y:String(p).substring(2),a:g<12?f.AmPm[0]:f.AmPm[1],A:g< +12?f.AmPm[2]:f.AmPm[3],B:"?",g:g%12||12,G:g,h:i(g%12||12),H:i(g),i:i(a),s:i(l),u:o,e:"?",I:"?",O:(j>0?"-":"+")+i(Math.floor(Math.abs(j)/60)*100+Math.abs(j)%60,4),P:"?",T:(String(h).match(/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g)||[""]).pop().replace(/[^-+\dA-Z]/g,""),Z:"?",c:"?",r:"?",U:Math.floor(h/1E3)};return d.replace(/\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,function(m){return m in t?t[m]:m.substring(1)})}}; +c.fn.fmatter.defaultFormat=function(a,b){return c.fmatter.isValue(a)&&a!==""?a:b.defaultValue?b.defaultValue:" "};c.fn.fmatter.email=function(a,b){return c.fmatter.isEmpty(a)?c.fn.fmatter.defaultFormat(a,b):''+a+""};c.fn.fmatter.checkbox=function(a,b){var d=c.extend({},b.checkbox);c.fmatter.isUndefined(b.colModel.formatoptions)||(d=c.extend({},d,b.colModel.formatoptions));b=d.disabled===true?'disabled="disabled"':"";if(c.fmatter.isEmpty(a)||c.fmatter.isUndefined(a))a= +c.fn.fmatter.defaultFormat(a,d);a+="";a=a.toLowerCase();return'"};c.fn.fmatter.link=function(a,b){var d={target:b.target},f="";c.fmatter.isUndefined(b.colModel.formatoptions)||(d=c.extend({},d,b.colModel.formatoptions));if(d.target)f="target="+d.target;return c.fmatter.isEmpty(a)?c.fn.fmatter.defaultFormat(a,b):"'+a+""};c.fn.fmatter.showlink=function(a,b){var d= +{baseLinkUrl:b.baseLinkUrl,showAction:b.showAction,addParam:b.addParam||"",target:b.target,idName:b.idName},f="";c.fmatter.isUndefined(b.colModel.formatoptions)||(d=c.extend({},d,b.colModel.formatoptions));if(d.target)f="target="+d.target;d=d.baseLinkUrl+d.showAction+"?"+d.idName+"="+b.rowId+d.addParam;return c.fmatter.isString(a)||c.fmatter.isNumber(a)?"'+a+"":c.fn.fmatter.defaultFormat(a,b)};c.fn.fmatter.integer=function(a,b){var d=c.extend({},b.integer);c.fmatter.isUndefined(b.colModel.formatoptions)|| +(d=c.extend({},d,b.colModel.formatoptions));if(c.fmatter.isEmpty(a))return d.defaultValue;return c.fmatter.util.NumberFormat(a,d)};c.fn.fmatter.number=function(a,b){var d=c.extend({},b.number);c.fmatter.isUndefined(b.colModel.formatoptions)||(d=c.extend({},d,b.colModel.formatoptions));if(c.fmatter.isEmpty(a))return d.defaultValue;return c.fmatter.util.NumberFormat(a,d)};c.fn.fmatter.currency=function(a,b){var d=c.extend({},b.currency);c.fmatter.isUndefined(b.colModel.formatoptions)||(d=c.extend({}, +d,b.colModel.formatoptions));if(c.fmatter.isEmpty(a))return d.defaultValue;return c.fmatter.util.NumberFormat(a,d)};c.fn.fmatter.date=function(a,b,d,f){d=c.extend({},b.date);c.fmatter.isUndefined(b.colModel.formatoptions)||(d=c.extend({},d,b.colModel.formatoptions));return!d.reformatAfterEdit&&f=="edit"?c.fn.fmatter.defaultFormat(a,b):c.fmatter.isEmpty(a)?c.fn.fmatter.defaultFormat(a,b):c.fmatter.util.DateFormat(d.srcformat,a,d.newformat,d)};c.fn.fmatter.select=function(a,b){a+="";var d=false,f=[]; +if(c.fmatter.isUndefined(b.colModel.formatoptions)){if(!c.fmatter.isUndefined(b.colModel.editoptions))d=b.colModel.editoptions.value}else d=b.colModel.formatoptions.value;if(d){var e=b.colModel.editoptions.multiple===true?true:false,i=[],g;if(e){i=a.split(",");i=c.map(i,function(l){return c.trim(l)})}if(c.fmatter.isString(d))for(var h=d.split(";"),j=0,k=0;k2)g[1]=jQuery.map(g,function(l,o){if(o>0)return l}).join(":");if(e){if(jQuery.inArray(g[0],i)>-1){f[j]= +g[1];j++}}else if(c.trim(g[0])==c.trim(a)){f[0]=g[1];break}}else if(c.fmatter.isObject(d))if(e)f=jQuery.map(i,function(l){return d[l]});else f[0]=d[a]||""}a=f.join(", ");return a===""?c.fn.fmatter.defaultFormat(a,b):a};c.fn.fmatter.rowactions=function(a,b,d,f){var e={keys:false,editbutton:true,delbutton:true,onEdit:null,onSuccess:null,afterSave:null,onError:null,afterRestore:null,extraparam:{oper:"edit"},url:null,delOptions:{}};f=c("#"+b)[0].p.colModel[f];c.fmatter.isUndefined(f.formatoptions)||(e= +c.extend(e,f.formatoptions));f=function(g){e.afterSave&&e.afterSave(g);c("tr#"+a+" div.ui-inline-edit, tr#"+a+" div.ui-inline-del","#"+b).show();c("tr#"+a+" div.ui-inline-save, tr#"+a+" div.ui-inline-cancel","#"+b).hide()};var i=function(g){e.afterRestore&&e.afterRestore(g);c("tr#"+a+" div.ui-inline-edit, tr#"+a+" div.ui-inline-del","#"+b).show();c("tr#"+a+" div.ui-inline-save, tr#"+a+" div.ui-inline-cancel","#"+b).hide()};switch(d){case "edit":c("#"+b).jqGrid("editRow",a,e.keys,e.onEdit,e.onSuccess, +e.url,e.extraparam,f,e.onError,i);c("tr#"+a+" div.ui-inline-edit, tr#"+a+" div.ui-inline-del","#"+b).hide();c("tr#"+a+" div.ui-inline-save, tr#"+a+" div.ui-inline-cancel","#"+b).show();break;case "save":c("#"+b).jqGrid("saveRow",a,e.onSuccess,e.url,e.extraparam,f,e.onError,i);c("tr#"+a+" div.ui-inline-edit, tr#"+a+" div.ui-inline-del","#"+b).show();c("tr#"+a+" div.ui-inline-save, tr#"+a+" div.ui-inline-cancel","#"+b).hide();break;case "cancel":c("#"+b).jqGrid("restoreRow",a,i);c("tr#"+a+" div.ui-inline-edit, tr#"+ +a+" div.ui-inline-del","#"+b).show();c("tr#"+a+" div.ui-inline-save, tr#"+a+" div.ui-inline-cancel","#"+b).hide();break;case "del":c("#"+b).jqGrid("delGridRow",a,e.delOptions);break}};c.fn.fmatter.actions=function(a,b){a={keys:false,editbutton:true,delbutton:true};c.fmatter.isUndefined(b.colModel.formatoptions)||(a=c.extend(a,b.colModel.formatoptions));var d=b.rowId,f="",e;if(typeof d=="undefined"||c.fmatter.isEmpty(d))return"";if(a.editbutton){e="onclick=$.fn.fmatter.rowactions('"+d+"','"+b.gid+ +"','edit',"+b.pos+");";f=f+"
"}if(a.delbutton){e="onclick=$.fn.fmatter.rowactions('"+d+"','"+b.gid+"','del',"+b.pos+");";f=f+"
"}e="onclick=$.fn.fmatter.rowactions('"+ +d+"','"+b.gid+"','save',"+b.pos+");";f=f+"";e="onclick=$.fn.fmatter.rowactions('"+d+"','"+b.gid+"','cancel',"+b.pos+");";return f=f+"
"};c.unformat=function(a,b, +d,f){var e,i=b.colModel.formatter,g=b.colModel.formatoptions||{},h=/([\.\*\_\'\(\)\{\}\+\?\\])/g,j=b.colModel.unformat||c.fn.fmatter[i]&&c.fn.fmatter[i].unformat;if(typeof j!=="undefined"&&c.isFunction(j))e=j(c(a).text(),b,a);else if(!c.fmatter.isUndefined(i)&&c.fmatter.isString(i)){e=c.jgrid.formatter||{};switch(i){case "integer":g=c.extend({},e.integer,g);b=g.thousandsSeparator.replace(h,"\\$1");b=new RegExp(b,"g");e=c(a).text().replace(b,"");break;case "number":g=c.extend({},e.number,g);b=g.thousandsSeparator.replace(h, +"\\$1");b=new RegExp(b,"g");e=c(a).text().replace(b,"").replace(g.decimalSeparator,".");break;case "currency":g=c.extend({},e.currency,g);b=g.thousandsSeparator.replace(h,"\\$1");b=new RegExp(b,"g");e=c(a).text().replace(b,"").replace(g.decimalSeparator,".").replace(g.prefix,"").replace(g.suffix,"");break;case "checkbox":g=b.colModel.editoptions?b.colModel.editoptions.value.split(":"):["Yes","No"];e=c("input",a).attr("checked")?g[0]:g[1];break;case "select":e=c.unformat.select(a,b,d,f);break;case "actions":return""; +default:e=c(a).text()}}return e?e:f===true?c(a).text():c.jgrid.htmlDecode(c(a).html())};c.unformat.select=function(a,b,d,f){d=[];a=c(a).text();if(f===true)return a;b=c.extend({},b.colModel.editoptions);if(b.value){var e=b.value;b=b.multiple===true?true:false;f=[];var i;if(b){f=a.split(",");f=c.map(f,function(k){return c.trim(k)})}if(c.fmatter.isString(e))for(var g=e.split(";"),h=0,j=0;j2)i[1]=jQuery.map(i,function(k,l){if(l>0)return k}).join(":");if(b){if(jQuery.inArray(i[1], +f)>-1){d[h]=i[0];h++}}else if(c.trim(i[1])==c.trim(a)){d[0]=i[0];break}}else if(c.fmatter.isObject(e)||c.isArray(e)){b||(f[0]=a);d=jQuery.map(f,function(k){var l;c.each(e,function(o,n){if(n==k){l=o;return false}});if(typeof l!="undefined")return l})}return d.join(", ")}else return a||""};c.unformat.date=function(a,b){var d=c.jgrid.formatter.date||{};c.fmatter.isUndefined(b.formatoptions)||(d=c.extend({},d,b.formatoptions));return c.fmatter.isEmpty(a)?c.fn.fmatter.defaultFormat(a,b):c.fmatter.util.DateFormat(d.newformat, +a,d.srcformat,d)}})(jQuery); (function(a){a.jgrid.extend({getColProp:function(f){var d={},b=this[0];if(!b.grid)return false;b=b.p.colModel;for(var m=0;m Date: Fri, 28 Jan 2011 17:05:14 +0100 Subject: Manage ordering - default item - save last search in session (refs #142) --- ishtar/furnitures/forms.py | 2 +- ishtar/furnitures/views.py | 19 +++++++++++++++---- ishtar/furnitures/widgets.py | 19 +++++++++++++------ static/media/style.css | 4 ++++ 4 files changed, 33 insertions(+), 11 deletions(-) (limited to 'static/media') diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 2725815b4..a7f31999e 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -1079,7 +1079,7 @@ class OperationFormSelection(forms.Form): form_label = _("Operation") associated_models = {'pk':models.Operation} currents = {'pk':models.Operation} - pk = forms.IntegerField(label=_("Operation"), required=False, + pk = forms.IntegerField(label="", required=False, widget=widgets.JQueryJqGrid(reverse_lazy('json-operation'), OperationSelect(), ['operation_type', 'year']), validators=[models.valid_id(models.Operation)]) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 811618449..b266bed63 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -157,7 +157,14 @@ def json_operation(request, non_closed=True): continue dct[request_keys[k]] = q if not dct: - return HttpResponse(mimetype='text/plain') + if 'json_operation' in request.session: + dct = request.session['json_operation'] + elif 'operation' in request.session: + dct = {"pk":request.session['operation']} + if not dct: + return HttpResponse(mimetype='text/plain') + else: + request.session['json_operation'] = dct query = Q(**dct) operations = models.Operation.objects.filter(query) q = request.GET.get('sidx') @@ -166,9 +173,13 @@ def json_operation(request, non_closed=True): if k.endswith("__pk"): k = k[:-len("__pk")] + "__label" q = request.GET.get('sord') - if q and q == u'desc': - k = "-" + k - operations.order_by(k) + sign = q and q == u'desc' and "-" or '' + if k == "name": + k = "operation_code" + operations = operations.order_by(sign + 'year').order_by( + sign + 'operation_code') + else: + operations = operations.order_by(sign + k) data = json.dumps({ "records":len(operations), "rows":[{"id":unicode(operation.pk), diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index b1d49f660..af22c7b3e 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -148,7 +148,8 @@ class JQueryJqGrid(forms.RadioSelect): rendered += """ -""" % (name, unicode(_("Search"))) +

%s

+""" % (name, unicode(_("Search")), unicode(_("Search and select an item"))) extra_cols = [] col_names, col_idx = [], [] for k in self.form.fields: @@ -160,8 +161,9 @@ class JQueryJqGrid(forms.RadioSelect): col_names = col_names and ",".join([""]+col_names) or "" col_idx = col_idx and ",".join(col_idx) or "" extra_cols = extra_cols and ",".join([""]+extra_cols) or "" - rendered += """
-""" % (name, name, name) + rendered += """
+
+""" % (name, name, name, name) rendered += """ """ % {'name':name, 'col_names':col_names, 'extra_cols':extra_cols, 'name_label':unicode(_("Name")), 'source':unicode(self.source), - 'col_idx':col_idx} + 'col_idx':col_idx, 'no_result':unicode(_("No results")), + 'loading':unicode(_("Loading..."))} return rendered diff --git a/static/media/style.css b/static/media/style.css index b9cfc18f6..25616ac69 100644 --- a/static/media/style.css +++ b/static/media/style.css @@ -224,3 +224,7 @@ div.form .errorlist{ table.confirm tr.spacer td:last-child{ border-bottom:1px solid #922; } + +.jqgrid{ + cursor:pointer; +} -- cgit v1.2.3