Merge branch 'edge' of github.com:webnotes/wnframework into edge
This commit is contained in:
commit
3d53d7a59d
14 changed files with 81 additions and 57 deletions
|
|
@ -10,7 +10,7 @@ wn.pages['data-import-tool'].onload = function(wrapper) {
|
|||
<p class="float-column">\
|
||||
<select style="width: 200px" name="dit-doctype">\
|
||||
</select><br><br>\
|
||||
<input type="checkbox" name="dit-with-data">\
|
||||
<input type="checkbox" name="dit-with-data" style="margin-top: -3px">\
|
||||
<span> Download with data</span>\
|
||||
</p>\
|
||||
<p class="float-column" id="dit-download"></p>\
|
||||
|
|
@ -141,12 +141,14 @@ wn.pages['data-import-tool'].onload = function(wrapper) {
|
|||
});
|
||||
|
||||
// add overwrite option
|
||||
$('<input type="checkbox" name="overwrite"><span> Overwrite</span>\
|
||||
$('<input type="checkbox" name="overwrite" style="margin-top: -3px">\
|
||||
<span> Overwrite</span>\
|
||||
<p class="help">If you are uploading a child table (for example Item Price), the all the entries of that table will be deleted (for that parent record) and new entries will be made.</p><br>')
|
||||
.insertBefore('#dit-upload-area form input[type="submit"]')
|
||||
|
||||
// add ignore option
|
||||
$('<input type="checkbox" name="ignore_encoding_errors"><span> Ignore Encoding Errors</span><br><br>')
|
||||
$('<input type="checkbox" name="ignore_encoding_errors" style="margin-top: -3px">\
|
||||
<span> Ignore Encoding Errors</span><br><br>')
|
||||
.insertBefore('#dit-upload-area form input[type="submit"]')
|
||||
|
||||
// rename button
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ function is_null(v) {
|
|||
}
|
||||
|
||||
function set_value_in(ele, v, ftype, fopt, doc) {
|
||||
$(ele).html(wn.format(v, {fieldtype:ftype, options:fopt}, doc));
|
||||
$(ele).html(wn.format(v, {fieldtype:ftype, options:fopt}, null, doc));
|
||||
return;
|
||||
}
|
||||
var $s = set_value_in; // used in print formats
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ function makeselector() {
|
|||
var l = $a($a(div,'div'),'span','link_type');
|
||||
l.innerHTML = r.values[i][0];
|
||||
l.link_name = r.values[i][0];
|
||||
l.dt = r.coloptions[0];
|
||||
l.dt = r.coloptions && r.coloptions[0];
|
||||
|
||||
if(d.input)
|
||||
l.onclick = function() { setlinkvalue(this.link_name); }
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ Field.prototype.set_description = function(txt) {
|
|||
}
|
||||
}
|
||||
|
||||
Field.prototype.get_status = function() {
|
||||
Field.prototype.get_status = function(explain) {
|
||||
// if used in filters
|
||||
if(this.in_filter)
|
||||
this.not_in_form = this.in_filter;
|
||||
|
|
@ -150,16 +150,22 @@ Field.prototype.get_status = function() {
|
|||
else
|
||||
ret='None';
|
||||
|
||||
if(explain) console.log("By Permission:" + ret)
|
||||
|
||||
// hidden
|
||||
if(cint(this.df.hidden)) {
|
||||
ret = 'None';
|
||||
}
|
||||
|
||||
if(explain) console.log("By Hidden:" + ret)
|
||||
|
||||
// for submit
|
||||
if(ret=='Write' && cint(cur_frm.doc.docstatus) > 0) {
|
||||
ret = 'Read';
|
||||
}
|
||||
|
||||
if(explain) console.log("By Submit:" + ret)
|
||||
|
||||
// allow on submit
|
||||
var a_o_s = cint(this.df.allow_on_submit);
|
||||
|
||||
|
|
@ -172,12 +178,16 @@ Field.prototype.get_status = function() {
|
|||
a_o_s = _f.cur_grid.field.df.allow_on_submit;
|
||||
}
|
||||
}
|
||||
|
||||
if(explain) console.log("Allow on Submit:" + a_o_s)
|
||||
|
||||
if(ret=="Read" && a_o_s && cint(cur_frm.doc.docstatus)==1 &&
|
||||
cur_frm.perm[this.df.permlevel][WRITE]) {
|
||||
ret='Write';
|
||||
}
|
||||
|
||||
if(explain) console.log("By Allow on Submt:" + ret)
|
||||
|
||||
// workflow state
|
||||
if(ret=="Write" && cur_frm && cur_frm.state_fieldname) {
|
||||
if(cint(cur_frm.read_only)) {
|
||||
|
|
@ -189,13 +199,17 @@ Field.prototype.get_status = function() {
|
|||
ret = 'Read';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(explain) console.log("By Workflow:" + ret)
|
||||
|
||||
// make a field read_only if read_only
|
||||
// is checked (disregards write permission)
|
||||
if(ret=="Write" && cint(this.df.read_only)) {
|
||||
ret = "Read";
|
||||
}
|
||||
|
||||
if(explain) console.log("By Read Only:" + ret)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -862,7 +876,7 @@ FloatField.prototype.onmake_input = function() {
|
|||
}
|
||||
}
|
||||
FloatField.prototype.set_disp = function(val) {
|
||||
this.set_disp_html(wn.format(val, this.df, locals[this.doctype][this.name]));
|
||||
this.set_disp_html(wn.format(val, this.df, null, locals[this.doctype][this.name]));
|
||||
}
|
||||
|
||||
function PercentField() { } PercentField.prototype = new FloatField();
|
||||
|
|
|
|||
|
|
@ -429,7 +429,8 @@ _f.Grid.prototype.notify_keypress = function(e, keycode) {
|
|||
}
|
||||
|
||||
_f.Grid.prototype.make_template = function(hc) {
|
||||
hc.template = make_field(wn.meta.get_docfield(hc.doctype, hc.fieldname), hc.doctype, '', this.field.frm, true);
|
||||
hc.template = make_field(wn.meta.get_docfield(hc.doctype, hc.fieldname), hc.doctype,
|
||||
'', this.field.frm, true);
|
||||
hc.template.grid = this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ wn.form.formatters = {
|
|||
Percent: function(value) {
|
||||
return cint(value) + "%";
|
||||
},
|
||||
Currency: function(value, docfield, doc) {
|
||||
Currency: function(value, docfield, options, doc) {
|
||||
var currency = wn.meta.get_field_currency(docfield, doc);
|
||||
return "<div style='text-align: right'>" + format_currency(value, currency) + "</div>";
|
||||
},
|
||||
|
|
@ -95,7 +95,7 @@ wn.form.get_formatter = function(fieldtype) {
|
|||
return wn.form.formatters[fieldtype.replace(/ /g, "")] || wn.form.formatters.Data;
|
||||
}
|
||||
|
||||
wn.format = function(value, df, options) {
|
||||
wn.format = function(value, df, options, doc) {
|
||||
if(!df) df = {"fieldtype":"Data"};
|
||||
return wn.form.get_formatter(df.fieldtype)(value, df, options);
|
||||
return wn.form.get_formatter(df.fieldtype)(value, df, options, doc);
|
||||
}
|
||||
|
|
@ -116,6 +116,10 @@ $.extend(wn.meta, {
|
|||
var options = df.options.split(":");
|
||||
if(options.length==3) {
|
||||
// get reference record e.g. Company
|
||||
var docname = doc[options[1]];
|
||||
if(!docname) {
|
||||
docname = cur_frm.doc[options[1]]
|
||||
}
|
||||
currency = wn.model.get_value(options[0], doc[options[1]],
|
||||
options[2]) || currency;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ wn.views.ListView = Class.extend({
|
|||
}
|
||||
else if(data[opts.content]) {
|
||||
$("<span>")
|
||||
.html(wn.format(data[opts.content], opts.df, data))
|
||||
.html(wn.format(data[opts.content], opts.df, null, data))
|
||||
.appendTo(parent)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,12 +103,14 @@ wn.views.moduleview.ModuleView = Class.extend({
|
|||
|
||||
// doctype permissions
|
||||
if(item.doctype && !wn.model.can_read(item.doctype)) {
|
||||
item.link = item.label;
|
||||
//item.link = item.label;
|
||||
return;
|
||||
}
|
||||
|
||||
// page permissions
|
||||
if(item.page && !in_list(wn.boot.allowed_pages, item.page)) {
|
||||
item.link = item.label;
|
||||
//item.link = item.label;
|
||||
return;
|
||||
}
|
||||
|
||||
if((item.country && wn.boot.control_panel.country==item.country)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ wn.views.ReportView = wn.ui.Listing.extend({
|
|||
width: (docfield ? cint(docfield.width) : 120) || 120,
|
||||
formatter: function(row, cell, value, columnDef, dataContext) {
|
||||
var docfield = columnDef.docfield;
|
||||
return wn.format(value, docfield, dataContext);
|
||||
return wn.format(value, docfield, null, dataContext);
|
||||
}
|
||||
}
|
||||
return coldef;
|
||||
|
|
|
|||
|
|
@ -126,6 +126,9 @@ class Database:
|
|||
else:
|
||||
return self._cursor.fetchall()
|
||||
|
||||
def sql_list(self, query, values=()):
|
||||
return [r[0] for r in self.sql(query, values)]
|
||||
|
||||
def check_transaction_status(self, query):
|
||||
if self.in_transaction and query and query.strip().split()[0].lower() in ['start', 'alter', 'drop', 'create']:
|
||||
raise Exception, 'This statement can cause implicit commit'
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type_map = {
|
|||
'currency': ('decimal', '18,6')
|
||||
,'int': ('int', '11')
|
||||
,'float': ('decimal', '18,6')
|
||||
,'percent': ('decimal', '9,6')
|
||||
,'percent': ('decimal', '18,6')
|
||||
,'check': ('int', '1')
|
||||
,'small text': ('text', '')
|
||||
,'long text': ('longtext', '')
|
||||
|
|
@ -264,10 +264,19 @@ class DbColumn:
|
|||
self.table.add_index.append(self)
|
||||
|
||||
# default
|
||||
if (self.default and (current_def['default'] != self.default) and (self.default not in default_shortcuts) and not (column_def in ['text','blob'])):
|
||||
if (self.default and self.default_changed(current_def) and (self.default not in default_shortcuts) and not (column_def in ['text','blob'])):
|
||||
self.table.set_default.append(self)
|
||||
|
||||
|
||||
def default_changed(self, current_def):
|
||||
if "decimal" in current_def['type']:
|
||||
try:
|
||||
return float(current_def['default'])!=float(self.default)
|
||||
except TypeError, e:
|
||||
return True
|
||||
else:
|
||||
return current_def['default'] != self.default
|
||||
|
||||
class DbManager:
|
||||
"""
|
||||
Basically, a wrapper for oft-used mysql commands. like show tables,databases, variables etc...
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
# Search
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
import webnotes.widgets.query_builder
|
||||
from webnotes.utils import cstr
|
||||
from startup.query_handlers import standard_queries
|
||||
|
||||
# this is called when a new doctype is setup for search - to set the filters
|
||||
@webnotes.whitelist()
|
||||
|
|
@ -49,6 +52,30 @@ def getsearchfields():
|
|||
|
||||
webnotes.response['searchfields'] = [['name', 'ID', 'Data', '']] + res
|
||||
|
||||
# this is called by the Link Field
|
||||
@webnotes.whitelist()
|
||||
def search_link(dt, txt, query=None):
|
||||
search_widget(dt, txt, query, page_len=10)
|
||||
webnotes.response['results'] = build_for_autosuggest(webnotes.response["values"])
|
||||
|
||||
# this is called by the search box
|
||||
@webnotes.whitelist()
|
||||
def search_widget(doctype, txt, query=None, searchfield="name", start=0, page_len=50):
|
||||
if query and query.split()[0].lower()!="select":
|
||||
webnotes.response["values"] = webnotes.get_method(query)(doctype, txt,
|
||||
searchfield, start, page_len)
|
||||
elif not query and doctype in standard_queries:
|
||||
search_widget(doctype, txt, standard_queries[doctype], searchfield, start, page_len)
|
||||
else:
|
||||
if query:
|
||||
webnotes.response["values"] = webnotes.conn.sql(scrub_custom_query(query,
|
||||
searchfield, txt))
|
||||
else:
|
||||
query = make_query(', '.join(get_std_fields_list(doctype, searchfield)), doctype,
|
||||
searchfield, txt, start, page_len)
|
||||
|
||||
webnotes.widgets.query_builder.runquery(query)
|
||||
|
||||
def make_query(fields, dt, key, txt, start, length):
|
||||
doctype = webnotes.get_doctype(dt)
|
||||
|
||||
|
|
@ -86,10 +113,7 @@ def get_std_fields_list(dt, key):
|
|||
return ['`tab%s`.`%s`' % (dt, f.strip()) for f in sflist]
|
||||
|
||||
def build_for_autosuggest(res):
|
||||
from webnotes.utils import cstr
|
||||
|
||||
results = []
|
||||
|
||||
for r in res:
|
||||
info = ''
|
||||
if len(r) > 1:
|
||||
|
|
@ -105,39 +129,4 @@ def scrub_custom_query(query, key, txt):
|
|||
query = query.replace('%(key)s', key)
|
||||
if '%s' in query:
|
||||
query = query.replace('%s', ((txt or '') + '%'))
|
||||
return query
|
||||
|
||||
# this is called by the Link Field
|
||||
@webnotes.whitelist()
|
||||
def search_link():
|
||||
import webnotes.widgets.query_builder
|
||||
|
||||
txt = webnotes.form_dict.get('txt')
|
||||
dt = webnotes.form_dict.get('dt')
|
||||
query = webnotes.form_dict.get('query')
|
||||
|
||||
if query:
|
||||
res = webnotes.conn.sql(scrub_custom_query(query, 'name', txt))
|
||||
else:
|
||||
q = make_query(', '.join(get_std_fields_list(dt, 'name')), dt, 'name', txt, '0', '10')
|
||||
res = webnotes.widgets.query_builder.runquery(q, ret=1)
|
||||
|
||||
# make output
|
||||
webnotes.response['results'] = build_for_autosuggest(res)
|
||||
|
||||
# this is called by the search box
|
||||
@webnotes.whitelist()
|
||||
def search_widget():
|
||||
import webnotes.widgets.query_builder
|
||||
|
||||
dt = webnotes.form_dict.get('doctype')
|
||||
txt = webnotes.form_dict.get('txt') or ''
|
||||
key = webnotes.form_dict.get('searchfield') or 'name' # key field
|
||||
user_query = webnotes.form_dict.get('query') or ''
|
||||
|
||||
if user_query:
|
||||
query = scrub_custom_query(user_query, key, txt)
|
||||
else:
|
||||
query = make_query(', '.join(get_std_fields_list(dt, key)), dt, key, txt, webnotes.form_dict.get('start') or 0, webnotes.form_dict.get('page_len') or 50)
|
||||
|
||||
webnotes.widgets.query_builder.runquery(query)
|
||||
return query
|
||||
Loading…
Add table
Reference in a new issue