Merge branch 'latest' of github.com:webnotes/wnframework into latest

This commit is contained in:
Rushabh Mehta 2012-01-25 18:47:54 +05:30
commit 19d2a73dce
6 changed files with 113 additions and 16 deletions

View file

@ -437,7 +437,9 @@ return layout;},print_std_add_table:function(t,layout,pf_list,dt,no_letterhead){
layout.cur_cell.appendChild(t[t.length-1]);}
return layout;},print_std_add_field:function(dt,dn,f,layout){var val=_f.get_value(dt,dn,f.fieldname);if(f.fieldtype!='Button'){if(val||in_list(['Float','Int','Currency'],f.fieldtype)){row=_p.field_tab(layout.cur_cell);row.cells[0].innerHTML=f.label?f.label:f.fieldname;$s(row.cells[1],val,f.fieldtype);if(f.fieldtype=='Currency'){$y(row.cells[1],{textAlign:'left'});}}}},field_tab:function(layout_cell){var tab=$a(layout_cell,'table','',{width:'100%'});var row=tab.insertRow(0);_p.row=row;row.insertCell(0);row.insertCell(1);row.cells[0].className='datalabelcell';row.cells[1].className='datainputcell';return row;}});print_table=function(dt,dn,fieldname,tabletype,cols,head_labels,widths,condition,cssClass,modifier){var me=this;$.extend(this,{flist:fields_list[tabletype],data:function(){var children=getchildren(tabletype,dn,fieldname,dt);var data=[]
for(var i=0;i<children.length;i++){data.push(copy_dict(children[i]));}
return data;}(),cell_style:{border:'1px solid #000',padding:'2px',verticalAlign:'top'},head_cell_style:{border:'1px solid #000',padding:'2px',verticalAlign:'top',backgroundColor:'#ddd',fontWeight:'bold'},table_style:{width:'100%',borderCollapse:'collapse',marginBottom:'10px'},prepare_col_heads:function(flist){var new_flist=[];if(cols&&cols.length){if(cols[0]=='SR'){new_flist.push('SR')}
return data;}(),cell_style:{border:'1px solid #000',padding:'2px',verticalAlign:'top'},head_cell_style:{border:'1px solid #000',padding:'2px',verticalAlign:'top',backgroundColor:'#ddd',fontWeight:'bold'},table_style:{width:'100%',borderCollapse:'collapse',marginBottom:'10px'},remove_empty_cols:function(flist){var non_empty_cols=[]
for(var i=0;i<me.data.length;i++){for(var c=0;c<flist.length;c++){if(flist[c].print_hide||!inList(['',null],me.data[i][flist[c].fieldname])){if(!inList(non_empty_cols,flist[c])){non_empty_cols.push(flist[c]);}}}}
for(var c=0;c<flist.length;c++){if(!inList(non_empty_cols,flist[c])){flist.splice(c,1);c=c-1;}}},prepare_col_heads:function(flist){var new_flist=[];me.remove_empty_cols(flist);if(cols&&cols.length){if(cols[0]=='SR'){new_flist.push('SR')}
for(var i=0;i<cols.length;i++){for(var j=0;j<flist.length;j++){if(flist[j].fieldname==cols[i]){new_flist.push(flist[j]);break;}}}}else{new_flist.push('SR');for(var i=0;i<flist.length;i++){if(!flist[i].print_hide){new_flist.push(flist[i]);}}}
me.flist=new_flist;},make_print_table:function(flist){var wrapper=document.createElement('div');var table=$a(wrapper,'table','',me.table_style);table.wrapper=wrapper;table.insertRow(0);var col_start=0;if(flist[0]=='SR'){var cell=table.rows[0].insertCell(0);cell.innerHTML=head_labels?head_labels[0]:'<b>SR</b>';$y(cell,{width:'30px'});$y(cell,me.head_cell_style);col_start++;}
for(var c=col_start;c<flist.length;c++){var cell=table.rows[0].insertCell(c);$y(cell,me.head_cell_style);cell.innerHTML=head_labels?head_labels[c]:flist[c].label;if(flist[c].width){$y(cell,{width:flist[c].width});}
@ -568,4 +570,4 @@ this.refresh();},refresh:function(){var me=this;$c('webnotes.widgets.form.assign
for(var i=0;i<d.length;i++){$(this.body).append(repl('<div>%(owner)s \
<a class="close" href="#" data-owner="%(owner)s">&#215</a></div>',d[i]))}
$(this.body).find('a.close').click(function(){$c('webnotes.widgets.form.assign_to.remove',{doctype:me.doctype,name:me.name,assign_to:$(this).attr('data-owner')},function(r,rt){me.render(r.message);});return false;});},add:function(){var me=this;if(!me.dialog){me.dialog=new wn.widgets.Dialog({title:'Add to To Do',width:350,fields:[{fieldtype:'Link',fieldname:'assign_to',options:'Profile',label:'Assign To',description:'Add to To Do List of',reqd:true},{fieldtype:'Data',fieldname:'description',label:'Comment','default':'Assigned by '+user},{fieldtype:'Date',fieldname:'date',label:'Complete By'},{fieldtype:'Select',fieldname:'priority',label:'Priority',options:'Low\nMedium\nHigh','default':'Medium'},{fieldtype:'Button',label:'Add',fieldname:'add_btn'}]});me.dialog.fields_dict.add_btn.input.onclick=function(){var assign_to=me.dialog.fields_dict.assign_to.get_value();if(assign_to){$c('webnotes.widgets.form.assign_to.add',{doctype:me.doctype,name:me.name,assign_to:assign_to,description:me.dialog.fields_dict.description.get_value(),priority:me.dialog.fields_dict.priority.get_value(),date:me.dialog.fields_dict.date.get_value()},function(r,rt){me.render(r.message);});}}}
me.dialog.clear();me.dialog.show();}});
me.dialog.clear();me.dialog.show();}});

View file

@ -624,12 +624,34 @@ print_table = function(dt, dn, fieldname, tabletype, cols, head_labels, widths,
borderCollapse: 'collapse',
marginBottom: '10px'
},
remove_empty_cols: function(flist) {
var non_empty_cols = []
for(var i=0; i<me.data.length; i++) {
for(var c=0; c<flist.length; c++) {
if(flist[c].print_hide || !inList(['', null], me.data[i][flist[c].fieldname])) {
if(!inList(non_empty_cols, flist[c])) {
non_empty_cols.push(flist[c]);
}
}
}
}
for(var c=0; c<flist.length; c++) {
if(!inList(non_empty_cols, flist[c])) {
//console.log(flist[c].fieldname);
flist.splice(c, 1);
c = c - 1;
}
}
},
/*
This function prepares a list of columns to be displayed and calls make_print_table to create a table with these columns
*/
prepare_col_heads: function(flist) {
var new_flist = [];
me.remove_empty_cols(flist);
// Make a list of column headings
if(cols && cols.length) {

View file

@ -8,13 +8,14 @@ cur_frm.cscript.onload = function(doc, dt, dn) {
cur_frm.grids[0].grid.tbar_div.style.width = "30%";
cur_frm.tip_wrapper.id = 'tip_wrapper';
cur_frm.add_fields_help();
cur_frm.load_doclabel_options(doc, dt, dn);
}
cur_frm.cscript.refresh = function(doc, dt, dn) {
//console.log(p)
cur_frm.frm_head.timestamp_area.hidden = true;
cur_frm.frm_head.page_head.buttons.Save.hidden = true;
cur_frm.page_layout.footer.hidden = true;
$(cur_frm.frm_head.timestamp_area).toggle(false);
$(cur_frm.frm_head.page_head.buttons.Save).toggle(false);
$(cur_frm.page_layout.footer).toggle(false);
if(doc.doc_type) { $('#tip_wrapper').slideUp('slow'); }
//cur_frm.grids[0].grid.tab.rows[cur_frm.grids[0].grid.tab.rows.length-1].hidden = true;
@ -32,7 +33,8 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
});
}
},1);
cur_frm.frm_head.page_head.buttons.Update.className = "cupid-green";
$(cur_frm.frm_head.page_head.buttons.Update).addClass('primary');
$(cur_frm.frm_head.page_head.buttons.Update).addClass('cupid-green');
cur_frm.add_custom_button('Refresh Form', function() {
cur_frm.cscript.doc_type(doc, dt, dn);
@ -51,6 +53,26 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
page_head.buttons['Refresh Form'].disabled = true;
page_head.buttons['Reset to defaults'].disabled = true;
}
cur_frm.refresh_doctype_select(doc, dt, dn);
}
cur_frm.load_doclabel_options = function(doc, dt, dn) {
$c_obj('DocLayer','get_doctype_list','', function(r,rt) {
cur_frm.doctype_list = add_lists([""], r.message.doctype_list).join("\n");
doc = locals[doc.doctype][doc.name]
cur_frm.refresh_doctype_select(doc, dt, dn);
});
}
cur_frm.refresh_doctype_select = function(doc, dt, dn) {
var doc_type = cur_frm.fields_dict['doc_type'];
doc_type.refresh_options(cur_frm.doctype_list);
if(doc.doc_type) {
doc_type.set_input(doc.doc_type);
} else {
doc_type.set_input('');
}
}

View file

@ -39,6 +39,10 @@ class DocType:
'name'
]
if self.doc.doc_type:
from webnotes.utils import get_label_doctype
self.true_doctype = get_label_doctype(self.doc.doc_type)
def get(self):
"""
@ -72,8 +76,8 @@ class DocType:
from webnotes.model.doctype import _DocType
from webnotes.model.doc import get
ref_doclist = get('DocType', self.doc.doc_type)
_DocType(self.doc.doc_type)._override_field_properties(ref_doclist)
ref_doclist = get('DocType', self.true_doctype)
_DocType(self.true_doctype)._override_field_properties(ref_doclist)
return ref_doclist
@ -122,7 +126,7 @@ class DocType:
this_doclist = [self.doc] + self.doclist
ref_doclist = self.get_ref_doclist()
dt_doclist = doc.get('DocType', self.doc.doc_type)
dt_doclist = doc.get('DocType', self.true_doctype)
# get a list of property setter docs
diff_list = self.diff(this_doclist, ref_doclist, dt_doclist)
@ -234,13 +238,13 @@ class DocType:
from webnotes.model.doc import Document
d = Document('Property Setter')
d.doctype_or_field = ref_d.doctype=='DocField' and 'DocField' or 'DocType'
d.doc_type = self.doc.doc_type
d.doc_type = self.true_doctype
d.doc_name = ref_d.name
d.property = prop
d.value = value
d.property_type = self.defaults[prop]['fieldtype']
d.default_value = self.defaults[prop]['default']
d.select_doctype = self.doc.doc_type
d.select_doctype = self.doc.doc_type
d.select_item = ref_d.label and str(ref_d.idx) \
+ " - " + str(ref_d.label) \
+ " (" + str(ref_d.fieldtype) + ")" \
@ -292,7 +296,7 @@ class DocType:
if self.doc.doc_type:
webnotes.conn.sql("""
DELETE FROM `tabProperty Setter`
WHERE doc_type = %s""", self.doc.doc_type)
WHERE doc_type = %s""", self.true_doctype)
self.get()
def remove_forbidden(self, string):
@ -302,4 +306,24 @@ class DocType:
forbidden = ['%', "'", '"', '#', '*', '?', '`']
for f in forbidden:
string.replace(f, ' ')
def get_doctype_list(self):
"""
Returns a list of doctypes allowed to be customized
"""
res = webnotes.conn.sql("""\
SELECT name FROM `tabDocType`
WHERE (module IN
("Accounts", "Buying", "HR", "Knowledge Base", "Production", "Projects",
"Selling", "Stock", "Support") OR name IN ("Contact", "Address"))
AND IFNULL(issingle, 0)=0 AND IFNULL(in_create, 0)=0
""")
from webnotes.utils import get_doctype_label
dt_label_dict = get_doctype_label()
doctype_list = res and [dt_label_dict.get(r[0], r[0]) for r in res] or []
doctype_list.sort()
return {'doctype_list': doctype_list}

View file

@ -5,14 +5,14 @@
{
'creation': '2011-12-21 11:07:56',
'docstatus': 0,
'modified': '2012-01-09 11:56:53',
'modified': '2012-01-25 17:14:46',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1325570719',
'_last_update': '1326273643',
'autoname': 'DL.####',
'colour': 'White:FFF',
'doctype': 'DocType',
@ -23,7 +23,7 @@
'search_fields': 'doc_type',
'section_style': 'Simple',
'show_in_menu': 0,
'version': 96
'version': 106
},
# These values are common for all DocField
@ -79,8 +79,8 @@
'doctype': 'DocField',
'fieldname': 'doc_type',
'fieldtype': 'Select',
'hidden': 0,
'label': 'Select Form Type',
'options': 'Link:DocType\nmodule IN ("Accounts", "Buying", "HR", "Knowledge Base", "Production", "Projects", "Selling", "Stock", "Support")\nIFNULL(issingle, 0)=0\nIFNULL(in_create, 0)=0',
'permlevel': 0
},

View file

@ -630,3 +630,30 @@ def make_esc(esc_chars):
return lambda s: ''.join(['\\' + c if c in esc_chars else c for c in s])
def get_doctype_label(dt=None):
"""
Gets label of a doctype
"""
if dt:
res = webnotes.conn.sql("""\
SELECT name, dt_label FROM `tabDocType Label`
WHERE name=%s""", dt)
return res and res[0][0] or dt
else:
res = webnotes.conn.sql("SELECT name, dt_label FROM `tabDocType Label`")
dt_label_dict = {}
for r in res:
dt_label_dict[r[0]] = r[1]
return dt_label_dict
def get_label_doctype(label):
"""
Gets doctype from its label
"""
res = webnotes.conn.sql("""\
SELECT name FROM `tabDocType Label`
WHERE dt_label=%s""", label)
return res and res[0][0] or label