Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
bb5d8efc
Commit
bb5d8efc
authored
Aug 26, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up JS a bit
parent
79f4f907
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
32 deletions
+76
-32
widgets.py
flask_admin/form/widgets.py
+14
-12
form.js
flask_admin/static/admin/js/form.js
+62
-20
No files found.
flask_admin/form/widgets.py
View file @
bb5d8efc
...
@@ -17,14 +17,25 @@ class Select2Widget(widgets.Select):
...
@@ -17,14 +17,25 @@ class Select2Widget(widgets.Select):
def
__call__
(
self
,
field
,
**
kwargs
):
def
__call__
(
self
,
field
,
**
kwargs
):
allow_blank
=
getattr
(
field
,
'allow_blank'
,
False
)
allow_blank
=
getattr
(
field
,
'allow_blank'
,
False
)
kwargs
[
'data-role'
]
=
u'select2'
if
allow_blank
and
not
self
.
multiple
:
if
allow_blank
and
not
self
.
multiple
:
kwargs
[
'data-role'
]
=
u'select2blank'
kwargs
[
'data-allow-blank'
]
=
u'1'
else
:
kwargs
[
'data-role'
]
=
u'select2'
return
super
(
Select2Widget
,
self
)
.
__call__
(
field
,
**
kwargs
)
return
super
(
Select2Widget
,
self
)
.
__call__
(
field
,
**
kwargs
)
class
Select2TagsWidget
(
widgets
.
TextInput
):
"""`Select2 <http://ivaynberg.github.com/select2/#tags>`_ styled text widget.
You must include select2.js, form.js and select2 stylesheet for it to work.
"""
def
__call__
(
self
,
field
,
**
kwargs
):
kwargs
[
'data-role'
]
=
u'select'
kwargs
[
'data-tags'
]
=
u'1'
return
super
(
Select2TagsWidget
,
self
)
.
__call__
(
field
,
**
kwargs
)
class
DatePickerWidget
(
widgets
.
TextInput
):
class
DatePickerWidget
(
widgets
.
TextInput
):
"""
"""
Date picker widget.
Date picker widget.
...
@@ -73,12 +84,3 @@ class RenderTemplateWidget(object):
...
@@ -73,12 +84,3 @@ class RenderTemplateWidget(object):
template
=
jinja_env
.
get_template
(
self
.
template
)
template
=
jinja_env
.
get_template
(
self
.
template
)
return
template
.
render
(
kwargs
)
return
template
.
render
(
kwargs
)
class
Select2TagsWidget
(
widgets
.
TextInput
):
"""`Select2 <http://ivaynberg.github.com/select2/#tags>`_ styled text widget.
You must include select2.js, form.js and select2 stylesheet for it to work.
"""
def
__call__
(
self
,
field
,
**
kwargs
):
kwargs
[
'data-role'
]
=
u'select2tags'
return
super
(
Select2TagsWidget
,
self
)
.
__call__
(
field
,
**
kwargs
)
flask_admin/static/admin/js/form.js
View file @
bb5d8efc
(
function
()
{
(
function
()
{
var
AdminForm
=
function
()
{
var
AdminForm
=
function
()
{
this
.
applyStyle
=
function
(
el
,
name
)
{
// Field converters
var
fieldConverters
=
[];
/**
* Process data-role attribute for the given input element. Feel free to override
*
* @param {Selector} $el jQuery selector
* @param {String} name data-role value
*/
this
.
applyStyle
=
function
(
$el
,
name
)
{
// Process converters first
for
(
var
conv
in
fieldConverters
)
{
var
fildConv
=
fieldConverters
[
conv
];
if
(
fieldConv
(
$el
,
name
))
return
true
;
}
switch
(
name
)
{
switch
(
name
)
{
case
'select2'
:
case
'select2'
:
$
(
el
).
select2
({
width
:
'resolve'
});
opts
=
{
break
;
width
:
'resolve'
case
'select2blank'
:
};
$
(
el
).
select2
({
allowClear
:
true
,
width
:
'resolve'
});
break
;
if
(
$el
.
attr
(
'data-allow-blank'
))
case
'select2tags'
:
opts
[
'allowClear'
]
=
true
;
$
(
el
).
select2
({
tags
:
[],
tokenSeparators
:
[
','
],
width
:
'resolve'
});
break
;
if
(
$el
.
attr
(
'data-tags'
))
{
$
.
extend
(
opts
,
{
multiple
:
true
,
tokenSeparators
:
[
','
]
});
}
$el
.
select2
(
opts
);
return
true
;
case
'datepicker'
:
case
'datepicker'
:
$
(
el
)
.
datepicker
();
$
el
.
datepicker
();
break
;
return
true
;
case
'datetimepicker'
:
case
'datetimepicker'
:
$
(
el
)
.
datepicker
({
displayTime
:
true
});
$
el
.
datepicker
({
displayTime
:
true
});
break
;
return
true
;
}
}
};
};
/**
* Add inline form field
*
* @method addInlineField
* @param {String} id Form ID
* @param {Node} el Form element
* @param {String} template Form template
*/
this
.
addInlineField
=
function
(
id
,
el
,
template
)
{
this
.
addInlineField
=
function
(
id
,
el
,
template
)
{
var
$el
=
$
(
el
);
var
$el
=
$
(
el
);
var
$template
=
$
(
$
(
template
).
text
());
var
$template
=
$
(
$
(
template
).
text
());
...
@@ -60,12 +93,19 @@
...
@@ -60,12 +93,19 @@
this
.
applyGlobalStyles
(
$template
);
this
.
applyGlobalStyles
(
$template
);
};
};
/**
* Apply global input styles.
*
* @method applyGlobalStyles
* @param {Selector} jQuery element
*/
this
.
applyGlobalStyles
=
function
(
parent
)
{
this
.
applyGlobalStyles
=
function
(
parent
)
{
$
(
'[data-role=select2]'
,
parent
).
select2
({
width
:
'resolve'
});
var
self
=
this
;
$
(
'[data-role=select2blank]'
,
parent
).
select2
({
allowClear
:
true
,
width
:
'resolve'
});
$
(
'[data-role=select2tags]'
,
parent
).
select2
({
multiple
:
true
,
tokenSeparators
:
[
','
],
width
:
'resolve'
});
$
(
'[data-role]'
,
parent
).
each
(
function
()
{
$
(
'[data-role=datepicker]'
,
parent
).
datepicker
();
var
$el
=
$
(
this
);
$
(
'[data-role=datetimepicker]'
,
parent
).
datepicker
({
displayTime
:
true
});
self
.
applyStyle
(
$el
,
$el
.
attr
(
'data-role'
));
});
};
};
};
};
...
@@ -80,6 +120,8 @@
...
@@ -80,6 +120,8 @@
// Expose faForm globally
// Expose faForm globally
var
faForm
=
window
.
faForm
=
new
AdminForm
();
var
faForm
=
window
.
faForm
=
new
AdminForm
();
// Apply global styles
// Apply global styles for current page after page loaded
faForm
.
applyGlobalStyles
(
document
);
$
(
function
()
{
faForm
.
applyGlobalStyles
(
document
);
});
})();
})();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment