@@ -69,7 +69,7 @@ function zip(k,v) { | |||
return obj; | |||
} | |||
function save_doclist(dt, dn, save_action, onsave, onerr) { | |||
function save_doclist(dt, dn, save_action, onsave, onerr, btn) { | |||
var doc = locals[dt][dn]; | |||
var doctype = locals['DocType'][dt]; | |||
@@ -96,16 +96,19 @@ function save_doclist(dt, dn, save_action, onsave, onerr) { | |||
var _save = function() { | |||
//console.log(compress_doclist(doclist)); | |||
btn && $(btn).attr("disabled", true); | |||
$c('webnotes.widgets.form.save.savedocs', {'docs':compress_doclist(doclist), 'docname':dn, 'action': save_action, 'user':user }, | |||
function(r, rtxt) { | |||
if(f){ f.savingflag = false;} | |||
function(r) { | |||
btn && $(btn).attr("disabled", false); | |||
if(r.saved) { | |||
if(onsave)onsave(r); | |||
} else { | |||
if(onerr)onerr(r); | |||
} | |||
}, function() { | |||
if(f){ f.savingflag = false; } /*time out*/ | |||
// | |||
},0,(f ? 'Saving...' : '') | |||
); | |||
} | |||
@@ -299,7 +299,7 @@ _f.Frm.prototype.setup_footer = function() { | |||
f.help_area = $a(this.page_layout.footer,'div'); | |||
var b = $btn(f.save_area, 'Save', | |||
function() { cur_frm.save('Save'); },{marginLeft:'0px'},'green'); | |||
function() { cur_frm.save('Save', this); },{marginLeft:'0px'},'green'); | |||
// show / hide save | |||
f.show_save = function() { | |||
@@ -807,7 +807,7 @@ _f.Frm.prototype.show_doc = function(dn) { | |||
// ====================================================================================== | |||
var validated; // bad design :( | |||
_f.Frm.prototype.save = function(save_action, call_back) { | |||
_f.Frm.prototype.save = function(save_action, callback, btn) { | |||
// removes focus from a field before save, | |||
// so that its change event gets triggered before saving | |||
$(document.activeElement).blur(); | |||
@@ -818,12 +818,6 @@ _f.Frm.prototype.save = function(save_action, call_back) { | |||
save_action = 'Save'; | |||
} | |||
var me = this; | |||
if(this.savingflag) { | |||
msgprint("Document is currently saving...."); | |||
return; // already saving (do not double save) | |||
} | |||
if(save_action=='Submit') { | |||
locals[this.doctype][this.docname].submitted_on = dateutil.full_str(); | |||
locals[this.doctype][this.docname].submitted_by = user; | |||
@@ -856,36 +850,28 @@ _f.Frm.prototype.save = function(save_action, call_back) { | |||
this.runclientscript('validate'); | |||
if(!validated) { | |||
this.savingflag = false; | |||
return 'Error'; | |||
} | |||
} | |||
var ret_fn = function(r) { | |||
me.savingflag = false; | |||
var onsave = function(r) { | |||
if(!me.meta.istable && r) { | |||
me.refresh(r.docname); | |||
} | |||
if(call_back){ | |||
call_back(r); | |||
} | |||
callback && callback(r) | |||
} | |||
var me = this; | |||
var ret_fn_err = function(r) { | |||
var onerr = function(r) { | |||
var doc = locals[me.doctype][me.docname]; | |||
me.savingflag = false; | |||
ret_fn(r); | |||
onsave(r); | |||
} | |||
this.savingflag = true; | |||
if(this.docname && validated) { | |||
// scroll to top | |||
scroll(0, 0); | |||
return this.savedoc(save_action, ret_fn, ret_fn_err); | |||
return save_doclist(this.doctype, this.docname, save_action, onsave, onerr, btn); | |||
} | |||
} | |||
@@ -1019,7 +1005,7 @@ _f.Frm.prototype.reload_doc = function() { | |||
this.check_doctype_conflict(this.docname); | |||
var me = this; | |||
var ret_fn = function(r, rtxt) { | |||
var onsave = function(r, rtxt) { | |||
// n tweets and last comment | |||
me.runclientscript('setup', me.doctype, me.docname); | |||
me.refresh(); | |||
@@ -1027,23 +1013,14 @@ _f.Frm.prototype.reload_doc = function() { | |||
if(me.doc.__islocal) { | |||
// reload only doctype | |||
$c('webnotes.widgets.form.load.getdoctype', {'doctype':me.doctype }, ret_fn, null, null, 'Refreshing ' + me.doctype + '...'); | |||
$c('webnotes.widgets.form.load.getdoctype', {'doctype':me.doctype }, onsave, null, null, 'Refreshing ' + me.doctype + '...'); | |||
} else { | |||
// reload doc and docytpe | |||
$c('webnotes.widgets.form.load.getdoc', {'name':me.docname, 'doctype':me.doctype, 'getdoctype':1, 'user':user}, ret_fn, null, null, 'Refreshing ' + me.docname + '...'); | |||
$c('webnotes.widgets.form.load.getdoc', {'name':me.docname, 'doctype':me.doctype, 'getdoctype':1, 'user':user}, onsave, null, null, 'Refreshing ' + me.docname + '...'); | |||
} | |||
} | |||
_f.Frm.prototype.savedoc = function(save_action, onsave, onerr) { | |||
save_doclist(this.doctype, this.docname, save_action, onsave, onerr); | |||
} | |||
_f.Frm.prototype.saveupdate = function() { | |||
this.save('Update'); | |||
} | |||
_f.Frm.prototype.savesubmit = function() { | |||
_f.Frm.prototype.savesubmit = function(btn) { | |||
var answer = confirm("Permanently Submit "+this.docname+"?"); | |||
var me = this; | |||
if(answer) { | |||
@@ -1051,13 +1028,13 @@ _f.Frm.prototype.savesubmit = function() { | |||
if(!r.exc && me.cscript.on_submit) { | |||
me.runclientscript('on_submit', me.doctype, me.docname); | |||
} | |||
}); | |||
}, btn); | |||
} | |||
} | |||
_f.Frm.prototype.savecancel = function() { | |||
_f.Frm.prototype.savecancel = function(btn) { | |||
var answer = confirm("Permanently Cancel "+this.docname+"?"); | |||
if(answer) this.save('Cancel'); | |||
if(answer) this.save('Cancel', null, btn); | |||
} | |||
// delete the record | |||
@@ -116,26 +116,32 @@ _f.FrmHeader = Class.extend({ | |||
var docstatus = cint(cur_frm.doc.docstatus); | |||
// Save | |||
if(docstatus==0 && p[WRITE]) { | |||
this.appframe.add_button('Save', function() { cur_frm.save('Save');}, ''); | |||
this.appframe.add_button('Save', function() { | |||
cur_frm.save('Save', null, this);}, ''); | |||
this.appframe.buttons['Save'].addClass('btn-info').text("Save (Ctrl+S)"); | |||
} | |||
// Submit | |||
if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal)) | |||
this.appframe.add_button('Submit', function() { cur_frm.savesubmit();}, 'icon-lock'); | |||
this.appframe.add_button('Submit', function() { | |||
cur_frm.savesubmit(this);}, 'icon-lock'); | |||
// Update after sumit | |||
if(docstatus==1 && p[SUBMIT]) { | |||
this.appframe.add_button('Update', function() { cur_frm.saveupdate();}, ''); | |||
this.appframe.add_button('Update', function() { | |||
this.save('Update', null, this); | |||
}, ''); | |||
if(!cur_frm.doc.__unsaved) this.appframe.buttons['Update'].toggle(false); | |||
} | |||
// Cancel | |||
if(docstatus==1 && p[CANCEL]) | |||
this.appframe.add_button('Cancel', function() { cur_frm.savecancel() }, 'icon-remove'); | |||
this.appframe.add_button('Cancel', function() { | |||
cur_frm.savecancel(this) }, 'icon-remove'); | |||
// Amend | |||
if(docstatus==2 && p[AMEND]) | |||
this.appframe.add_button('Amend', function() { cur_frm.amend_doc() }, 'icon-pencil'); | |||
this.appframe.add_button('Amend', function() { | |||
cur_frm.amend_doc() }, 'icon-pencil'); | |||
// Help | |||
if(cur_frm.meta.description) { | |||
@@ -1,87 +0,0 @@ | |||
wn.provide('wn.form'); | |||
wn.form.Header = Class.extend({ | |||
init: function(parent) { | |||
this.buttons = {}; | |||
this.$w = $('<div><h1></h1>\ | |||
<a class="close" onclick="window.history.back();">×</a> | |||
<div class="label-area"></div>\ | |||
<div class="toolbar-area"></div></div><hr>'). | |||
appendTo(parent); | |||
}, | |||
refresh: function() { | |||
var m = cur_frm.meta; | |||
this.$w.toggle(!m.hide_heading && !cur_frm.in_dialog); | |||
this.$w.find('.toolbar-area').toggle(m.hide_toolbar); | |||
this.$w.find('.toolbar-area').empty(); | |||
this.add_buttons(); | |||
}, | |||
add_buttons: function() { | |||
// Print View | |||
if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) { | |||
if(cur_frm.editable) { | |||
this.add_button({ | |||
label:'Print View', | |||
click: function() { | |||
cur_frm.is_editable[cur_frm.docname] = 0; | |||
cur_frm.refresh(); | |||
}, | |||
icon: 'icon-print' | |||
}) | |||
} | |||
} | |||
switch(cur_frm.doc.docstatus) { | |||
case 0: | |||
if(p[WRITE]) { | |||
this.add_button({ | |||
label:'Save', click:function() { cur_frm.save('Save'); } | |||
}); | |||
if(!cur_frm.doc.__islocal) { | |||
this.add_button({ | |||
label:'Submit', click:function() { cur_frm.savesubmit(); }, | |||
icon: 'icon-lock' | |||
}); | |||
}; | |||
} | |||
break; | |||
case 1: | |||
if(p[SUBMIT] && cur_frm.doc.__unsaved) { | |||
this.add_button({ | |||
label:'Update', click: function() { cur_frm.saveupdate(); } | |||
}); | |||
} | |||
if(p[CANCEL]) { | |||
this.add_button({ | |||
label:'Cancel', click: function() { cur_frm.savecancel(); }, | |||
icon: 'icon-remove' | |||
}); | |||
} | |||
break; | |||
case 2: | |||
if(p[AMEND]) { | |||
this.add_button({ | |||
label:'Amend', click: function() { cur_frm.amend_doc(); }, | |||
icon: 'icon-pencil' | |||
}); | |||
} | |||
} | |||
}, | |||
add_button: function(opts) { | |||
// label, icon, click | |||
var b = $('<button class="btn btn-small"></button>') | |||
.text(opts.label) | |||
.click(click) | |||
.appendTo(this.$w.find('.toolbar-area')) | |||
if(opts.icon) { | |||
b.html('<i class="'+opts.icon+'"></i> ' + opts.label); | |||
} | |||
this.buttons[opts.label] = b; | |||
} | |||
}) |
@@ -274,7 +274,7 @@ def run(): | |||
elif options.watch: | |||
from webnotes.utils import bundlejs | |||
bundlejs.watch(options.no_compress) | |||
bundlejs.watch(True) | |||
return | |||
# code replace | |||