From 44dd97dbd4b251a44d1806cc6025e72869427bbe Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Mon, 4 Nov 2019 11:51:23 +0530 Subject: [PATCH 1/9] Add version of baseframe-mui without select2. --- baseframe/assets.py | 25 +++++++++++++++---- baseframe/static/js/baseframe-material.js | 18 ++++++------- .../static/sass/baseframe-material/_menu.scss | 1 - 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/baseframe/assets.py b/baseframe/assets.py index 577b6f4c..956a559e 100644 --- a/baseframe/assets.py +++ b/baseframe/assets.py @@ -118,7 +118,6 @@ assets['select2-material.css'][Version('4.0.3')] = ('select2.css', 'baseframe/css/select2-baseframe-material.css') assets['select2-material.js'][Version('4.0.3')] = {'requires': ['select2.js==4.0.3']} - assets['bootstrap-multiselect.css'][Version('0.9.13')] = 'baseframe/css/bootstrap-multiselect.css' assets['bootstrap-multiselect.js'][Version('0.9.13')] = 'baseframe/js/bootstrap-multiselect.js' @@ -334,12 +333,18 @@ 'select2-baseframe.js', 'getdevicepixelratio.js' ]} -assets['extra-material.js'][Version('0.0.0')] = {'requires': [ +assets['extra-material.js'][Version('0.1.0')] = {'requires': [ 'jquery-modal.js', 'jquery.form.js', 'select2-material.js', 'getdevicepixelratio.js' ]} +assets['extra-material.js'][Version('0.2.0')] = {'requires': [ + 'jquery-modal.js', + 'jquery.form.js', + 'getdevicepixelratio.js' + ]} + assets['baseframe.js'][Version(__version__)] = {'requires': [ 'jquery.js<1.9.0', @@ -376,16 +381,26 @@ assets['mui.js'][Version('0.9.21')] = 'baseframe/js/mui.js' assets['baseframe-material.js'][Version('0.9.21')] = 'baseframe/js/baseframe-material.js' -assets['baseframe-mui.js'][Version(__version__)] = {'requires': [ - 'extra-material.js', +assets['baseframe-mui.js'][Version('0.1.0')] = {'requires': [ + 'extra-material.js==0.1.0', + 'mui.js', + 'jquery.tinymce.js>=4.0.0', + 'baseframe-material.js' + ]} +assets['baseframe-mui.js'][Version('0.2.0')] = {'requires': [ + 'extra-material.js==0.2.0', 'mui.js', 'jquery.tinymce.js>=4.0.0', 'baseframe-material.js' ]} assets['mui.css'][Version('0.9.21')] = 'baseframe/css/mui.css' -assets['baseframe-mui.css'][Version(__version__)] = {'requires': [ +assets['baseframe-mui.css'][Version('0.1.0')] = {'requires': [ 'jquery-modal.css', 'select2-material.css', 'mui.css' ]} +assets['baseframe-mui.css'][Version('0.2.0')] = {'requires': [ + 'jquery-modal.css', + 'mui.css' + ]} diff --git a/baseframe/static/js/baseframe-material.js b/baseframe/static/js/baseframe-material.js index 53bde2a7..d98a0a8f 100644 --- a/baseframe/static/js/baseframe-material.js +++ b/baseframe/static/js/baseframe-material.js @@ -1,15 +1,11 @@ // This is a global function. Isn't there a better way to do this? function activate_widgets() { - // Activate select2.js for non-mobile browsers - if (!Modernizr.touch) { - $('select:not(.notselect)').select2(); - //Remove the scroll lock class added by mui.js on opening select menu - $('select:not(.notselect)').on("select2:select", function(e) { - $('body').removeClass('mui-scroll-lock'); - }); - } + //Remove the scroll lock class added by mui.js on opening select dropdown + $('select:not(.notselect)').on("select2:select", function(e) { + $('body').removeClass('mui-scroll-lock'); + }); var cm_markdown_config = { mode: 'gfm', lineNumbers: false, @@ -186,8 +182,8 @@ window.Baseframe.Config = { window.Baseframe.Forms = { preventSubmitOnEnter: function(id){ $('#' + id).on("keyup keypress", function(e) { - var code = e.keyCode || e.which; - if (code === 13) { + var code = e.keyCode || e.which; + if (code === 13) { e.preventDefault(); return false; } @@ -463,5 +459,5 @@ $(function() { $('body').on('click', '.alert__close', function () { $(this).parents('.alert').fadeOut(); }); - + }); diff --git a/baseframe/static/sass/baseframe-material/_menu.scss b/baseframe/static/sass/baseframe-material/_menu.scss index eee01ce1..dd886128 100644 --- a/baseframe/static/sass/baseframe-material/_menu.scss +++ b/baseframe/static/sass/baseframe-material/_menu.scss @@ -209,7 +209,6 @@ and (orientation: landscape) { .content-wrapper { position: relative; - z-index: 1; padding-top: 50px; } From e572849033436599998cd69bb82ff4b8dc5b363b Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Mon, 4 Nov 2019 12:04:48 +0530 Subject: [PATCH 2/9] Add a class for select2 fields --- baseframe/static/css/mui.css | 15 +++++++++------ .../static/sass/baseframe-material/_form.scss | 14 ++++++++++---- .../templates/baseframe/mui/forms.html.jinja2 | 7 ++++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/baseframe/static/css/mui.css b/baseframe/static/css/mui.css index b3bef8f1..07824e7a 100644 --- a/baseframe/static/css/mui.css +++ b/baseframe/static/css/mui.css @@ -3559,7 +3559,6 @@ h4, h5, h6 { .content-wrapper { position: relative; - z-index: 1; padding-top: 50px; } @@ -3830,12 +3829,16 @@ li p + ol { margin-top: 20px; margin-bottom: 0; } -.mui-select > label { - top: -5px; -} .mui-select .select2 { width: 100% !important; } +.mui-select .mui-select__menu { + z-index: 1001; +} + +.mui-select.select2 .mui-select__menu { + display: none; +} .listwidget ul, .listwidget ol { list-style: none; @@ -4031,8 +4034,8 @@ li p + ol { @media (min-width: 768px) { .alert { - margin-top: 1em; - margin-bottom: 1em; + margin-top: 15px; + margin-bottom: 15px; } } .thumbnail { diff --git a/baseframe/static/sass/baseframe-material/_form.scss b/baseframe/static/sass/baseframe-material/_form.scss index 16cd0267..e34de0c5 100644 --- a/baseframe/static/sass/baseframe-material/_form.scss +++ b/baseframe/static/sass/baseframe-material/_form.scss @@ -10,7 +10,7 @@ .mui-textfield, .mui-radio, .mui-checkbox { - margin-bottom: 5px; + margin-bottom: 5px; } .mui-textfield--float-label { @@ -97,12 +97,18 @@ .mui-select { margin-top: $mui-form-group-margin-bottom; margin-bottom: 0; - > label { - top: -$mui-form-group-margin-bottom/4; - } .select2 { width: 100% !important; } + .mui-select__menu { + z-index: 1001; //Higher than the fixed header + } +} + +.mui-select.select2 { + .mui-select__menu { + display: none; + } } .listwidget ul, .listwidget ol { diff --git a/baseframe/templates/baseframe/mui/forms.html.jinja2 b/baseframe/templates/baseframe/mui/forms.html.jinja2 index 4a5a8971..31c38d8b 100644 --- a/baseframe/templates/baseframe/mui/forms.html.jinja2 +++ b/baseframe/templates/baseframe/mui/forms.html.jinja2 @@ -77,11 +77,16 @@ {%- endif %} - {%- elif field.type in ['SelectField', 'QuerySelectField', 'SelectMultipleField', 'QuerySelectMultipleField', 'UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} + {%- elif field.type in ['SelectField', 'QuerySelectField', 'SelectMultipleField', 'QuerySelectMultipleField'] and field.widget.html_tag not in ['ul', 'ol'] %}
{{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}}
+ {%- elif field.type in ['SelectField', 'QuerySelectField', 'SelectMultipleField', 'QuerySelectMultipleField', 'UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} +
+ {{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} + +
{%- else %}
{%- if not nolabel %}{%- endif %} From d40ac980b909be133d88ab35595ec3bcbd4a6a20 Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Mon, 4 Nov 2019 21:35:05 +0530 Subject: [PATCH 3/9] When an item is selected from dropdown remove scroll class from body --- baseframe/static/js/baseframe-material.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseframe/static/js/baseframe-material.js b/baseframe/static/js/baseframe-material.js index d98a0a8f..198aef9a 100644 --- a/baseframe/static/js/baseframe-material.js +++ b/baseframe/static/js/baseframe-material.js @@ -3,7 +3,7 @@ function activate_widgets() { //Remove the scroll lock class added by mui.js on opening select dropdown - $('select:not(.notselect)').on("select2:select", function(e) { + $('select').on("select2:select", function(e) { $('body').removeClass('mui-scroll-lock'); }); From b403edb0620cab9a57b840aa32195e901ec77eb9 Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Wed, 6 Nov 2019 18:49:27 +0530 Subject: [PATCH 4/9] Fix the check for select2 in the template --- baseframe/templates/baseframe/mui/forms.html.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseframe/templates/baseframe/mui/forms.html.jinja2 b/baseframe/templates/baseframe/mui/forms.html.jinja2 index 31c38d8b..17a5f8b9 100644 --- a/baseframe/templates/baseframe/mui/forms.html.jinja2 +++ b/baseframe/templates/baseframe/mui/forms.html.jinja2 @@ -82,7 +82,7 @@ {{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}}
- {%- elif field.type in ['SelectField', 'QuerySelectField', 'SelectMultipleField', 'QuerySelectMultipleField', 'UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} + {%- elif field.type in ['UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %}
{{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} From cb9d96d4b5eda3f109bbb579d6ef5ac8293d70af Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Wed, 6 Nov 2019 19:34:31 +0530 Subject: [PATCH 5/9] Enable select2 for SelectMultipleField --- baseframe/static/css/mui.css | 2 +- baseframe/static/css/select2-baseframe-material.css | 6 +----- baseframe/static/js/baseframe-material.js | 3 +++ baseframe/static/sass/baseframe-material/_form.scss | 2 +- baseframe/templates/baseframe/mui/forms.html.jinja2 | 11 +++++++++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/baseframe/static/css/mui.css b/baseframe/static/css/mui.css index 07824e7a..33ea7a02 100644 --- a/baseframe/static/css/mui.css +++ b/baseframe/static/css/mui.css @@ -3837,7 +3837,7 @@ li p + ol { } .mui-select.select2 .mui-select__menu { - display: none; + display: none !important; } .listwidget ul, .listwidget ol { diff --git a/baseframe/static/css/select2-baseframe-material.css b/baseframe/static/css/select2-baseframe-material.css index b5129177..9cb17860 100644 --- a/baseframe/static/css/select2-baseframe-material.css +++ b/baseframe/static/css/select2-baseframe-material.css @@ -1,7 +1,3 @@ -.mui-select__menu { - display: none!important; -} - .select2-container .select2-selection { border: none; border-radius: 0; @@ -18,7 +14,7 @@ box-shadow: 0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24); } -.select2-container.select2-container--focus .select2-selection, +.select2-container.select2-container--focus .select2-selection, .select2-container.select2-container--open .select2-selection { box-shadow: none; border: none; diff --git a/baseframe/static/js/baseframe-material.js b/baseframe/static/js/baseframe-material.js index 198aef9a..21e68067 100644 --- a/baseframe/static/js/baseframe-material.js +++ b/baseframe/static/js/baseframe-material.js @@ -189,6 +189,9 @@ window.Baseframe.Forms = { } }); }, + enableSelect2: function() { + $('.mui-select2 select').select2(); + }, lastuserAutocomplete: function(options) { var assembleUsers = function(users) { return users.map(function(user){ diff --git a/baseframe/static/sass/baseframe-material/_form.scss b/baseframe/static/sass/baseframe-material/_form.scss index e34de0c5..372f1133 100644 --- a/baseframe/static/sass/baseframe-material/_form.scss +++ b/baseframe/static/sass/baseframe-material/_form.scss @@ -107,7 +107,7 @@ .mui-select.select2 { .mui-select__menu { - display: none; + display: none !important; } } diff --git a/baseframe/templates/baseframe/mui/forms.html.jinja2 b/baseframe/templates/baseframe/mui/forms.html.jinja2 index 17a5f8b9..99d728f7 100644 --- a/baseframe/templates/baseframe/mui/forms.html.jinja2 +++ b/baseframe/templates/baseframe/mui/forms.html.jinja2 @@ -77,12 +77,17 @@ {%- endif %}
- {%- elif field.type in ['SelectField', 'QuerySelectField', 'SelectMultipleField', 'QuerySelectMultipleField'] and field.widget.html_tag not in ['ul', 'ol'] %} + {%- elif field.type in ['SelectField', 'QuerySelectField', 'QuerySelectMultipleField'] and field.widget.html_tag not in ['ul', 'ol'] %}
{{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}}
- {%- elif field.type in ['UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} + {%- elif field.type in ['SelectMultipleField'] and field.widget.html_tag not in ['ul', 'ol'] %} +
+ {{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} + +
+ {%- elif field.type in ['SelectMultipleField', 'UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %}
{{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} @@ -359,6 +364,8 @@ document.getElementById("{{ ref_id }}").submit(); } }) + {%- elif field.type in ['SelectMultipleField'] %} + Baseframe.Forms.enableSelect2(); {%- elif field.type in ['UserSelectField', 'UserSelectMultiField'] %} {%- if config['LASTUSER_CLIENT_ID'] and current_auth.cookie and 'sessionid' in current_auth.cookie %} Baseframe.Forms.lastuserAutocomplete({ From 41d20f4fd85e05135fd3d2adb0b29435af40229b Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Wed, 6 Nov 2019 19:39:22 +0530 Subject: [PATCH 6/9] Fix the elif --- baseframe/templates/baseframe/mui/forms.html.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseframe/templates/baseframe/mui/forms.html.jinja2 b/baseframe/templates/baseframe/mui/forms.html.jinja2 index 99d728f7..65d5a3a7 100644 --- a/baseframe/templates/baseframe/mui/forms.html.jinja2 +++ b/baseframe/templates/baseframe/mui/forms.html.jinja2 @@ -87,7 +87,7 @@ {{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}}
- {%- elif field.type in ['SelectMultipleField', 'UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %} + {%- elif field.type in ['UserSelectField', 'UserSelectMultiField', 'AutocompleteField', 'AutocompleteMultipleField', 'GeonameSelectField', 'GeonameSelectMultiField'] and field.widget.html_tag not in ['ul', 'ol'] %}
{{ field | render_field_options(class="field-" + field.id + " " + widget_css_class, tabindex=tabindex, autofocus=autofocus, rows=rows)}} From 30aa08b083143e10251469300ddfddc96832e014 Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Fri, 8 Nov 2019 11:22:40 +0530 Subject: [PATCH 7/9] Add select2 bundle --- baseframe/__init__.py | 6 ++++++ .../baseframe/mui/formlayout.html.jinja2 | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/baseframe/__init__.py b/baseframe/__init__.py index ee320d02..e215cb81 100644 --- a/baseframe/__init__.py +++ b/baseframe/__init__.py @@ -184,6 +184,10 @@ def init_app(self, app, requires=[], ext_requires=[], bundle_js=None, bundle_css filters='uglipyjs', output='js/baseframe-packed.js') css_all = Bundle(assets.require(*(ignore_css + assets_css)), filters=['cssrewrite', 'cssmin'], output='css/baseframe-packed.css') + js_select2 = Bundle(assets.require('!jquery.js', 'select2-material.js'), + filters='uglipyjs', output='js/select2-material-packed.js') + css_select2 = Bundle(assets.require('select2-material.css'), + filters=['cssrewrite', 'cssmin'], output='css/select2-material-packed.css') if bundle_js: js_all = Bundle(js_all, bundle_js) if bundle_css: @@ -196,6 +200,8 @@ def init_app(self, app, requires=[], ext_requires=[], bundle_js=None, bundle_css app.assets.register('js_jquery', assets.require('jquery.js')) app.assets.register('js_all', js_all) app.assets.register('css_all', css_all) + app.assets.register('js_select2', js_select2) + app.assets.register('css_select2', css_select2) app.register_blueprint(self, static_subdomain=subdomain) # Optional config for a client app to use a manifest file diff --git a/baseframe/templates/baseframe/mui/formlayout.html.jinja2 b/baseframe/templates/baseframe/mui/formlayout.html.jinja2 index 545cc611..93f1023a 100644 --- a/baseframe/templates/baseframe/mui/formlayout.html.jinja2 +++ b/baseframe/templates/baseframe/mui/formlayout.html.jinja2 @@ -1 +1,18 @@ {% extends "layout.html.jinja2" -%} + +{%- block layoutheaders %} + {% assets "css_select2" -%} + + {%- endassets -%} + {% block pageheaders %}{% endblock %} +{% endblock %} + +{% block basecontent -%} + {% block content %}{% endblock %} +{%- endblock %} + +{% block pagescripts %} + {% assets "js_select2" -%} + + {%- endassets -%} +{% endblock %} From 7f31d82ba436a1e956be523b4617b95306215744 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Thu, 14 Nov 2019 00:02:10 +0530 Subject: [PATCH 8/9] Fix validator flags --- baseframe/forms/validators.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/baseframe/forms/validators.py b/baseframe/forms/validators.py index 56925bea..3062d7bc 100644 --- a/baseframe/forms/validators.py +++ b/baseframe/forms/validators.py @@ -124,6 +124,8 @@ class AllowedIf(object): :param str message: Validation error message. Will be formatted with an optional ``{field}}`` label """ + field_flags = ('not_solo',) + def __init__(self, fieldname, message=None): self.fieldname = fieldname self.message = message or __(u"This requires ‘{field}’ to be specified") @@ -149,6 +151,8 @@ class OptionalIf(Optional): :param str message: Validation error message """ + field_flags = ('not_solo',) + def __init__(self, fieldname, message=None): super(OptionalIf, self).__init__() self.fieldname = fieldname @@ -172,7 +176,7 @@ class RequiredIf(DataRequired): :param str message: Validation error message """ - field_flags = set() + field_flags = ('not_solo',) def __init__(self, fieldname, message=None): message = message or __("This is required") @@ -189,6 +193,7 @@ class _Comparison(object): Base class for validators that compare this field's value with another field """ + field_flags = ('not_solo',) default_message = __("Comparison failed") def __init__(self, fieldname, message=None): From b5c1b220a855adb4022ab108035d902443a6a6a6 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Thu, 14 Nov 2019 00:02:50 +0530 Subject: [PATCH 9/9] Add support for widget scripts hosted in widget itself --- baseframe/forms/patch_wtforms.py | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/baseframe/forms/patch_wtforms.py b/baseframe/forms/patch_wtforms.py index a01f41ca..4f3a4b82 100644 --- a/baseframe/forms/patch_wtforms.py +++ b/baseframe/forms/patch_wtforms.py @@ -12,11 +12,15 @@ def _patch_wtforms_add_flags(): + """Patch WTForms validators as required (currently just one type of patch)""" + def add_flags(validator, flags): + """Add more flags to existing WTForms validators""" validator.field_flags = tuple(flags) + tuple( getattr(validator, 'field_flags', ()) ) + # Patch the `EqualTo` validator to add a 'not_solo' flag on any field it is used on add_flags(wtforms.validators.EqualTo, ('not_solo',)) @@ -70,3 +74,36 @@ def field_init( _patch_wtforms_field_init() del _patch_wtforms_field_init + + +def render_script(self, tag=True): + """ + Render the JavaScript necessary (including script tag) for this field. + + This delegates rendering to + :meth:`meta.render_field_script` + whose default behavior is to call the field's widget, passing any + keyword arguments from this call along to the widget. + + :param bool tag: If False, don't include a ``