Implementation of DocLayer front end for easy management of Property Setter

This commit is contained in:
Anand Doshi 2011-11-17 18:39:31 +05:30
parent 261ef11fae
commit 1c2014d78b
7 changed files with 646 additions and 0 deletions

View file

View file

@ -0,0 +1,20 @@
cur_frm.cscript.doc_type = function(doc, dt, dn) {
//console.log(doc);
//console.log(doc_type);
$c_obj(make_doclist(dt, dn), 'get', '', function(r, rt) {
cur_frm.refresh();
//console.log(arguments);
});
}
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
cur_frm.frm_head.page_head.buttons.Save.hidden=1;
cur_frm.page_layout.footer.hidden = 1;
cur_frm.add_custom_button('Update', function() {
if(cur_frm.fields_dict['doc_type'].value) {
$c_obj(make_doclist(dt, dn), 'post', '', function(r, rt) {
console.log(arguments);
});
}
});
}

View file

@ -0,0 +1,106 @@
"""
DocLayer is a Single DocType used to mask the Property Setter
Thus providing a better UI from user perspective
"""
class DocType:
def __init__(self, doc, doclist=[]):
self.doc, self.doclist = doc, doclist
self.doctype_properties = [
'autoname',
'search_fields',
'tag_fields',
'default_print_format',
'read_only_onload',
'allow_print',
'allow_email',
'allow_copy',
'allow_rename',
'allow_attach',
'max_attachments'
]
self.docfield_properties = [
'label',
'fieldtype',
'fieldname',
'options',
'permlevel',
'width',
'reqd',
'in_filter',
'hidden',
'print_hide',
'no_copy',
'report_hide',
'allow_on_submit',
'depends_on',
'description',
'default',
'name'
]
def get(self):
"""
Gets DocFields applied with Property Setter customizations via DocLayerField
"""
from webnotes.model.doctype import get
from webnotes.model.doc import addchild
import webnotes
self.clear()
if self.doc.doc_type:
for d in get(self.doc.doc_type):
if d.doctype=='DocField':
new = addchild(self.doc, 'fields', 'DocLayerField', 1, self.doclist)
self.set(
{
'list': self.docfield_properties,
'doc' : d,
'doc_to_set': new
}
)
elif d.doctype=='DocType':
self.set({ 'list': self.doctype_properties, 'doc': d })
def post(self):
"""
Save diff between DocLayer DocList and DocType DocList as property setter entries
"""
pass
def clear(self):
"""
Clear fields in the doc
"""
# Clear table before adding new doctype's fields
self.doc.clear_table(self.doclist, 'fields')
self.set({ 'list': self.doctype_properties, 'value': None })
def set(self, args):
"""
Set a list of attributes of a doc to a value
or to attribute values of a doc passed
args can contain:
* list --> list of attributes to set
* doc_to_set --> defaults to self.doc
* value --> to set all attributes to one value eg. None
* doc --> copy attributes from doc to doc_to_set
"""
if not 'doc_to_set' in args:
args['doc_to_set'] = self.doc
if 'list' in args:
if 'value' in args:
for f in args['list']:
args['doc_to_set'].fields[f] = None
elif 'doc' in args:
for f in args['list']:
args['doc_to_set'].fields[f] = args['doc'].fields[f]
else:
import webnotes
webnotes.msgprint("Please specify args['list'] to set", raise_exception=1)

View file

@ -0,0 +1,226 @@
# DocType, DocLayer
[
# These values are common in all dictionaries
{
'creation': '2011-11-16 16:09:34',
'docstatus': 0,
'modified': '2011-11-17 16:38:45',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1321528082',
'autoname': 'DL.####',
'colour': 'White:FFF',
'doctype': 'DocType',
'hide_toolbar': 0,
'issingle': 1,
'module': 'Core',
'name': '__common__',
'search_fields': 'doc_type',
'section_style': 'Simple',
'show_in_menu': 1,
'version': 21
},
# These values are common for all DocField
{
'doctype': 'DocField',
'name': '__common__',
'parent': 'DocLayer',
'parentfield': 'fields',
'parenttype': 'DocType'
},
# These values are common for all DocPerm
{
'doctype': 'DocPerm',
'name': '__common__',
'parent': 'DocLayer',
'parentfield': 'permissions',
'parenttype': 'DocType',
'read': 1,
'role': 'System Manager'
},
# DocType, DocLayer
{
'doctype': 'DocType',
'name': 'DocLayer'
},
# DocPerm
{
'create': 1,
'doctype': 'DocPerm',
'permlevel': 0,
'write': 1
},
# DocPerm
{
'create': 1,
'doctype': 'DocPerm',
'permlevel': 1,
'write': 1
},
# DocPerm
{
'doctype': 'DocPerm',
'permlevel': 2
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'doc_type',
'fieldtype': 'Select',
'label': 'Type',
'options': 'Link:DocType',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'label': 'Properties',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'autoname',
'fieldtype': 'Data',
'label': 'Auto Name',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'search_fields',
'fieldtype': 'Data',
'label': 'Search Fields',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'tag_fields',
'fieldtype': 'Data',
'label': 'Tag Fields',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'default_print_format',
'fieldtype': 'Link',
'label': 'Default Print Format',
'options': 'Print Format',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'read_only_onload',
'fieldtype': 'Check',
'label': 'Show Print First',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'allow_print',
'fieldtype': 'Check',
'label': 'Hide Print',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'allow_email',
'fieldtype': 'Check',
'label': 'Hide Email',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'allow_copy',
'fieldtype': 'Check',
'label': 'Hide Copy',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'allow_rename',
'fieldtype': 'Check',
'label': 'Allow Rename',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'allow_attach',
'fieldtype': 'Check',
'label': 'Allow Attach',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'max_attachments',
'fieldtype': 'Int',
'label': 'Max Attachments',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'label': 'Fields',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fields',
'fieldtype': 'Table',
'label': 'Fields',
'options': 'DocLayerField',
'permlevel': 1
}
]

