@@ -9,6 +9,10 @@ from webnotes.utils import cint, cstr | |||||
class DocType: | class DocType: | ||||
def __init__(self, d, dl): | def __init__(self, d, dl): | ||||
self.doc, self.doclist = d, dl | self.doc, self.doclist = d, dl | ||||
def autoname(self): | |||||
self.set_fieldname() | |||||
self.doc.name = self.doc.dt + "-" + self.doc.fieldname | |||||
def set_fieldname(self): | def set_fieldname(self): | ||||
if not self.doc.fieldname: | if not self.doc.fieldname: | ||||
@@ -104,7 +108,7 @@ def get_fields_label(dt=None, form=1): | |||||
field_list = [cstr(d.fieldname) for d in docfields] | field_list = [cstr(d.fieldname) for d in docfields] | ||||
return idx_label_list, field_list | return idx_label_list, field_list | ||||
def delete_and_create_custom_field_if_values_exist(doctype, df): | |||||
def create_custom_field_if_values_exist(doctype, df): | |||||
df = webnotes._dict(df) | df = webnotes._dict(df) | ||||
if webnotes.conn.sql("""select count(*) from `tab{doctype}` | if webnotes.conn.sql("""select count(*) from `tab{doctype}` | ||||
where ifnull({fieldname},'')!=''""".format(doctype=doctype, fieldname=df.fieldname))[0][0]: | where ifnull({fieldname},'')!=''""".format(doctype=doctype, fieldname=df.fieldname))[0][0]: | ||||
@@ -2,12 +2,11 @@ | |||||
{ | { | ||||
"creation": "2013-01-10 16:34:01", | "creation": "2013-01-10 16:34:01", | ||||
"docstatus": 0, | "docstatus": 0, | ||||
"modified": "2013-07-05 14:33:59", | |||||
"modified": "2013-11-05 20:07:27", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"owner": "Administrator" | "owner": "Administrator" | ||||
}, | }, | ||||
{ | { | ||||
"autoname": "eval:doc.dt+\"-\"+doc.fieldname", | |||||
"description": "Adds a custom field to a DocType", | "description": "Adds a custom field to a DocType", | ||||
"doctype": "DocType", | "doctype": "DocType", | ||||
"icon": "icon-glass", | "icon": "icon-glass", | ||||
@@ -2,7 +2,7 @@ | |||||
{ | { | ||||
"creation": "2013-02-18 13:36:19", | "creation": "2013-02-18 13:36:19", | ||||
"docstatus": 0, | "docstatus": 0, | ||||
"modified": "2013-11-02 23:01:10", | |||||
"modified": "2013-11-05 20:09:08", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"owner": "Administrator" | "owner": "Administrator" | ||||
}, | }, | ||||
@@ -155,7 +155,7 @@ | |||||
"fieldtype": "Section Break" | "fieldtype": "Section Break" | ||||
}, | }, | ||||
{ | { | ||||
"description": "<a onclick=\"msgprint('<ol>\\\n<li><b>field:[fieldname]</b> - By Field\\\n<li><b>naming_series:</b> - By Naming Series (field called naming_series must be present\\\n<li><b>eval:[expression]</b> - Evaluate an expression in python (self is doc)\\\n<li><b>Prompt</b> - Prompt user for a name\\\n<li><b>[series]</b> - Series by prefix (separated by a dot); for example PRE.#####\\\n</ol>')\">Naming Options</a>", | |||||
"description": "<a onclick=\"msgprint('<ol>\\\n<li><b>field:[fieldname]</b> - By Field\\\n<li><b>naming_series:</b> - By Naming Series (field called naming_series must be present\\\n<li><b>Prompt</b> - Prompt user for a name\\\n<li><b>[series]</b> - Series by prefix (separated by a dot); for example PRE.#####\\\n</ol>')\">Naming Options</a>", | |||||
"doctype": "DocField", | "doctype": "DocField", | ||||
"fieldname": "autoname", | "fieldname": "autoname", | ||||
"fieldtype": "Data", | "fieldtype": "Data", | ||||
@@ -133,12 +133,12 @@ _f.Frm.prototype.field_map = function(fnames, fn) { | |||||
fnames = [fnames]; | fnames = [fnames]; | ||||
} | } | ||||
} | } | ||||
$.each(fnames, function(i,f) { | |||||
$.each(fnames, function(i,fieldname) { | |||||
//var field = cur_frm.fields_dict[f]; - much better design | //var field = cur_frm.fields_dict[f]; - much better design | ||||
var field = wn.meta.get_docfield(cur_frm.doctype, f, cur_frm.docname) | |||||
var field = wn.meta.get_docfield(cur_frm.doctype, fieldname, cur_frm.docname); | |||||
if(field) { | if(field) { | ||||
fn(field); | fn(field); | ||||
cur_frm.refresh_field(f); | |||||
cur_frm.refresh_field(fieldname); | |||||
}; | }; | ||||
}) | }) | ||||
@@ -147,8 +147,8 @@ wn.ui.form.ControlInput = wn.ui.form.Control.extend({ | |||||
} else { | } else { | ||||
this.$wrapper = $('<div class="form-horizontal">\ | this.$wrapper = $('<div class="form-horizontal">\ | ||||
<div class="form-group row" style="margin: 0px">\ | <div class="form-group row" style="margin: 0px">\ | ||||
<label class="control-label col-xs-'+(this.horizontal?"3":"12")+'" style="padding-right: 0px"></label>\ | |||||
<div class="col-xs-'+(this.horizontal?"9":"12")+'">\ | |||||
<label class="control-label small text-muted col-xs-'+(this.horizontal?"4":"12")+'" style="padding-right: 0px"></label>\ | |||||
<div class="col-xs-'+(this.horizontal?"8":"12")+'">\ | |||||
<div class="control-input"></div>\ | <div class="control-input"></div>\ | ||||
<div class="control-value like-disabled-input" style="display: none;"></div>\ | <div class="control-value like-disabled-input" style="display: none;"></div>\ | ||||
<p class="help-box small text-muted"></p>\ | <p class="help-box small text-muted"></p>\ | ||||
@@ -450,13 +450,13 @@ wn.ui.form.ControlCheck = wn.ui.form.ControlData.extend({ | |||||
input_type: "checkbox", | input_type: "checkbox", | ||||
make_wrapper: function() { | make_wrapper: function() { | ||||
this.$wrapper = $('<div class="form-group row">\ | this.$wrapper = $('<div class="form-group row">\ | ||||
<div class="col-md-offset-3 col-md-9">\ | |||||
<div class="checkbox">\ | |||||
<div class="col-md-offset-4 col-md-8">\ | |||||
<div class="checkbox" style="margin: 5px 0px">\ | |||||
<label class="input-area">\ | <label class="input-area">\ | ||||
<span class="disp-area" style="display:none;"></span>\ | <span class="disp-area" style="display:none;"></span>\ | ||||
<span class="label-area"></span>\ | |||||
<span class="label-area small text-muted"></span>\ | |||||
</label>\ | </label>\ | ||||
<p class="help-box small text-muted"> </p>\ | |||||
<p class="help-box small text-muted"></p>\ | |||||
</div>\ | </div>\ | ||||
</div>\ | </div>\ | ||||
</div>').appendTo(this.parent) | </div>').appendTo(this.parent) | ||||
@@ -697,9 +697,10 @@ wn.ui.form.ControlSelect = wn.ui.form.ControlData.extend({ | |||||
wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({ | wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({ | ||||
make_input: function() { | make_input: function() { | ||||
var me = this; | var me = this; | ||||
$('<div class="link-field">\ | |||||
<input type="text" class="input-with-feedback form-control" style="width: 80%; display: inline-block">\ | |||||
<span class="link-field-btn">\ | |||||
$('<div class="link-field" style="display: table; width: 100%;">\ | |||||
<input type="text" class="input-with-feedback form-control" \ | |||||
style="display: table-cell">\ | |||||
<span class="link-field-btn" style="display: table-cell">\ | |||||
<a class="btn-search" title="Search Link">\ | <a class="btn-search" title="Search Link">\ | ||||
<i class="icon-search"></i>\ | <i class="icon-search"></i>\ | ||||
</a><a class="btn-open" title="Open Link">\ | </a><a class="btn-open" title="Open Link">\ | ||||
@@ -199,7 +199,7 @@ $.extend(wn.perm, { | |||||
} | } | ||||
if(explain) console.log("By Read Only:" + ret) | if(explain) console.log("By Read Only:" + ret) | ||||
return ret; | return ret; | ||||
} | } |
@@ -36,8 +36,7 @@ bsEditor = Class.extend({ | |||||
}).data("object", this); | }).data("object", this); | ||||
this.bind_hotkeys(); | this.bind_hotkeys(); | ||||
this.init_file_drops(); | |||||
this.init_file_drops(); | |||||
}, | }, | ||||
set_editing: function() { | set_editing: function() { | ||||
@@ -56,7 +55,7 @@ bsEditor = Class.extend({ | |||||
this.toolbar = window.bs_editor_toolbar; | this.toolbar = window.bs_editor_toolbar; | ||||
}, | }, | ||||
setup_inline_toolbar: function() { | setup_inline_toolbar: function() { | ||||
this.toolbar = new bsEditorToolbar(this.options, this.wrapper); | |||||
this.toolbar = new bsEditorToolbar(this.options, this.wrapper, this.editor); | |||||
}, | }, | ||||
onhide: function(action) { | onhide: function(action) { | ||||
this.editing = false; | this.editing = false; | ||||
@@ -193,8 +192,9 @@ bsEditor = Class.extend({ | |||||
}) | }) | ||||
bsEditorToolbar = Class.extend({ | bsEditorToolbar = Class.extend({ | ||||
init: function(options, parent) { | |||||
init: function(options, parent, editor) { | |||||
this.options = options; | this.options = options; | ||||
this.editor = editor; | |||||
this.inline = !!parent; | this.inline = !!parent; | ||||
this.options.toolbar_style = $.extend((this.inline ? this.inline_style : this.fixed_style), | this.options.toolbar_style = $.extend((this.inline ? this.inline_style : this.fixed_style), | ||||
this.options.toolbar_style || {}); | this.options.toolbar_style || {}); | ||||
@@ -330,7 +330,8 @@ bsEditorToolbar = Class.extend({ | |||||
me.execCommand($(this).data(me.options.command_role)); | me.execCommand($(this).data(me.options.command_role)); | ||||
me.save_selection(); | me.save_selection(); | ||||
// close dropdown | // close dropdown | ||||
me.toolbar.find('[data-toggle="dropdown"]').dropdown("toggle"); | |||||
if(me.toolbar.find("ul.dropdown-menu:visible").length) | |||||
me.toolbar.find('[data-toggle="dropdown"]').dropdown("toggle"); | |||||
return false; | return false; | ||||
}); | }); | ||||
this.toolbar.find('[data-toggle=dropdown]').click(function() { me.restore_selection() }); | this.toolbar.find('[data-toggle=dropdown]').click(function() { me.restore_selection() }); | ||||
@@ -272,12 +272,7 @@ class Document: | |||||
if not self.naming_series: | if not self.naming_series: | ||||
webnotes.msgprint(webnotes._("Naming Series mandatory"), raise_exception=True) | webnotes.msgprint(webnotes._("Naming Series mandatory"), raise_exception=True) | ||||
self.name = make_autoname(self.naming_series+'.#####') | self.name = make_autoname(self.naming_series+'.#####') | ||||
# based on expression | |||||
elif autoname and autoname.startswith('eval:'): | |||||
doc = self # for setting | |||||
self.name = eval(autoname[5:]) | |||||
# call the method! | # call the method! | ||||
elif autoname and autoname!='Prompt': | elif autoname and autoname!='Prompt': | ||||
self.name = make_autoname(autoname, self.doctype) | self.name = make_autoname(autoname, self.doctype) | ||||