summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/static/media/style.css14
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_tables/documents.html2
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html37
-rw-r--r--ishtar_common/templatetags/table_form.py1
-rw-r--r--ishtar_common/templatetags/window_tables.py46
-rw-r--r--ishtar_common/widgets.py35
6 files changed, 115 insertions, 20 deletions
diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css
index a00fce2cf..babdae9f7 100644
--- a/ishtar_common/static/media/style.css
+++ b/ishtar_common/static/media/style.css
@@ -90,7 +90,7 @@ a {
text-decoration:none;
}
-caption, h2, h3 {
+caption, h2, h3, #window h4 {
color:#922;
font-weight:bold;
}
@@ -105,6 +105,10 @@ h3{
margin:1em 0 0.5em 0;
}
+#window h4 {
+ text-align: center;
+}
+
h4{
margin:10px 0;
}
@@ -703,7 +707,7 @@ table.confirm tr.spacer td:last-child{
overflow:auto;
}
-#window table, .dashboard table.resume{
+#window table.simple, .dashboard table.resume{
font-size:0.9em;
margin:10px 0;
border-collapse:collapse;
@@ -727,13 +731,13 @@ table.confirm tr.spacer td:last-child{
margin-top:1em;
}
-#window table th, .dashboard table.resume th{
+#window table.simple th, .dashboard table.resume th{
background-color:#922;
border:1px solid #f1f2f6;
color:#FFF;
}
-#window table th{
+#window table.simple th{
text-align:center;
}
@@ -759,7 +763,7 @@ table.confirm tr.spacer td:last-child{
text-align:left;
}
-#window table td, .dashboard table.resume td{
+#window table.simple td, .dashboard table.resume td{
text-align:right;
padding:0 1em;
border:1px solid #f1f2f6;
diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/documents.html
index 9405bc3e8..f1592cc42 100644
--- a/ishtar_common/templates/ishtar/blocks/window_tables/documents.html
+++ b/ishtar_common/templates/ishtar/blocks/window_tables/documents.html
@@ -1,5 +1,5 @@
{% load i18n %}
-<table>
+<table class='simple'>
<caption>{{caption}}</caption>
<tr>
<th>{% trans "Title" %}</th>
diff --git a/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html
new file mode 100644
index 000000000..bd83983f4
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html
@@ -0,0 +1,37 @@
+{% load i18n %}
+
+<h4>{{caption}}</h4>
+<table id='grid_{{name}}' class='jqgrid'></table>
+<div id='pager_{{name}}'></div>
+
+<script type="text/javascript" language='javascript'>
+
+setTimeout(
+ function(){
+ jQuery("#grid_{{name}}").jqGrid({
+ url:'{{source}}',
+ datatype: "json",
+ mtype: 'GET',
+ colNames:['id', '', {{col_names|safe}}],
+ colModel:[
+ {name:'id', index:'id', hidden:true},
+ {name:'link', index:'link', width:30},
+ {{extra_cols|safe}}
+ ],
+ sortname: 'value',
+ viewrecords: true,
+ sortorder: "asc",
+ emptyrecords: "{{no_result}}",
+ loadtext: "{{loading}}",
+ pager: '#pager_{{name}}',
+ width:720,
+ rowNum:20,
+ jsonReader : {repeatitems: false},
+ loadError: function (jqXHR, textStatus, errorThrown) {
+ alert("{% trans "An error as occured during search. Check your query fields." %}");
+ }
+ });
+}, 200);
+
+</script>
+
diff --git a/ishtar_common/templatetags/table_form.py b/ishtar_common/templatetags/table_form.py
index 0ab49d93f..6ee99b9a5 100644
--- a/ishtar_common/templatetags/table_form.py
+++ b/ishtar_common/templatetags/table_form.py
@@ -5,6 +5,7 @@ from django.template import Library
register = Library()
+
@register.inclusion_tag('blocks/form_snippet.html')
def table_form(form):
return {'form': form}
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
index 5eebf6359..a135ad5c0 100644
--- a/ishtar_common/templatetags/window_tables.py
+++ b/ishtar_common/templatetags/window_tables.py
@@ -1,4 +1,11 @@
+import time
+
from django import template
+from django.template.defaultfilters import slugify
+from django.utils.translation import ugettext_lazy as _
+
+from ishtar_common.forms import reverse_lazy
+from ishtar_common.widgets import JQueryJqGrid
register = template.Library()
@@ -6,3 +13,42 @@ register = template.Library()
@register.inclusion_tag('ishtar/blocks/window_tables/documents.html')
def table_document(caption, data):
return {'caption': caption, 'data': data}
+
+ASSOCIATED_MODELS = {}
+try:
+ from archaeological_operations.models import OperationSource
+ ASSOCIATED_MODELS['operation_docs'] = (OperationSource,
+ 'get-operationsource')
+except:
+ pass
+
+try:
+ from archaeological_context_records.models import ContextRecord, \
+ ContextRecordSource
+ ASSOCIATED_MODELS['context_records'] = (ContextRecord, 'get-contextrecord')
+ ASSOCIATED_MODELS['context_records_docs'] = (ContextRecordSource,
+ 'get-contextrecordsource')
+except:
+ pass
+
+try:
+ from archaeological_finds.models import Find
+ ASSOCIATED_MODELS['finds'] = (Find, 'get-find')
+except:
+ pass
+
+
+@register.inclusion_tag('ishtar/blocks/window_tables/dynamic_documents.html')
+def dynamic_table_document(caption, associated_model, key, value):
+ model, url = ASSOCIATED_MODELS[associated_model]
+ grid = JQueryJqGrid(None, None, model)
+
+ col_names, extra_cols = grid.get_cols()
+ return {'caption': caption,
+ 'name': slugify(caption) + '{}'.format(int(time.time())),
+ 'source': unicode(reverse_lazy(url)) + '?{}={}'.format(key, value),
+ 'col_names': col_names,
+ 'extra_cols': extra_cols,
+ 'no_result': unicode(_("No results")),
+ 'loading': unicode(_("Loading...")),
+ }
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index 9bffe4ec5..66380db8b 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -524,19 +524,8 @@ class JQueryJqGrid(forms.RadioSelect):
self.new, self.new_message = new, new_message
self.source_full = source_full
- def render(self, name, value=None, attrs=None):
- t = loader.get_template('blocks/form_snippet.html')
- form = self.form()
- rendered = t.render(Context({'form': form}))
- dct = {}
- if self.new:
- model_name = self.associated_model._meta.object_name.lower()
- dct['url_new'] = reverse('new-' + model_name, args=['0'])
- dct['new_message'] = self.new_message
- extra_cols = []
- col_names, col_idx = [], []
- for k in form.get_input_ids():
- col_idx.append(u'"%s"' % k)
+ def get_cols(self):
+ col_names, extra_cols = [], []
for field_name in getattr(self.associated_model, self.table_cols):
field = self.associated_model
keys = field_name.split('.')
@@ -557,8 +546,26 @@ class JQueryJqGrid(forms.RadioSelect):
col_names.append(u'"%s"' % field_verbose_name)
extra_cols.append(self.COL_TPL % {'idx': field_name})
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 ""
+ return col_names, extra_cols
+
+ def render(self, name, value=None, attrs=None):
+ t = loader.get_template('blocks/form_snippet.html')
+ form = self.form()
+ rendered = t.render(Context({'form': form}))
+ dct = {}
+ if self.new:
+ model_name = self.associated_model._meta.object_name.lower()
+ dct['url_new'] = reverse('new-' + model_name, args=['0'])
+ dct['new_message'] = self.new_message
+
+ col_names, extra_cols = self.get_cols()
+
+ col_idx = []
+ for k in form.get_input_ids():
+ col_idx.append(u'"%s"' % k)
+ col_idx = col_idx and ", ".join(col_idx) or ""
+
dct['encoding'] = settings.ENCODING or 'utf-8'
dct['source'] = unicode(self.source)
if unicode(self.source_full) and unicode(self.source_full) != 'None':