View file

@ -0,0 +1,294 @@
# DocType, DocLayerField
[
# These values are common in all dictionaries
{
'creation': '2011-11-16 16:45:16',
'docstatus': 0,
'modified': '2011-11-17 14:28:16',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'allow_copy': 0,
'allow_email': 0,
'allow_print': 0,
'autoname': 'DLF.#####',
'colour': 'White:FFF',
'doctype': 'DocType',
'hide_heading': 0,
'hide_toolbar': 0,
'issingle': 0,
'istable': 1,
'module': 'Core',
'name': '__common__',
'read_only': 0,
'section_style': 'Simple',
'show_in_menu': 0,
'version': 2
},
# These values are common for all DocField
{
'doctype': 'DocField',
'hidden': 0,
'name': '__common__',
'parent': 'DocLayerField',
'parentfield': 'fields',
'parenttype': 'DocType',
'print_hide': 0
},
# These values are common for all DocPerm
{
'doctype': 'DocPerm',
'name': '__common__',
'parent': 'DocLayerField',
'parentfield': 'permissions',
'parenttype': 'DocType',
'read': 1,
'role': 'System Manager'
},
# DocType, DocLayerField
{
'doctype': 'DocType',
'name': 'DocLayerField'
},
# DocPerm
{
'create': 1,
'doctype': 'DocPerm',
'permlevel': 0,
'write': 1
},
# DocPerm
{
'create': 1,
'doctype': 'DocPerm',
'permlevel': 1,
'write': 1
},
# DocPerm
{
'doctype': 'DocPerm',
'permlevel': 2
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'label',
'fieldtype': 'Data',
'label': 'Label',
'oldfieldname': 'label',
'oldfieldtype': 'Data',
'permlevel': 1,
'reqd': 0,
'search_index': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fieldtype',
'fieldtype': 'Select',
'label': 'Type',
'oldfieldname': 'fieldtype',
'oldfieldtype': 'Select',
'options': 'Data\nSelect\nText\nSmall Text\nText Editor\nLink\nInt\nDate\nTime\nCurrency\nTable\nFloat\nCheck\nSection Break\nColumn Break\nButton\nRead Only\nCode\nHTML\nImage\nBlob\nPassword',
'permlevel': 2,
'reqd': 1,
'search_index': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fieldname',
'fieldtype': 'Data',
'label': 'Name',
'oldfieldname': 'fieldname',
'oldfieldtype': 'Data',
'permlevel': 2,
'reqd': 0,
'search_index': 1
},
# DocField
{
'description': 'For Links, enter the DocType as range\nFor Select, enter list of Options separated by comma',
'doctype': 'DocField',
'fieldname': 'options',
'fieldtype': 'Text',
'label': 'Options',
'oldfieldname': 'options',
'oldfieldtype': 'Text',
'permlevel': 1,
'reqd': 0,
'search_index': 0
},
# DocField
{
'default': '0',
'doctype': 'DocField',
'fieldname': 'permlevel',
'fieldtype': 'Int',
'label': 'Perm Level',
'oldfieldname': 'permlevel',
'oldfieldtype': 'Int',
'permlevel': 1,
'reqd': 0,
'search_index': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'width',
'fieldtype': 'Data',
'label': 'Width',
'oldfieldname': 'width',
'oldfieldtype': 'Data',
'permlevel': 1,
'reqd': 0,
'search_index': 0,
'width': '50px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'reqd',
'fieldtype': 'Check',
'label': 'Reqd',
'oldfieldname': 'reqd',
'oldfieldtype': 'Check',
'permlevel': 1,
'reqd': 0,
'search_index': 0,
'width': '50px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'in_filter',
'fieldtype': 'Check',
'label': 'In Filter',
'oldfieldname': 'in_filter',
'oldfieldtype': 'Check',
'permlevel': 1,
'reqd': 0,
'width': '50px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'hidden',
'fieldtype': 'Check',
'label': 'Hidden',
'oldfieldname': 'hidden',
'oldfieldtype': 'Check',
'permlevel': 1,
'reqd': 0,
'search_index': 0,
'width': '50px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'print_hide',
'fieldtype': 'Check',
'label': 'Print Hide',
'oldfieldname': 'print_hide',
'oldfieldtype': 'Check',
'permlevel': 1,
'reqd': 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
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldname': 'report_hide',
'fieldtype': 'Check',
'label': 'Report Hide',
'oldfieldname': 'report_hide',
'oldfieldtype': 'Check',
'permlevel': 1,
'reqd': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'allow_on_submit',
'fieldtype': 'Check',
'label': 'Allow on Submit',
'oldfieldname': 'allow_on_submit',
'oldfieldtype': 'Check',
'permlevel': 0,
'reqd': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'depends_on',
'fieldtype': 'Data',
'label': 'Depends On',
'oldfieldname': 'depends_on',
'oldfieldtype': 'Data',
'permlevel': 1,
'reqd': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'description',
'fieldtype': 'Text',
'label': 'Description',
'oldfieldname': 'description',
'oldfieldtype': 'Text',
'permlevel': 1,
'reqd': 0,
'width': '300px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'default',
'fieldtype': 'Text',
'label': 'Default',
'oldfieldname': 'default',
'oldfieldtype': 'Text',
'permlevel': 1,
'reqd': 0,
'search_index': 0
}
]