Merge branch 'responsive' of github.com:webnotes/wnframework into responsive

Conflicts:
	webnotes/model/mapper.py
This commit is contained in:
Anand Doshi 2013-07-10 20:55:05 +05:30
commit 20dce362d8
25 changed files with 184 additions and 80 deletions

View file

@ -1,22 +1,21 @@
cur_frm.cscript.onload = function(doc) {
cur_frm.fields_dict.user.get_query = function() {
return "select name, concat_ws(' ', first_name, middle_name, last_name) \
from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
(%(key)s like \"%s\" or \
concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
limit 50";
return {
query: "core.doctype.communication.communication.get_user"
}
};
cur_frm.fields_dict.lead.get_query = function() {
return "select name, lead_name from `tabLead` \
where docstatus < 2 and \
(%(key)s like \"%s\" or lead_name like \"%%%s\" or \
company_name like \"%%%s\") \
order by lead_name asc limit 50";
return {
query: "core.doctype.communication.communication.get_user"
}
};
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{ query:"controllers.queries.customer_query" } }
cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) {
return{ query:"controllers.queries.supplier_query" } }
if(doc.content)
doc.content = wn.utils.escape_script_and_style(doc.content);

View file

@ -119,3 +119,29 @@ class DocType():
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
def get_user(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql("""select name, concat_ws(' ', first_name, middle_name, last_name)
from `tabProfile`
where ifnull(enabled, 0)=1
and docstatus < 2
and (%(key)s like "%(txt)s"
or concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s")
%(mcond)s
limit %(start)s, %(page_len)s """ % {'key': searchfield,
'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})
def get_lead(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql(""" select name, lead_name from `tabLead`
where docstatus < 2
and (%(key)s like "%(txt)s"
or lead_name like "%(txt)s"
or company_name like "%(txt)s")
%(mcond)s
order by lead_name asc
limit %(start)s, %(page_len)s """ % {'key': searchfield,'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield), 'start': start,
'page_len': page_len})

View file

@ -55,10 +55,12 @@ cur_frm.cscript.label = function(doc){
cur_frm.fields_dict['dt'].get_query = function(doc, dt, dn) {
return 'SELECT name FROM `tabDocType` \
WHERE IFNULL(issingle,0)=0 AND \
module != "Core" AND \
name LIKE "%s%%" ORDER BY name ASC LIMIT 50';
return{
filters:[
['DocType', 'issingle', '=', 0],
['DocType', 'module', '!=', 'Core']
]
}
}
cur_frm.cscript.fieldtype = function(doc, dt, dn) {

View file

@ -42,13 +42,14 @@ cur_frm.cscript.onload = function(doc, dt, dn) {
}
cur_frm.fields_dict.doc_type.get_query = function(doc, dt, dn) {
return 'SELECT name FROM `tabDocType` \
WHERE ((IFNULL(issingle,0)=0 AND \
IFNULL(in_create, 0)=0 AND \
name not in ("DocType", "DocField", "DocPerm", "Profile", "Role", "UserRole", "Page", \
"Page Role", "Module Def", "Print Format", "Report")) \
or name = "Item Group") \
AND name LIKE "%s%%" ORDER BY name ASC LIMIT 50';
return{
filters:[
['DocType', 'issingle', '=', 0],
['DocType', 'in_create', '=', 0],
['DocType', 'name', 'not in', 'DocType, DocField, DocPerm, Profile, Role, UserRole,\
Page, Page Role, Module Def, Print Format, Report']
]
}
}
cur_frm.cscript.refresh = function(doc, dt, dn) {

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:32",
"docstatus": 0,
"modified": "2013-03-07 07:03:19",
"modified": "2013-07-10 14:54:06",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -37,6 +37,7 @@
"fieldname": "label",
"fieldtype": "Data",
"hidden": 0,
"in_list_view": 1,
"label": "Label",
"oldfieldname": "label",
"oldfieldtype": "Data",
@ -49,6 +50,7 @@
"fieldname": "fieldtype",
"fieldtype": "Select",
"hidden": 0,
"in_list_view": 1,
"label": "Type",
"oldfieldname": "fieldtype",
"oldfieldtype": "Select",
@ -62,6 +64,7 @@
"fieldname": "fieldname",
"fieldtype": "Data",
"hidden": 0,
"in_list_view": 1,
"label": "Name",
"oldfieldname": "fieldname",
"oldfieldtype": "Data",
@ -76,6 +79,7 @@
"fieldname": "options",
"fieldtype": "Text",
"hidden": 0,
"in_list_view": 1,
"label": "Options",
"oldfieldname": "options",
"oldfieldtype": "Text",
@ -89,6 +93,7 @@
"fieldname": "permlevel",
"fieldtype": "Int",
"hidden": 0,
"in_list_view": 1,
"label": "Perm Level",
"oldfieldname": "permlevel",
"oldfieldtype": "Int",
@ -101,6 +106,7 @@
"fieldname": "width",
"fieldtype": "Data",
"hidden": 0,
"in_list_view": 1,
"label": "Width",
"oldfieldname": "width",
"oldfieldtype": "Data",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:32",
"docstatus": 0,
"modified": "2013-03-07 07:03:20",
"modified": "2013-07-10 14:54:07",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -15,6 +15,7 @@
{
"doctype": "DocField",
"fieldtype": "Link",
"in_list_view": 1,
"name": "__common__",
"oldfieldtype": "Link",
"parent": "Default Home Page",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:32",
"docstatus": 0,
"modified": "2013-03-07 07:03:20",
"modified": "2013-07-10 14:54:07",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -23,6 +23,7 @@
{
"doctype": "DocField",
"hidden": 0,
"in_list_view": 1,
"name": "__common__",
"parent": "DefaultValue",
"parentfield": "fields",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:33",
"docstatus": 0,
"modified": "2013-07-03 10:03:56",
"modified": "2013-07-10 14:54:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -38,6 +38,7 @@
"fieldname": "label",
"fieldtype": "Data",
"hidden": 0,
"in_list_view": 1,
"label": "Label",
"oldfieldname": "label",
"oldfieldtype": "Data",
@ -51,6 +52,7 @@
"fieldname": "fieldtype",
"fieldtype": "Select",
"hidden": 0,
"in_list_view": 1,
"label": "Type",
"oldfieldname": "fieldtype",
"oldfieldtype": "Select",
@ -63,6 +65,7 @@
"fieldname": "fieldname",
"fieldtype": "Data",
"hidden": 0,
"in_list_view": 1,
"label": "Name",
"oldfieldname": "fieldname",
"oldfieldtype": "Data",
@ -75,6 +78,7 @@
"fieldname": "options",
"fieldtype": "Text",
"hidden": 0,
"in_list_view": 1,
"label": "Options",
"oldfieldname": "options",
"oldfieldtype": "Text",
@ -86,6 +90,7 @@
"fieldname": "reqd",
"fieldtype": "Check",
"hidden": 0,
"in_list_view": 1,
"label": "Mandatory",
"oldfieldname": "reqd",
"oldfieldtype": "Check",
@ -98,6 +103,7 @@
"doctype": "DocField",
"fieldname": "description",
"fieldtype": "Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Text",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:33",
"docstatus": 0,
"modified": "2013-03-07 07:03:20",
"modified": "2013-07-10 14:54:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -38,6 +38,7 @@
"fieldname": "permlevel",
"fieldtype": "Int",
"hidden": 0,
"in_list_view": 1,
"label": "Level",
"oldfieldname": "permlevel",
"oldfieldtype": "Int",
@ -51,6 +52,7 @@
"fieldname": "role",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 1,
"label": "Role",
"oldfieldname": "role",
"oldfieldtype": "Link",
@ -65,6 +67,7 @@
"fieldname": "read",
"fieldtype": "Check",
"hidden": 0,
"in_list_view": 1,
"label": "Read",
"oldfieldname": "read",
"oldfieldtype": "Check",
@ -78,6 +81,7 @@
"fieldname": "write",
"fieldtype": "Check",
"hidden": 0,
"in_list_view": 1,
"label": "Write",
"oldfieldname": "write",
"oldfieldtype": "Check",
@ -91,6 +95,7 @@
"fieldname": "create",
"fieldtype": "Check",
"hidden": 0,
"in_list_view": 1,
"label": "Create",
"oldfieldname": "create",
"oldfieldtype": "Check",
@ -104,6 +109,7 @@
"fieldname": "submit",
"fieldtype": "Check",
"hidden": 0,
"in_list_view": 1,
"label": "Submit",
"oldfieldname": "submit",
"oldfieldtype": "Check",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:33",
"docstatus": 0,
"modified": "2013-03-07 07:03:21",
"modified": "2013-07-10 14:54:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -17,6 +17,7 @@
"doctype": "DocField",
"fieldname": "role",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Role",
"name": "__common__",
"oldfieldname": "role",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:33",
"docstatus": 0,
"modified": "2013-03-07 07:03:21",
"modified": "2013-07-10 14:54:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -17,6 +17,7 @@
"doctype": "DocField",
"fieldname": "person",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Person",
"name": "__common__",
"oldfieldname": "person",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:34",
"docstatus": 0,
"modified": "2013-03-07 07:03:26",
"modified": "2013-07-10 14:54:11",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -25,6 +25,7 @@
"fieldname": "role",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 1,
"label": "Role",
"name": "__common__",
"oldfieldname": "role",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-06 11:30:13",
"docstatus": 0,
"modified": "2013-02-13 07:51:57",
"modified": "2013-07-10 14:54:25",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -25,6 +25,7 @@
"fieldname": "role",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 1,
"label": "Role",
"name": "__common__",
"oldfieldname": "role",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:36",
"docstatus": 0,
"modified": "2013-03-07 07:03:34",
"modified": "2013-07-10 14:54:25",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -16,6 +16,7 @@
},
{
"doctype": "DocField",
"in_list_view": 1,
"name": "__common__",
"parent": "Workflow Document State",
"parentfield": "fields",

View file

@ -2,7 +2,7 @@
{
"creation": "2013-02-22 01:27:36",
"docstatus": 0,
"modified": "2013-03-07 07:03:34",
"modified": "2013-07-10 14:54:25",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -16,6 +16,7 @@
{
"doctype": "DocField",
"fieldtype": "Link",
"in_list_view": 1,
"name": "__common__",
"parent": "Workflow Transition",
"parentfield": "fields",

View file

@ -395,6 +395,10 @@ textarea[data-fieldtype="Small Text"] {
cursor: pointer;
}
.grid-row .panel {
background-color: #fffff8;
}
/* form footer */
.form-footer {

View file

@ -655,7 +655,7 @@ wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({
source: function(request, response) {
var args = {
'txt': request.term,
'dt': me.df.options,
'doctype': me.df.options,
};
me.set_custom_query(args);

View file

@ -174,6 +174,12 @@ wn.ui.form.GridRow = Class.extend({
</div>\
</div>\
<div class="form-area"></div>\
<div class="toolbar footer-toolbar" style="height: 36px;">\
<button class="btn btn-success pull-right" \
title="'+wn._("Close")+'"\
style="margin-left: 7px;">\
<i class="icon-chevron-up"></i></button>\
</div>\
</div>\
<div class="divider row"></div>\
</div>')
@ -203,7 +209,12 @@ wn.ui.form.GridRow = Class.extend({
},
set_button_events: function() {
var me = this;
this.wrapper.find(".btn-success").click(function() {
me.toggle_view();
return false;
});
this.wrapper.find(".btn-danger").click(function() {
me.wrapper.fadeOut(function() {
wn.model.clear_doc(me.doc.doctype, me.doc.name);
@ -241,12 +252,12 @@ wn.ui.form.GridRow = Class.extend({
col = $('<div class="col col-lg-1 row-index">' + (me.doc ? me.doc.idx : "#")+ '</div>')
.appendTo(me.row)
$.each(me.docfields, function(ci, df) {
if(!df.hidden && !df.print_hide && me.grid.frm.perm[df.permlevel][READ]
if(!df.hidden && df.in_list_view && me.grid.frm.perm[df.permlevel][READ]
&& !in_list(["Section Break", "Column Break"], df.fieldtype)) {
var colsize = 2,
txt = me.doc ?
wn.format(me.doc[df.fieldname], df, null, me.doc) :
df.label;
wn._(df.label);
switch(df.fieldtype) {
case "Text":
colsize = 3;
@ -254,6 +265,8 @@ wn.ui.form.GridRow = Class.extend({
case "Check":
colsize = 1;
break;
case "Select":
txt = wn._(txt)
}
total_colsize += colsize
if(total_colsize > 12)
@ -323,11 +336,13 @@ wn.ui.form.GridRow = Class.extend({
render_form: function() {
var me = this,
make_row = function(label) {
var row = $('<div class="row">').appendTo(me.form_area);
if(label)
$('<div class="col col-lg-12"><h4>'+ label +'</h4></div>')
.appendTo(row);
$('<div><h4><b>'+ label +'</b></h4><hr></div>')
.appendTo(me.form_area);
var row = $('<div class="row">')
.css({"padding": "0px 15px"})
.appendTo(me.form_area);
var col1 = $('<div class="col col-lg-6"></div>').appendTo(row),
col2 = $('<div class="col col-lg-6"></div>').appendTo(row);
@ -342,6 +357,7 @@ wn.ui.form.GridRow = Class.extend({
if(df.fieldtype=="Section Break") {
cols = make_row(df.label);
cnt = 0;
return;
}
var fieldwrapper = $('<div>')
.appendTo(cols[cnt % 2])
@ -367,6 +383,8 @@ wn.ui.form.GridRow = Class.extend({
this.wrapper.find(".btn-danger, .grid-insert-row").toggle(false);
}
this.wrapper.find(".footer-toolbar").toggle(me.fields.length > 6);
this.grid.open_grid_row = this;
},
set_data: function() {

View file

@ -80,7 +80,7 @@ wn.ui.form.Layout = Class.extend({
$('<h3 class="col col-lg-12">'
+ (df.options ? (' <i class="text-muted '+df.options+'"></i> ') : "")
+ '<span class="section-count-label">' + this.labelled_section_count + "</span>. "
+ df.label
+ wn._(df.label)
+ "</h3>")
.css({
"font-weight": "bold",
@ -131,14 +131,14 @@ wn.ui.form.Layout = Class.extend({
doctype = current.attr("data-doctype"),
fieldname = current.attr("data-fieldname");
if(doctype)
return me.handle_tab(doctype, fieldname);
return me.handle_tab(doctype, fieldname, ev.shiftKey);
}
})
},
handle_tab: function(doctype, fieldname) {
handle_tab: function(doctype, fieldname, shift) {
var me = this,
grid_row = null;
next = null,
prev = null,
fields = me.frm.fields,
in_grid = false;
@ -150,6 +150,14 @@ wn.ui.form.Layout = Class.extend({
for(var i=0, len=fields.length; i < len; i++) {
if(fields[i].df.fieldname==fieldname) {
if(shift) {
if(prev) {
this.set_focus(prev)
} else {
$(cur_frm.wrapper).find(".btn-primary").focus();
}
break;
}
if(i==len-1) {
// last field in this group
if(grid_row) {
@ -164,7 +172,7 @@ wn.ui.form.Layout = Class.extend({
grid_row.grid.grid_rows[grid_row.doc.idx].toggle_view(true);
}
} else {
// last field - to title buttons
$(cur_frm.wrapper).find(".btn-primary").focus();
}
} else {
me.focus_on_next_field(i, fields);
@ -172,33 +180,36 @@ wn.ui.form.Layout = Class.extend({
break;
}
if(fields[i].disp_status==="Write")
prev = fields[i];
}
return false;
},
focus_on_next_field: function(start_idx, fields) {
// loop to find next eligible fields
for(var ii= start_idx + 1, len = fields.length; ii < len; ii++) {
if(fields[ii].disp_status=="Write") {
var next = fields[ii];
// next is table, show the table
if(next.df.fieldtype=="Table") {
if(!next.grid.grid_rows.length) {
next.grid.add_new_row(1);
} else {
next.grid.grid_rows[0].toggle_view(true);
}
}
else if(next.editor) {
next.editor.set_focus();
}
else if(next.$input) {
next.$input.focus();
}
if(fields[ii].disp_status==="Write") {
this.set_focus(fields[ii]);
break;
}
}
},
set_focus: function(field) {
// next is table, show the table
if(field.df.fieldtype=="Table") {
if(!field.grid.grid_rows.length) {
field.grid.add_new_row(1);
} else {
field.grid.grid_rows[0].toggle_view(true);
}
}
else if(field.editor) {
field.editor.set_focus();
}
else if(field.$input) {
field.$input.focus();
}
},
get_open_grid_row: function() {
return $(".grid-row-open").data("grid_row");
},

View file

@ -61,7 +61,7 @@ wn.ui.form.LinkSelector = Class.extend({
var args = {
txt: this.dialog.fields_dict.txt.get_value(),
doctype: this.doctype,
searchfield: this.dialog.fields_dict.search_field.get_value()
searchfield: this.dialog.fields_dict.search_field.get_value() || "name"
},
me = this;

View file

@ -4,7 +4,7 @@
{% block content %}
<div class="content">
<div class="layout-wrapper layout-main">
<div class="layout-wrapper layout-main col col-lg-12">
<h3><i class="icon-exclamation-sign"></i> Page missing or moved</h3>
<br>
<p>We are very sorry for this, but the page you are looking for is missing

View file

@ -245,13 +245,16 @@ def get_roles(user=None, with_standard=True):
return roles
def has_permission(doctype, ptype="read", doc=None):
def has_permission(doctype, ptype="read", refdoc=None):
"""check if user has permission"""
from webnotes.defaults import get_user_default_as_list
if session.user=="Administrator":
return True
if conn.get_value("DocType", doctype, "istable"):
return True
if isinstance(refdoc, basestring):
refdoc = doc(doctype, refdoc)
perms = conn.sql("""select `name`, `match` from tabDocPerm p
where p.parent = %s
and ifnull(p.`%s`,0) = 1
@ -259,7 +262,7 @@ def has_permission(doctype, ptype="read", doc=None):
and (p.role="All" or p.role in (select `role` from tabUserRole where `parent`=%s))
""" % ("%s", ptype, "%s"), (doctype, session.user), as_dict=1)
if doc:
if refdoc:
match_failed = {}
for p in perms:
if p.match:
@ -268,11 +271,11 @@ def has_permission(doctype, ptype="read", doc=None):
else:
keys = [p.match, p.match]
if doc.fields.get(keys[0],"[No Value]") \
if refdoc.fields.get(keys[0],"[No Value]") \
in get_user_default_as_list(keys[1]):
return True
else:
match_failed[keys[0]] = doc.fields.get(keys[0],"[No Value]")
match_failed[keys[0]] = refdoc.fields.get(keys[0],"[No Value]")
else:
# found a permission without a match
return True

View file

@ -33,15 +33,18 @@ def get_mapped_doclist(from_doctype, from_docname, table_maps, target_doclist=[]
source = webnotes.bean(from_doctype, from_docname)
if not ignore_permissions and not webnotes.has_permission(from_doctype, doc=source.doc):
if not ignore_permissions and not webnotes.has_permission(from_doctype, "read", source.doc):
webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)
source_meta = webnotes.get_doctype(from_doctype)
target_meta = webnotes.get_doctype(table_maps[from_doctype]["doctype"])
# main
if target_doclist:
target_doc = webnotes.doc(target_doclist[0])
if isinstance(target_doclist[0], dict):
target_doc = webnotes.doc(fielddata=target_doclist[0])
else:
target_doc = target_doclist[0]
else:
target_doc = webnotes.new_doc(table_maps[from_doctype]["doctype"])
@ -99,10 +102,19 @@ def map_doc(source_doc, target_doc, table_map, source_meta, target_meta, source_
# map other fields
for source_key, target_key in table_map.get("field_map", {}).items():
val = source_doc.fields.get(source_key)
if val not in (None, ""):
target_doc.fields[target_key] = val
field_map = table_map.get("field_map")
if field_map:
if isinstance(field_map, dict):
for source_key, target_key in field_map.items():
val = source_doc.fields.get(source_key)
if val not in (None, ""):
target_doc.fields[target_key] = val
else:
for fmap in field_map:
val = source_doc.fields.get(fmap[0])
if val not in (None, ""):
target_doc.fields[fmap[1]] = val
# map idx
if source_doc.idx:

View file

@ -172,6 +172,8 @@ def build_conditions(doctype, fields, filters, docstatus):
def build_filter_conditions(filters, conditions):
"""build conditions from user filters"""
from webnotes.utils import cstr
global tables
if not tables: tables = []
for f in filters:
if isinstance(f, basestring):
@ -182,7 +184,7 @@ def build_filter_conditions(filters, conditions):
tables.append(tname)
# prepare in condition
if f[2]=='in':
if f[2] in ['in', 'not in']:
opts = ["'" + t.strip().replace("'", "\\'") + "'" for t in f[3].split(',')]
f[3] = "(" + ', '.join(opts) + ")"
conditions.append(tname + '.' + f[1] + " " + f[2] + " " + f[3])

View file

@ -30,8 +30,8 @@ from startup.query_handlers import standard_queries
# this is called by the Link Field
@webnotes.whitelist()
def search_link(dt, txt, query=None, filters=None):
search_widget(dt, txt, query, page_len=10, filters=filters)
def search_link(doctype, txt, query=None, filters=None):
search_widget(doctype, txt, query, page_len=10, filters=filters)
webnotes.response['results'] = build_for_autosuggest(webnotes.response["values"])
# this is called by the search box