Merge branch 'master' of github.com:webnotes/wnframework
This commit is contained in:
commit
8360240366
8 changed files with 48 additions and 24 deletions
|
|
@ -111,7 +111,7 @@ class DocType:
|
|||
webnotes.conn.sql("delete from `tabProperty Setter` where doc_type = %s", self.doc.name)
|
||||
webnotes.conn.sql("delete from `tabSearch Criteria` where doc_type = %s", self.doc.name)
|
||||
|
||||
def on_rename(self, new, old):
|
||||
def on_rename(self, new, old, merge=False):
|
||||
if self.doc.issingle:
|
||||
webnotes.conn.sql("""\
|
||||
update tabSingles set doctype=%s
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ Thank you,<br>
|
|||
webnotes.conn.sql("""delete from `tabComment` where comment_doctype='Message'
|
||||
and (comment_docname=%s or owner=%s)""", (self.doc.name, self.doc.name))
|
||||
|
||||
def on_rename(self,newdn,olddn):
|
||||
def on_rename(self,newdn,olddn, merge=False):
|
||||
self.validate_rename(newdn, olddn)
|
||||
|
||||
tables = webnotes.conn.sql("show tables")
|
||||
|
|
|
|||
|
|
@ -1088,7 +1088,7 @@ SelectField.prototype.make_input = function() {
|
|||
padding-left: 6px; padding-right: 6px; margin-left: 6px;'>\
|
||||
<i class='icon-plus'></i></button>")
|
||||
.click(function() {
|
||||
cur_frm.attachments.new_attachment();
|
||||
cur_frm.attachments.new_attachment(me.df.fieldname);
|
||||
})
|
||||
.appendTo(this.input_area);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,11 +62,14 @@ wn.ui.form.Attachments = Class.extend({
|
|||
|
||||
var file_list = this.get_file_list();
|
||||
var file_names = keys(file_list).sort();
|
||||
|
||||
|
||||
// add attachment objects
|
||||
for(var i=0; i<file_names.length; i++) {
|
||||
this.add_attachment(file_names[i], file_list);
|
||||
}
|
||||
|
||||
// refresh select fields with options attach_files:
|
||||
this.refresh_attachment_select_fields();
|
||||
},
|
||||
get_file_list: function() {
|
||||
return this.frm.doc.file_list ? JSON.parse(this.frm.doc.file_list) : {};
|
||||
|
|
@ -104,16 +107,13 @@ wn.ui.form.Attachments = Class.extend({
|
|||
return;
|
||||
}
|
||||
me.remove_fileid(data);
|
||||
me.frm && me.frm.cscript.on_remove_attachment
|
||||
&& me.frm.cscript.on_remove_attachment(me.frm.doc);
|
||||
me.frm.refresh();
|
||||
}
|
||||
});
|
||||
});
|
||||
return false;
|
||||
});
|
||||
},
|
||||
new_attachment: function() {
|
||||
new_attachment: function(fieldname) {
|
||||
var me = this;
|
||||
if(!this.dialog) {
|
||||
this.dialog = new wn.ui.Dialog({
|
||||
|
|
@ -125,7 +125,7 @@ wn.ui.form.Attachments = Class.extend({
|
|||
}
|
||||
this.dialog.body.innerHTML = '';
|
||||
this.dialog.show();
|
||||
|
||||
|
||||
wn.upload.make({
|
||||
parent: this.dialog.body,
|
||||
args: {
|
||||
|
|
@ -134,15 +134,19 @@ wn.ui.form.Attachments = Class.extend({
|
|||
docname: this.frm.docname
|
||||
},
|
||||
callback: function(fileid, filename, r) {
|
||||
me.update_attachment(fileid, filename, r);
|
||||
me.update_attachment(fileid, filename, fieldname, r);
|
||||
}
|
||||
});
|
||||
},
|
||||
update_attachment: function(fileid, filename, r) {
|
||||
update_attachment: function(fileid, filename, fieldname, r) {
|
||||
this.dialog && this.dialog.hide();
|
||||
if(fileid) {
|
||||
this.add_to_file_list(fileid, filename);
|
||||
this.refresh();
|
||||
if(fieldname) {
|
||||
this.frm.set_value(fieldname, "files/"+filename);
|
||||
this.frm.cscript[fieldname] && this.frm.cscript[fieldname](this.frm.doc);
|
||||
}
|
||||
}
|
||||
},
|
||||
add_to_file_list: function(fileid, filename) {
|
||||
|
|
@ -159,5 +163,18 @@ wn.ui.form.Attachments = Class.extend({
|
|||
new_file_list[key] = value;
|
||||
});
|
||||
this.frm.doc.file_list = JSON.stringify(new_file_list);
|
||||
this.refresh();
|
||||
},
|
||||
refresh_attachment_select_fields: function() {
|
||||
for(var i=0; i<this.frm.fields.length; i++) {
|
||||
if(this.frm.fields[i].attach_files) {
|
||||
var fieldname = this.frm.fields[i].df.fieldname;
|
||||
refresh_field(fieldname);
|
||||
if(this.frm.doc[fieldname]!=undefined && !inList(this.frm.fields[i].df.options.split("\n"), this.frm.doc[fieldname])) {
|
||||
this.frm.cscript.on_remove_attachment && this.frm.cscript.on_remove_attachment(this.frm.doc);
|
||||
this.frm.set_value(fieldname, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -342,9 +342,9 @@ def reload_doc(module, dt=None, dn=None):
|
|||
import webnotes.modules
|
||||
return webnotes.modules.reload_doc(module, dt, dn)
|
||||
|
||||
def rename_doc(doctype, old, new, debug=0, force=False):
|
||||
def rename_doc(doctype, old, new, debug=0, force=False, merge=False):
|
||||
from webnotes.model.rename_doc import rename_doc
|
||||
rename_doc(doctype, old, new, force=force)
|
||||
rename_doc(doctype, old, new, force=force, merge=merge)
|
||||
|
||||
def insert(doclist):
|
||||
import webnotes.model
|
||||
|
|
|
|||
|
|
@ -670,9 +670,10 @@ def copy_common_fields(from_doc, to_doc):
|
|||
if doctype_list.get_field(fieldname) and to_doc.fields[fieldname] != value:
|
||||
to_doc.fields[fieldname] = value
|
||||
|
||||
def validate_name(doctype, name, case=None):
|
||||
if webnotes.conn.sql('select name from `tab%s` where name=%s' % (doctype,'%s'), name):
|
||||
raise NameError, 'Name %s already exists' % name
|
||||
def validate_name(doctype, name, case=None, merge=False):
|
||||
if not merge:
|
||||
if webnotes.conn.sql('select name from `tab%s` where name=%s' % (doctype,'%s'), name):
|
||||
raise NameError, 'Name %s already exists' % name
|
||||
|
||||
# no name
|
||||
if not name: return 'No Name Specified for %s' % doctype
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import _
|
||||
import webnotes.utils
|
||||
from webnotes.utils import cint
|
||||
import webnotes.model.doctype
|
||||
from webnotes.model.doc import validate_name
|
||||
|
||||
|
|
@ -13,16 +13,19 @@ def rename_doc(doctype, old, new, force=False, merge=False):
|
|||
"""
|
||||
if not webnotes.conn.exists(doctype, old):
|
||||
return
|
||||
|
||||
|
||||
force = cint(force)
|
||||
merge = cint(merge)
|
||||
|
||||
# get doclist of given doctype
|
||||
doclist = webnotes.model.doctype.get(doctype)
|
||||
|
||||
new = validate_rename(doctype, new, doclist, merge, force)
|
||||
|
||||
# call on_rename
|
||||
obj = webnotes.get_obj(doctype, old)
|
||||
if hasattr(obj, 'on_rename'):
|
||||
new = obj.on_rename(new, old) or new
|
||||
new = obj.on_rename(new, old, merge) or new
|
||||
|
||||
new = validate_rename(doctype, new, doclist, merge, force)
|
||||
|
||||
if not merge:
|
||||
rename_parent_and_child(doctype, old, new, doclist)
|
||||
|
|
@ -61,8 +64,8 @@ def validate_rename(doctype, new, doclist, merge, force):
|
|||
|
||||
if merge and not exists:
|
||||
webnotes.msgprint("%s: %s does not exist, select a new target to merge." % (doctype, new), raise_exception=1)
|
||||
|
||||
if not merge and exists:
|
||||
|
||||
if (not merge) and exists:
|
||||
webnotes.msgprint("%s: %s exists, select a new, new name." % (doctype, new), raise_exception=1)
|
||||
|
||||
if not webnotes.has_permission(doctype, "write"):
|
||||
|
|
@ -72,7 +75,7 @@ def validate_rename(doctype, new, doclist, merge, force):
|
|||
webnotes.msgprint("%s cannot be renamed" % doctype, raise_exception=1)
|
||||
|
||||
# validate naming like it's done in doc.py
|
||||
new = validate_name(doctype, new)
|
||||
new = validate_name(doctype, new, merge=merge)
|
||||
|
||||
return new
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,9 @@ def runserverobj():
|
|||
else:
|
||||
webnotes.response['message'] = r
|
||||
|
||||
from webnotes.widgets.form.load import add_file_list
|
||||
add_file_list(so.doc.doctype, so.doc.name, so.doclist)
|
||||
|
||||
webnotes.response['docs'] += so.doclist
|
||||
|
||||
def check_guest_access(doc):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue