@@ -8,14 +8,83 @@ cur_frm.cscript.doc_type = function(doc, dt, dn) { | |||||
}); | }); | ||||
} | } | ||||
cur_frm.cscript.onload = function(doc, dt, dn) { | |||||
cur_frm.grids[0].grid.tbar_div.style.width = "30%"; | |||||
p = cur_frm.grids[0].grid.tbar_tab.children[0].children[0]; | |||||
p.removeChild(p.children[0]) | |||||
p.removeChild(p.children[0]) | |||||
} | |||||
cur_frm.cscript.refresh = function(doc, dt, dn) { | cur_frm.cscript.refresh = function(doc, dt, dn) { | ||||
//console.log(p) | |||||
cur_frm.frm_head.timestamp_area.hidden = 1; | |||||
cur_frm.frm_head.page_head.buttons.Save.hidden=1; | cur_frm.frm_head.page_head.buttons.Save.hidden=1; | ||||
cur_frm.page_layout.footer.hidden = 1; | cur_frm.page_layout.footer.hidden = 1; | ||||
cur_frm.add_custom_button('Update', function() { | cur_frm.add_custom_button('Update', function() { | ||||
if(cur_frm.fields_dict['doc_type'].value) { | if(cur_frm.fields_dict['doc_type'].value) { | ||||
$c_obj(make_doclist(dt, dn), 'post', '', function(r, rt) { | $c_obj(make_doclist(dt, dn), 'post', '', function(r, rt) { | ||||
console.log(arguments); | |||||
if(r.exc) { | |||||
msgprint(r.exc); | |||||
} else { | |||||
cur_frm.frm_head.status_area.innerHTML = | |||||
'<span style="padding: 2px; background-color: rgb(0, 170, 17); \ | |||||
color: rgb(255, 255, 255); font-weight: bold; margin-left: 0px; \ | |||||
font-size: 11px;">Saved</span>' | |||||
console.log(arguments); | |||||
} | |||||
}); | }); | ||||
} | } | ||||
},1); | },1); | ||||
cur_frm.frm_head.page_head.buttons.Update.className = "cupid-green"; | |||||
cur_frm.add_custom_button('Reload', function() { | |||||
cur_frm.cscript.doc_type(doc, dt, dn); | |||||
}, 1); | |||||
cur_frm.add_custom_button('Reset to defaults', function() { | |||||
cur_frm.confirm('This will remove the customizations defined for this form.\n\n' | |||||
+ 'Are you sure you want to reset to defaults?'); | |||||
}, 1); | |||||
} | |||||
cur_frm.confirm = function(msg) { | |||||
var d = new wn.widgets.Dialog({ | |||||
title: 'Reset To Defaults', | |||||
width: 300, | |||||
fields: [ | |||||
{ | |||||
fieldtype: 'HTML', | |||||
label: 'Please Confirm', | |||||
fieldname: 'msg' | |||||
}, | |||||
{ | |||||
fieldtype: 'Button', | |||||
label: 'Proceed', | |||||
fieldname: 'btn_proceed' | |||||
}, | |||||
{ | |||||
fieldtype: 'Button', | |||||
label: 'Cancel', | |||||
fieldname: 'btn_cancel' | |||||
} | |||||
] | |||||
}); | |||||
//d.set_value('msg', msg); | |||||
d.fields_dict.btn_proceed.input.onclick = function() { | |||||
this.set_working(); | |||||
$c_obj(make_doclist(dt, dn), 'delete', '', function(r, rt) { | |||||
if(r.exc) { | |||||
msgprint(r.exc); | |||||
} else { | |||||
console.log(arguments); | |||||
} | |||||
}); | |||||
this.done_working(); | |||||
cur_frm.confirm_dialog.hide(); | |||||
} | |||||
d.fields_dict.btn_cancel.input.onclick = function() { | |||||
cur_frm.confirm.dialog.hide(); | |||||
} | |||||
cur_frm.confirm.dialog = d; | |||||
} | } |
@@ -129,17 +129,17 @@ class DocType: | |||||
# get a list of property setter docs | # get a list of property setter docs | ||||
diff_list = self.diff(this_doclist, ref_doclist, dt_doclist) | diff_list = self.diff(this_doclist, ref_doclist, dt_doclist) | ||||
webnotes.msgprint('this doc') | |||||
webnotes.msgprint([[d.name, d.idx, 'label' in d.fields and d.label or None] for d in this_doclist]) | |||||
webnotes.msgprint('ref doc') | |||||
webnotes.msgprint([[d.name, d.idx, 'label' in d.fields and d.label or None] for d in ref_doclist]) | |||||
webnotes.msgprint('def doc') | |||||
webnotes.msgprint([[d.name, d.idx, 'label' in d.fields and d.label or None] for d in dt_doclist]) | |||||
self.set_properties(diff_list) | self.set_properties(diff_list) | ||||
webnotes.msgprint('End of Post') | |||||
webnotes.msgprint([[d.fields['property'], d.fields['value'], d.fields['doc_name'], d.fields['select_item'], 'delete' in d.fields and d.fields['delete'] or None] for d in diff_list]) | |||||
#webnotes.msgprint('End of Post') | |||||
#webnotes.msgprint('this doc') | |||||
#webnotes.msgprint([[d.name, d.idx, 'label' in d.fields and d.label or None] for d in this_doclist]) | |||||
#webnotes.msgprint('ref doc') | |||||
#webnotes.msgprint([[d.name, d.idx, 'label' in d.fields and d.label or None] for d in ref_doclist]) | |||||
#webnotes.msgprint('def doc') | |||||
#webnotes.msgprint([[d.name, d.idx, 'label' in d.fields and d.label or None] for d in dt_doclist]) | |||||
#webnotes.msgprint([[d.fields['property'], d.fields['value'], d.fields['doc_name'], d.fields['select_item'], 'delete' in d.fields and d.fields['delete'] or None] for d in diff_list]) | |||||
def diff(self, new_dl, ref_dl, dt_dl): | def diff(self, new_dl, ref_dl, dt_dl): | ||||
@@ -178,11 +178,9 @@ class DocType: | |||||
defaults = {} | defaults = {} | ||||
for d in df_defaults: | for d in df_defaults: | ||||
fieldname = d['fieldname'] | |||||
del d['fieldname'] | |||||
defaults[fieldname] = d | |||||
defaults['idx'] = {'fieldtype' : 'Int', 'default' : 1, 'label' : 'idx'} | |||||
defaults['previous_field'] = {'fieldtype' : 'Data', 'default' : None, 'label' : 'Previous Field'} | |||||
defaults[d['fieldname']] = d | |||||
defaults['idx'] = {'fieldname' : 'idx', 'fieldtype' : 'Int', 'default' : 1, 'label' : 'idx'} | |||||
defaults['previous_field'] = {'fieldname' : 'previous_field', 'fieldtype' : 'Data', 'default' : None, 'label' : 'Previous Field'} | |||||
return defaults | return defaults | ||||
@@ -5,7 +5,7 @@ | |||||
{ | { | ||||
'creation': '2011-11-16 16:45:16', | 'creation': '2011-11-16 16:45:16', | ||||
'docstatus': 0, | 'docstatus': 0, | ||||
'modified': '2011-11-17 14:28:16', | |||||
'modified': '2011-11-22 16:09:21', | |||||
'modified_by': 'Administrator', | 'modified_by': 'Administrator', | ||||
'owner': 'Administrator' | 'owner': 'Administrator' | ||||
}, | }, | ||||
@@ -27,7 +27,7 @@ | |||||
'read_only': 0, | 'read_only': 0, | ||||
'section_style': 'Simple', | 'section_style': 'Simple', | ||||
'show_in_menu': 0, | 'show_in_menu': 0, | ||||
'version': 2 | |||||
'version': 3 | |||||
}, | }, | ||||
# These values are common for all DocField | # These values are common for all DocField | ||||
@@ -216,19 +216,6 @@ | |||||
'search_index': 0 | 'search_index': 0 | ||||
}, | }, | ||||
# DocField | |||||
{ | |||||
'doctype': 'DocField', | |||||
'fieldname': 'no_copy', | |||||
'fieldtype': 'Check', | |||||
'label': 'No Copy', | |||||
'oldfieldname': 'no_copy', | |||||
'oldfieldtype': 'Check', | |||||
'permlevel': 0, | |||||
'reqd': 0, | |||||
'width': '50px' | |||||
}, | |||||
# DocField | # DocField | ||||
{ | { | ||||
'colour': 'White:FFF', | 'colour': 'White:FFF', | ||||
@@ -206,10 +206,9 @@ class _DocType: | |||||
dt = doclist[0].name | dt = doclist[0].name | ||||
try: | try: | ||||
for f in webnotes.conn.sql("select doc_name, property, property_type, value from `tabProperty Setter` where doc_type=%s", dt, as_dict=1): | for f in webnotes.conn.sql("select doc_name, property, property_type, value from `tabProperty Setter` where doc_type=%s", dt, as_dict=1): | ||||
#if not f['doc_name'] in property_dict: | |||||
# property_dict[f['doc_name']] = [] | |||||
#property_dict[f['doc_name']].append(f) | |||||
property_dict[f['doc_name']] = f | |||||
if not f['doc_name'] in property_dict: | |||||
property_dict[f['doc_name']] = [] | |||||
property_dict[f['doc_name']].append(f) | |||||
except Exception, e: | except Exception, e: | ||||
if e.args[0]==1146: | if e.args[0]==1146: | ||||
# no override table | # no override table | ||||
@@ -218,19 +217,21 @@ class _DocType: | |||||
raise e | raise e | ||||
change_idx = False | |||||
# loop over fields and override property | # loop over fields and override property | ||||
for d in doclist: | for d in doclist: | ||||
if d.doctype=='DocField' and d.name in property_dict: | if d.doctype=='DocField' and d.name in property_dict: | ||||
#for p in property_dict[d.name]: | |||||
p = property_dict[d.name] | |||||
if p['property_type']=='Check': | |||||
d.fields[p['property']] = int(p['value']) | |||||
elif p['property']=='previous_field': | |||||
continue | |||||
else: | |||||
d.fields[p['property']] = p['value'] | |||||
for p in property_dict[d.name]: | |||||
if p['property_type']=='Check': | |||||
d.fields[p['property']] = int(p['value']) | |||||
elif p['property']=='previous_field': | |||||
change_idx = True | |||||
continue | |||||
else: | |||||
d.fields[p['property']] = p['value'] | |||||
self.change_doclist_idx(doclist, property_dict) | |||||
if change_idx: self._change_doclist_idx(doclist, property_dict) | |||||
# override properties in the main doctype | # override properties in the main doctype | ||||
if dt in property_dict: | if dt in property_dict: | ||||
@@ -238,46 +239,69 @@ class _DocType: | |||||
doclist[0].fields[p['property']] = p['value'] | doclist[0].fields[p['property']] = p['value'] | ||||
def change_doclist_idx(self, doclist, property_dict): | |||||
def _change_doclist_idx(self, doclist, property_dict): | |||||
""" | """ | ||||
1. Select docs in doclist of type DocField | |||||
2. Sort this doclist according to idx | |||||
3. Extract the name of docs in a list | |||||
4. Arrange the property_dict entries of property "previous_field" | |||||
and chain the set of fields according to value | |||||
5. Move the docnames according to their previous field values | |||||
6. Assign the new idx values to the doclist docs | |||||
""" | """ | ||||
docfields = [] | |||||
sorted_doclist = sorted([dl for dl in doclist if dl.doctype=='DocField'], key=lambda dl: dl.idx) | |||||
old_order = [d.name for d in sorted_doclist] | |||||
property_list = [] | |||||
import webnotes | |||||
for p in property_dict.values(): | |||||
if p['property']=='previous_field': | |||||
property_list.append([p['value'], p['doc_name']]) | |||||
nf = [p for p in property_list if p[0] is None] | |||||
while(old_order): | |||||
if nf: | |||||
property_list.remove(nf[0]) | |||||
next_field = nf[0][1] | |||||
else: | |||||
for o in old_order: | |||||
if not (o in docfields): | |||||
next_field = o | |||||
old_order.remove(o) | |||||
break | |||||
else: | |||||
old_order.remove(o) | |||||
docfields.append(next_field) | |||||
nf = property_list and [p for p in property_list if p[0]==next_field] or None | |||||
# Process doclist | |||||
docfield_doclist = [d for d in doclist if d.doctype=='DocField'] | |||||
sorted_docfield_doclist = sorted(docfield_doclist, key=lambda df: df.idx) | |||||
docfields = [d.name for d in sorted_docfield_doclist] | |||||
# Process property_dict | |||||
previous_field_dict = {} | |||||
for pl in property_dict.values(): | |||||
for p in pl: | |||||
if p['property'] == 'previous_field': | |||||
previous_field_dict[str(p['value'])] = str(p['doc_name']) | |||||
i = 0 | |||||
if 'None' in previous_field_dict: | |||||
prev_field = 'None' | |||||
else: | |||||
i = i + 1 | |||||
prev_field = docfields[i] | |||||
while previous_field_dict: | |||||
get_next_docfield = 0 | |||||
webnotes.msgprint(docfields) | |||||
if prev_field in previous_field_dict: | |||||
this_field = previous_field_dict[prev_field] | |||||
docfields.remove(this_field) | |||||
if prev_field == 'None': | |||||
docfields.insert(0, this_field) | |||||
else: | |||||
docfields.insert(docfields.index(prev_field) + 1, this_field) | |||||
del previous_field_dict[prev_field] | |||||
if this_field in previous_field_dict: | |||||
prev_field = this_field | |||||
else: | |||||
get_next_docfield = 1 | |||||
else: | |||||
get_next_docfield = 1 | |||||
if get_next_docfield: | |||||
i = i + 1 | |||||
prev_field = docfields[i] | |||||
vals = previous_field_dict.values() | |||||
if prev_field in vals: | |||||
i = i - 1 | |||||
keys = previous_field_dict.keys() | |||||
prev_field = keys[vals.index(prev_field)] | |||||
for d in doclist: | for d in doclist: | ||||
if d.doctype == 'DocField': | |||||
if d.doctype=='DocField': | |||||
d.idx = docfields.index(d.name) + 1 | d.idx = docfields.index(d.name) + 1 | ||||
for d in sorted([dl for dl in doclist if dl.doctype=='DocField'], key=lambda dl: dl.idx): | |||||
webnotes.msgprint(str(d.idx) + " | " + str(d.label)) | |||||
def make_doclist(self): | def make_doclist(self): | ||||
""" | """ | ||||