summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-30 14:04:52 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-30 14:04:52 +0200
commitd66686f332337211929ddb505eeab8eff42cd4e4 (patch)
tree46147e5d07fb8c3d2587c1bc7faf2e0e63e529aa
parent04911d3534c2ee903ddaf4b831c42e70c3d28986 (diff)
downloadIshtar-d66686f332337211929ddb505eeab8eff42cd4e4.tar.bz2
Ishtar-d66686f332337211929ddb505eeab8eff42cd4e4.zip
Manage many to one treatment (refs #499)
-rw-r--r--ishtar/ishtar_base/forms_items.py20
-rw-r--r--ishtar/ishtar_base/models.py17
-rw-r--r--ishtar/ishtar_base/widgets.py28
-rw-r--r--static/js/ishtar.js2
-rw-r--r--static/media/style.css14
5 files changed, 63 insertions, 18 deletions
diff --git a/ishtar/ishtar_base/forms_items.py b/ishtar/ishtar_base/forms_items.py
index 7e3047741..484902341 100644
--- a/ishtar/ishtar_base/forms_items.py
+++ b/ishtar/ishtar_base/forms_items.py
@@ -206,10 +206,10 @@ class BaseTreatmentForm(forms.Form):
class ItemMultipleFormSelection(forms.Form):
form_label = _(u"Upstream items")
associated_models = {'items':models.Item}
- items = forms.IntegerField(label="", required=False,
+ items = forms.CharField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-item'),
- ItemSelect(), models.Item, multiple=True),
- validators=[models.valid_id(models.Item)])
+ ItemSelect(), models.Item, multiple=True, multiple_cols=[2, 3, 4]),
+ validators=[models.valid_ids(models.Item)])
class ContainerForm(forms.Form):
form_label = _(u"Container")
@@ -272,10 +272,10 @@ treatment_creation_wizard = TreatmentWizard([
condition_list={
'selecitem-treatment_creation':
check_treatment('basetreatment-treatment_creation', 'treatment_type',
- not_type_list=['physical_grouping']),
+ not_type_list=['physical_grouping', 'packaging']),
'multiselecitems-treatment_creation':
check_treatment('basetreatment-treatment_creation', 'treatment_type',
- ['physical_grouping']),
+ ['physical_grouping', 'packaging']),
'resultitems-treatment_creation':
check_treatment('basetreatment-treatment_creation', 'treatment_type',
['split']),
@@ -288,6 +288,16 @@ treatment_creation_wizard = TreatmentWizard([
},
url_name='treatment_creation',)
+########################
+# Warehouse management #
+########################
+
+"""
+warehouse_packaging_wizard = ItemSourceWizard([
+ ('selec-warehouse_packaging', ItemsSelection),
+ ('final-warehouse_packaging', FinalForm)],
+ url_name='warehouse_packaging',)
+"""
#############################################
# Source management for archaelogical items #
#############################################
diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py
index 0f3cb8a8b..37af19f87 100644
--- a/ishtar/ishtar_base/models.py
+++ b/ishtar/ishtar_base/models.py
@@ -66,6 +66,17 @@ def valid_id(cls):
raise ValidationError(_(u"Not a valid item."))
return func
+def valid_ids(cls):
+ def func(value):
+ if "," in value:
+ value = value.split(",")
+ for v in value:
+ try:
+ cls.objects.get(pk=v)
+ except ObjectDoesNotExist:
+ raise ValidationError(_(u"Not a valid item."))
+ return func
+
# unique validator for models
def is_unique(cls, field):
def func(value):
@@ -945,13 +956,13 @@ class BaseItem(BaseHistorizedItem, OwnPerms):
self.context_record.label,
self.label)])
class Item(BaseHistorizedItem, OwnPerms):
- TABLE_COLS = ['base_items.context_record.parcel.town',
+ TABLE_COLS = ['label', 'material_type', 'dating.period',
+ 'base_items.context_record.parcel.town',
'base_items.context_record.parcel.operation.year',
'base_items.context_record.parcel.operation.operation_code',
- 'label', 'material_type', 'dating.period',
'base_items.is_isolated']
if settings.COUNTRY == 'fr':
- TABLE_COLS.insert(1,
+ TABLE_COLS.insert(6,
'base_items.context_record.parcel.operation.code_patriarche')
base_items = models.ManyToManyField(BaseItem, verbose_name=_(u"Base item"),
related_name='item')
diff --git a/ishtar/ishtar_base/widgets.py b/ishtar/ishtar_base/widgets.py
index e058f7074..cb257325c 100644
--- a/ishtar/ishtar_base/widgets.py
+++ b/ishtar/ishtar_base/widgets.py
@@ -205,13 +205,14 @@ class JQueryJqGrid(forms.RadioSelect):
]}
def __init__(self, source, form, associated_model, attrs={},
- table_cols='TABLE_COLS', multiple=False):
+ table_cols='TABLE_COLS', multiple=False, multiple_cols=[2]):
self.source = source
self.form = form
self.attrs = attrs
self.associated_model = associated_model
self.table_cols = table_cols
self.multiple = multiple
+ self.multiple_cols = multiple_cols
def render(self, name, value=None, attrs=None):
t = loader.get_template('form_snippet.html')
@@ -259,11 +260,12 @@ class JQueryJqGrid(forms.RadioSelect):
dct = {'name':name, 'col_names':col_names, 'extra_cols':extra_cols,
'source':unicode(self.source), 'col_idx':col_idx,
'no_result':unicode(_("No results")), 'loading':unicode(_("Loading...")),
- 'remove':unicode(_("Remove")), 'sname':name.replace('-', '')}
-
+ 'remove':unicode(_(u"Remove")), 'sname':name.replace('-', ''),
+ 'multi_cols': ",".join((u'"%d"' % col for col in self.multiple_cols))}
rendered += """
<script type="text/javascript">
var query_vars = new Array(%(col_idx)s);
+var selItems_%(sname)s = new Array();
jQuery(document).ready(function(){
jQuery("#search_%(name)s").click(function (){
var data = "";
@@ -307,11 +309,22 @@ jQuery(document).ready(function(){
""" % dct
if self.multiple:
rendered += """
- var selItems_%(sname)s = new Array();
jQuery("#add_button_%(name)s").click(function (){
var mygrid = jQuery("#grid_%(name)s");
var idx = mygrid.getGridParam('selrow');
- var label = mygrid.getCell(idx, 2);
+ var lbl_cols = new Array(%(multi_cols)s);
+ var label = "";
+ for (var id in lbl_cols){
+ if(id == 1){
+ label += " (";
+ }else if (id > 1){
+ label += " ; ";
+ }
+ label += mygrid.getCell(idx, lbl_cols[id]);
+ }
+ if (id > 0){
+ label += ")";
+ }
for (id in selItems_%(sname)s){
if(selItems_%(sname)s[id] == idx){
return false;
@@ -319,7 +332,10 @@ jQuery(document).ready(function(){
}
selItems_%(sname)s.push(idx);
jQuery("#selectmulti_%(name)s").append(
- "<li id='selected_%(name)s_"+idx+"'>"+label+" <a href='#' class='remove' onclick=\\"multiRemoveItem('selItems_%(sname)s', '%(name)s', "+ idx +");return false;\\">%(remove)s</a></li>");
+ "<li id='selected_%(name)s_"+idx+"'>\
+<a href='#' class='remove' \
+ onclick=\\"multiRemoveItem(selItems_%(sname)s, '%(name)s', "+ idx +");\
+ return false;\\" title=\\"%(remove)s\\">X</a>" + label + "</li>");
return true;
});
jQuery("#submit_form").click(function (){
diff --git a/static/js/ishtar.js b/static/js/ishtar.js
index 26fbbd950..25fc3c66a 100644
--- a/static/js/ishtar.js
+++ b/static/js/ishtar.js
@@ -94,7 +94,7 @@ function save_and_close_window(name_label, name_pk, item_name, item_pk){
function multiRemoveItem(selItems, name, idx){
for(id in selItems){
if(selItems[id] == idx){
- selItems.pop(id);
+ selItems.splice(id, 1);
}
}
jQuery("#selected_"+name+"_"+idx).remove();
diff --git a/static/media/style.css b/static/media/style.css
index 82c895080..fb7248e84 100644
--- a/static/media/style.css
+++ b/static/media/style.css
@@ -416,17 +416,19 @@ table.confirm tr.spacer td:last-child{
ul.selectmulti{
list-style-type:none;
+ text-align:left;
+ margin-left:100px;
}
-ul.selectmulti li a.remove{
- padding-left:100px;
+ul.selectmulti li{
+ margin:6px 0;
}
td.submit_button{
text-align:center;
}
-a.add-button{
+a.add-button, a.remove{
background-color:#FFF;
border:2px solid #CCC;
-moz-border-radius:8px;
@@ -435,3 +437,9 @@ a.add-button{
padding:0 4px;
color:#61615C;
}
+
+a.remove{
+ color:#D14;
+ margin:0 6px;
+}
+