From 5140ff38dff73daae82c5158f00c83ec43420204 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 10 Jul 2015 11:24:46 +0530 Subject: [PATCH 1/4] [filter] fix for filters and fix tabs in web_form.html --- frappe/public/js/frappe/form/control.js | 1 + frappe/public/js/frappe/ui/filters/filters.js | 21 +++- frappe/templates/generators/web_form.html | 102 +++++++++--------- 3 files changed, 68 insertions(+), 56 deletions(-) diff --git a/frappe/public/js/frappe/form/control.js b/frappe/public/js/frappe/form/control.js index e489c96e25..f28df12f2b 100644 --- a/frappe/public/js/frappe/form/control.js +++ b/frappe/public/js/frappe/form/control.js @@ -1024,6 +1024,7 @@ frappe.ui.form.ControlLink = frappe.ui.form.ControlData.extend({ this.$input.cache = {}; this.$input.autocomplete({ minLength: 0, + autoFocus: true, source: function(request, response) { var doctype = me.get_options(); if(!doctype) return; diff --git a/frappe/public/js/frappe/ui/filters/filters.js b/frappe/public/js/frappe/ui/filters/filters.js index 0c3f22f333..41411e881c 100644 --- a/frappe/public/js/frappe/ui/filters/filters.js +++ b/frappe/public/js/frappe/ui/filters/filters.js @@ -272,7 +272,8 @@ frappe.ui.Filter = Class.extend({ } else if(df.fieldtype=='Check') { df.fieldtype='Select'; df.options='No\nYes'; - } else if(['Text','Small Text','Text Editor','Code','Tag','Comments','Dynamic Link', 'Read Only'].indexOf(df.fieldtype)!=-1) { + } else if(['Text','Small Text','Text Editor','Code','Tag','Comments', + 'Dynamic Link','Read Only','Assign'].indexOf(df.fieldtype)!=-1) { df.fieldtype = 'Data'; } else if(df.fieldtype=='Link' && this.$w.find('.condition').val()!="=") { df.fieldtype = 'Data'; @@ -306,13 +307,20 @@ frappe.ui.Filter = Class.extend({ } if(this.get_condition()==='like') { - // add % only if not there at the end - if ((val.length === 0) || (val.lastIndexOf("%") !== (val.length - 1))) { - val = (val || "") + '%'; + // automatically append wildcards + if(val) { + if(val.slice(0,1) !== "%") { + val = "%" + val; + } + if(val.slice(-1) !== "%") { + val = val + "%"; + } } } else if(in_list(["in", "not in"], this.get_condition())) { val = $.map(val.split(","), function(v) { return strip(v); }); - } if(val === '%') val = ""; + } if(val === '%') { + val = ""; + } return val; }, @@ -368,6 +376,8 @@ frappe.ui.Filter = Class.extend({ value = this.field.get_value(); } + console.log(value); + this.$btn_group.find(".toggle-filter") .html(repl('%(label)s %(condition)s "%(value)s"', { label: __(this.field.df.label), @@ -392,6 +402,7 @@ frappe.ui.FieldSelect = Class.extend({ .autocomplete({ source: me.options, minLength: 0, + autoFocus: true, focus: function(event, ui) { ui.item && me.$select.val(ui.item.label); return false; diff --git a/frappe/templates/generators/web_form.html b/frappe/templates/generators/web_form.html index ee3ecaa839..48fe7c02af 100644 --- a/frappe/templates/generators/web_form.html +++ b/frappe/templates/generators/web_form.html @@ -5,25 +5,25 @@ {% endblock %} {% block header_actions %} - {% if params.name or params.new %} - - - {{ _("Cancel") }} - {% elif is_list %} - - {{ _("New {0}").format(_(doc_type)) }} - - {% endif %} + {% if params.name or params.new %} + + + {{ _("Cancel") }} + {% elif is_list %} + + {{ _("New {0}").format(_(doc_type)) }} + + {% endif %} {% endblock %} {% block content %}
- {% if introduction_text %} -

{{ introduction_text }}

-
- {% endif %} + {% if introduction_text %} +

{{ introduction_text }}

+
+ {% endif %}
{% if login_required and frappe.user=="Guest" %}
@@ -37,31 +37,31 @@

{% elif is_list %} - {% include "templates/includes/list/list.html" %} - + {% include "templates/includes/list/list.html" %} + {% else %}
{%- macro properties(field) %} - name="{{ field.fieldname }}" id="{{ field.fieldname }}" - {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %} - data-label="{{ field.label }}" data-fieldtype="{{ field.fieldtype }}" - {{ (field.reqd and field.fieldtype!="Attach") and "required" or "" }} - {{ field.read_only and "disabled" or "" }} + name="{{ field.fieldname }}" id="{{ field.fieldname }}" + {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %} + data-label="{{ field.label }}" data-fieldtype="{{ field.fieldtype }}" + {{ (field.reqd and field.fieldtype!="Attach") and "required" or "" }} + {{ field.read_only and "disabled" or "" }} {% endmacro -%} {%- macro value(field) -%}{% if doc %}{{ doc.get(field.fieldname) or field.default or "" }}{% else %}{{ getCookie(field.options) or field.default or "" }}{% endif %}{%- endmacro -%} {%- macro help(field) -%} - {% if field.description -%} - {{ field.description }} - {%- endif -%} + {% if field.description -%} + {{ field.description }} + {%- endif -%} {%- endmacro %} {% macro label(field) %} - + {% endmacro %} {% macro render_field(field) %} @@ -138,7 +138,7 @@
@@ -150,17 +150,17 @@ {%- endif %} - {% for section in layout %} -
- {% for column in section %} -
- {% for field in column %} - {{ render_field(field) }} - {% endfor %} -
- {% endfor %} -
- {% endfor %} + {% for section in layout %} +
+ {% for column in section %} +
+ {% for field in column %} + {{ render_field(field) }} + {% endfor %} +
+ {% endfor %} +
+ {% endfor %} {% if allow_comments and not params.new -%}
@@ -176,7 +176,7 @@