Added reset to default functionality to doclayer

This commit is contained in:
Anand Doshi 2011-11-22 18:17:56 +05:30
parent 0389e76a94
commit d98667a4e8
2 changed files with 45 additions and 33 deletions

View file

@ -29,8 +29,8 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
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);
font-size: 11px;">Saved</span>';
//console.log(arguments);
}
});
}
@ -42,49 +42,49 @@ cur_frm.cscript.refresh = function(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?');
cur_frm.confirm('This will <b>remove the customizations</b> defined for this form.<br /><br />'
+ 'Are you sure you want to <i>reset to defaults</i>?', doc, dt, dn);
}, 1);
}
cur_frm.confirm = function(msg) {
cur_frm.confirm = function(msg, doc, dt, dn) {
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'
}
]
width: 500
});
//d.set_value('msg', msg);
d.fields_dict.btn_proceed.input.onclick = function() {
this.set_working();
$y(d.body, {padding: '32px', textAlign: 'center'});
$a(d.body, 'div', '', '', msg);
var button_wrapper = $a(d.body, 'div');
$y(button_wrapper, {paddingTop: '15px'});
var proceed_btn = $btn(button_wrapper, 'Proceed', function() {
$c_obj(make_doclist(dt, dn), 'delete', '', function(r, rt) {
//console.log(arguments);
if(r.exc) {
msgprint(r.exc);
} else {
console.log(arguments);
cur_frm.confirm.dialog.hide();
cur_frm.refresh();
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>';
}
});
this.done_working();
cur_frm.confirm_dialog.hide();
}
d.fields_dict.btn_cancel.input.onclick = function() {
});
$y(proceed_btn, {marginRight: '20px', fontWeight: 'bold'});
var cancel_btn = $btn(button_wrapper, 'Cancel', function() {
cur_frm.confirm.dialog.hide();
}
});
cancel_btn.className = 'cupid-green';
$y(cancel_btn, {fontWeight: 'bold'});
cur_frm.confirm.dialog = d;
d.show();
}

View file

@ -32,7 +32,6 @@ class DocType:
'in_filter',
'hidden',
'print_hide',
'no_copy',
'report_hide',
'allow_on_submit',
'depends_on',
@ -200,6 +199,7 @@ class DocType:
new_d.fields[prop] in [None, ''] \
and ref_d.fields[prop] in [None, ''] \
):
#webnotes.msgprint("new: " + str(new_d.fields[prop]) + " | old: " + str(ref_d.fields[prop]))
# Check if the new property is same as that in original doctype
# If yes, we need to delete the property setter entry
for dt_d in dt_doclist:
@ -278,3 +278,15 @@ class DocType:
# Save the property setter doc if not marked for deletion i.e. delete=0
if not d.delete:
d.save(1)
def delete(self):
"""
Deletes all property setter entries for the selected doctype
and resets it to standard
"""
if self.doc.doc_type:
webnotes.conn.sql("""
DELETE FROM `tabProperty Setter`
WHERE doc_type = %s""", self.doc.doc_type)
self.get()