Commit a9514323 authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #89 from plaes/select2-v2

s/Chosen/Select2
parents 820c75b4 3157f78f
Flask-Admin includes some bundled software to ease installation.
Select2
=======
Distributed under `APLv2 <http://www.apache.org/licenses/LICENSE-2.0>`_.
Twitter Bootstrap
=================
Distributed under `APLv2 <http://www.apache.org/licenses/LICENSE-2.0>`_.
...@@ -33,7 +33,7 @@ Flask-Admin is extensively documented, you can find `documentation here <http:// ...@@ -33,7 +33,7 @@ Flask-Admin is extensively documented, you can find `documentation here <http://
3rd Party Stuff 3rd Party Stuff
--------------- ---------------
Flask-Admin is built with help of `Twitter Bootstrap <http://twitter.github.com/bootstrap/>`_ and `Chosen <http://harvesthq.github.com/chosen/>`_. Flask-Admin is built with help of `Twitter Bootstrap <http://twitter.github.com/bootstrap/>`_ and `Select2 <https://github.com/ivaynberg/select2>`_.
Kudos Kudos
----- -----
......
...@@ -70,7 +70,7 @@ class AdminModelConverter(ModelConverterBase): ...@@ -70,7 +70,7 @@ class AdminModelConverter(ModelConverterBase):
kwargs['query_factory'] = lambda: self.session.query(remote_model) kwargs['query_factory'] = lambda: self.session.query(remote_model)
if prop.direction.name == 'MANYTOONE': if prop.direction.name == 'MANYTOONE':
return QuerySelectField(widget=form.ChosenSelectWidget(), return QuerySelectField(widget=form.Select2Widget(),
**kwargs) **kwargs)
elif prop.direction.name == 'ONETOMANY': elif prop.direction.name == 'ONETOMANY':
# Skip backrefs # Skip backrefs
...@@ -78,11 +78,11 @@ class AdminModelConverter(ModelConverterBase): ...@@ -78,11 +78,11 @@ class AdminModelConverter(ModelConverterBase):
return None return None
return QuerySelectMultipleField( return QuerySelectMultipleField(
widget=form.ChosenSelectWidget(multiple=True), widget=form.Select2Widget(multiple=True),
**kwargs) **kwargs)
elif prop.direction.name == 'MANYTOMANY': elif prop.direction.name == 'MANYTOMANY':
return QuerySelectMultipleField( return QuerySelectMultipleField(
widget=form.ChosenSelectWidget(multiple=True), widget=form.Select2Widget(multiple=True),
**kwargs) **kwargs)
else: else:
# Ignore pk/fk # Ignore pk/fk
......
...@@ -138,28 +138,28 @@ class ModelView(BaseModelView): ...@@ -138,28 +138,28 @@ class ModelView(BaseModelView):
giving SQLAlchemy chance to manually cleanup any dependencies (many-to-many giving SQLAlchemy chance to manually cleanup any dependencies (many-to-many
relationships, etc). relationships, etc).
If set to True, will run DELETE statement which is somewhat faster, but If set to `True`, will run `DELETE` statement which is somewhat faster,
might leave corrupted data if you forget to configure DELETE CASCADE but might leave corrupted data if you forget to configure `DELETE
for your model. CASCADE` for your model.
""" """
inline_models = None inline_models = None
""" """
Inline related-model editing for models with parent to child relation. Inline related-model editing for models with parent to child relation.
Accept enumerable with one of the values: Accepts enumerable with one of the following possible values:
1. Child model class 1. Child model class::
class MyModelView(ModelView): class MyModelView(ModelView):
inline_models = (Post,) inline_models = (Post,)
2. Child model class and additional options 2. Child model class and additional options::
class MyModelView(ModelView): class MyModelView(ModelView):
inline_models = [(Post, dict(form_columns=['title']))] inline_models = [(Post, dict(form_columns=['title']))]
3. Django-like ``InlineFormAdmin`` class instance 3. Django-like ``InlineFormAdmin`` class instance::
class MyInlineForm(InlineFormAdmin): class MyInlineForm(InlineFormAdmin):
forum_columns = ('title', 'date') forum_columns = ('title', 'date')
......
...@@ -83,28 +83,30 @@ class TimeField(fields.Field): ...@@ -83,28 +83,30 @@ class TimeField(fields.Field):
raise ValueError(gettext('Invalid time format')) raise ValueError(gettext('Invalid time format'))
class ChosenSelectWidget(widgets.Select): class Select2Widget(widgets.Select):
""" """
`Chosen <http://harvesthq.github.com/chosen/>`_ styled select widget. `Select2 <https://github.com/ivaynberg/select2>`_ styled select widget.
You must include chosen.js and form.js for styling to work. You must include select2.js, form.js and select2 stylesheet for it to
work.
""" """
def __call__(self, field, **kwargs): def __call__(self, field, **kwargs):
if field.allow_blank and not self.multiple: if field.allow_blank and not self.multiple:
kwargs['data-role'] = u'chosenblank' kwargs['data-role'] = u'select2blank'
else: else:
kwargs['data-role'] = u'chosen' kwargs['data-role'] = u'select2'
return super(ChosenSelectWidget, self).__call__(field, **kwargs) return super(Select2Widget, self).__call__(field, **kwargs)
class ChosenSelectField(fields.SelectField): class Select2Field(fields.SelectField):
""" """
`Chosen <http://harvesthq.github.com/chosen/>`_ styled select field. `Select2 <https://github.com/ivaynberg/select2>`_ styled select widget.
You must include chosen.js and form.js for styling to work. You must include select2.js, form.js and select2 stylesheet for it to
work.
""" """
widget = ChosenSelectWidget widget = Select2Widget
class DatePickerWidget(widgets.TextInput): class DatePickerWidget(widgets.TextInput):
......
This diff is collapsed.
This diff is collapsed.
...@@ -41,7 +41,7 @@ var AdminFilters = function(element, filters_element, operations, options, types ...@@ -41,7 +41,7 @@ var AdminFilters = function(element, filters_element, operations, options, types
$select.append($('<option/>').attr('value', this[0]).text(this[1])); $select.append($('<option/>').attr('value', this[0]).text(this[1]));
}); });
$select.chosen(); $select.select2();
var optId = op[0][0]; var optId = op[0][0];
...@@ -58,7 +58,7 @@ var AdminFilters = function(element, filters_element, operations, options, types ...@@ -58,7 +58,7 @@ var AdminFilters = function(element, filters_element, operations, options, types
.appendTo($el); .appendTo($el);
}); });
$field.chosen(); $field.select2();
} else } else
{ {
$field = $('<input type="text" class="filter-val" />') $field = $('<input type="text" class="filter-val" />')
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
var AdminForm = function() { var AdminForm = function() {
this.applyStyle = function(el, name) { this.applyStyle = function(el, name) {
switch (name) { switch (name) {
case 'chosen': case 'select2':
$(el).chosen(); $(el).select2({width: 'resolve'});
break; break;
case 'chosenblank': case 'select2blank':
$(el).chosen({allow_single_deselect: true}); $(el).select2({allowClear: true, width: 'resolve'});
break; break;
case 'datepicker': case 'datepicker':
$(el).datepicker(); $(el).datepicker();
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
}; };
this.applyGlobalStyles = function(parent) { this.applyGlobalStyles = function(parent) {
$('[data-role=chosen]', parent).chosen(); $('[data-role=select2]', parent).select2({width: 'resolve'});
$('[data-role=chosenblank]', parent).chosen({allow_single_deselect: true}); $('[data-role=select2blank]', parent).select2({allowClear: true, width: 'resolve'});
$('[data-role=datepicker]', parent).datepicker(); $('[data-role=datepicker]', parent).datepicker();
$('[data-role=datetimepicker]', parent).datepicker({displayTime: true}); $('[data-role=datetimepicker]', parent).datepicker({displayTime: true});
}; };
......
Copyright 2012 Igor Vaynberg
Version: @@ver@@ Timestamp: @@timestamp@@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in
compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="{{ url_for('admin.static', filename='bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script> <script src="{{ url_for('admin.static', filename='bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('admin.static', filename='chosen/chosen.jquery.min.js') }}" type="text/javascript"></script> <script src="{{ url_for('admin.static', filename='select2/select2.min.js') }}" type="text/javascript"></script>
{% block tail %} {% block tail %}
{% endblock %} {% endblock %}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% import 'admin/lib.html' as lib with context %} {% import 'admin/lib.html' as lib with context %}
{% block head %} {% block head %}
<link href="{{ url_for('admin.static', filename='chosen/chosen.css') }}" rel="stylesheet"> <link href="{{ url_for('admin.static', filename='select2/select2.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='css/datepicker.css') }}" rel="stylesheet"> <link href="{{ url_for('admin.static', filename='css/datepicker.css') }}" rel="stylesheet">
{% endblock %} {% endblock %}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% import 'admin/lib.html' as lib with context %} {% import 'admin/lib.html' as lib with context %}
{% block head %} {% block head %}
<link href="{{ url_for('admin.static', filename='chosen/chosen.css') }}" rel="stylesheet"> <link href="{{ url_for('admin.static', filename='select2/select2.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='css/datepicker.css') }}" rel="stylesheet"> <link href="{{ url_for('admin.static', filename='css/datepicker.css') }}" rel="stylesheet">
{% endblock %} {% endblock %}
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% import 'admin/actions.html' as actionlib with context %} {% import 'admin/actions.html' as actionlib with context %}
{% block head %} {% block head %}
<link href="{{ url_for('admin.static', filename='chosen/chosen.css') }}" rel="stylesheet"> <link href="{{ url_for('admin.static', filename='select2/select2.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='css/datepicker.css') }}" rel="stylesheet"> <link href="{{ url_for('admin.static', filename='css/datepicker.css') }}" rel="stylesheet">
{% endblock %} {% endblock %}
...@@ -73,14 +73,14 @@ ...@@ -73,14 +73,14 @@
{% set filter = admin_view._filters[flt[0]] %} {% set filter = admin_view._filters[flt[0]] %}
<a href="#" class="btn remove-filter" title="{{ _gettext('Remove Filter') }}"> <a href="#" class="btn remove-filter" title="{{ _gettext('Remove Filter') }}">
<span class="close-icon">&times;</span>&nbsp;{{ filters[flt[0]] }} <span class="close-icon">&times;</span>&nbsp;{{ filters[flt[0]] }}
</a><select class="filter-op" data-role="chosen"> </a><select class="filter-op" data-role="select2">
{% for op in admin_view._filter_dict[filter.name] %} {% for op in admin_view._filter_dict[filter.name] %}
<option value="{{ op[0] }}"{% if flt[0] == op[0] %} selected="selected"{% endif %}>{{ op[1] }}</option> <option value="{{ op[0] }}"{% if flt[0] == op[0] %} selected="selected"{% endif %}>{{ op[1] }}</option>
{% endfor %} {% endfor %}
</select> </select>
{%- set data = filter_data.get(flt[0]) -%} {%- set data = filter_data.get(flt[0]) -%}
{%- if data -%} {%- if data -%}
<select name="flt{{ i }}_{{ flt[0] }}" class="filter-val" data-role="chosen"> <select name="flt{{ i }}_{{ flt[0] }}" class="filter-val" data-role="select2">
{%- for d in data %} {%- for d in data %}
<option value="{{ d[0] }}"{% if flt[1] == d[0] %} selected{% endif %}>{{ d[1] }}</option> <option value="{{ d[0] }}"{% if flt[1] == d[0] %} selected{% endif %}>{{ d[1] }}</option>
{%- endfor %} {%- endfor %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment