Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
31393043
Commit
31393043
authored
Feb 07, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More for that commit
parent
9cd1162a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
cms/static/js/views/settings/settings_grading_view.js
+0
-0
cms/static/js/views/validating_view.js
+67
-0
No files found.
cms/static/js/views/settings/settings_grading_view.js
0 → 100644
View file @
31393043
This diff is collapsed.
Click to expand it.
cms/static/js/views/validating_view.js
0 → 100644
View file @
31393043
CMS
.
Views
.
ValidatingView
=
Backbone
.
View
.
extend
({
// Intended as an abstract class which catches validation errors on the model and
// decorates the fields. Needs wiring per class, but this initialization shows how
// either have your init call this one or copy the contents
initialize
:
function
()
{
this
.
model
.
on
(
'error'
,
this
.
handleValidationError
,
this
);
this
.
selectorToField
=
_
.
invert
(
this
.
fieldToSelectorMap
);
},
errorTemplate
:
_
.
template
(
'<span class="message-error"><%= message %></span>'
),
events
:
{
"blur input"
:
"clearValidationErrors"
,
"blur textarea"
:
"clearValidationErrors"
},
fieldToSelectorMap
:
{
// Your subclass must populate this w/ all of the model keys and dom selectors
// which may be the subjects of validation errors
},
_cacheValidationErrors
:
[],
handleValidationError
:
function
(
model
,
error
)
{
// error is object w/ fields and error strings
for
(
var
field
in
error
)
{
var
ele
=
this
.
$el
.
find
(
'#'
+
this
.
fieldToSelectorMap
[
field
]);
this
.
_cacheValidationErrors
.
push
(
ele
);
if
(
$
(
ele
).
is
(
'div'
))
{
// put error on the contained inputs
$
(
ele
).
find
(
'input, textarea'
).
addClass
(
'error'
);
}
else
$
(
ele
).
addClass
(
'error'
);
$
(
ele
).
parent
().
append
(
this
.
errorTemplate
({
message
:
error
[
field
]}));
}
},
clearValidationErrors
:
function
()
{
// error is object w/ fields and error strings
while
(
this
.
_cacheValidationErrors
.
length
>
0
)
{
var
ele
=
this
.
_cacheValidationErrors
.
pop
();
if
(
$
(
ele
).
is
(
'div'
))
{
// put error on the contained inputs
$
(
ele
).
find
(
'input, textarea'
).
removeClass
(
'error'
);
}
else
$
(
ele
).
removeClass
(
'error'
);
$
(
ele
).
nextAll
(
'.message-error'
).
remove
();
}
},
saveIfChanged
:
function
(
event
)
{
// returns true if the value changed and was thus sent to server
var
field
=
this
.
selectorToField
[
event
.
currentTarget
.
id
];
var
currentVal
=
this
.
model
.
get
(
field
);
var
newVal
=
$
(
event
.
currentTarget
).
val
();
if
(
currentVal
!=
newVal
)
{
this
.
clearValidationErrors
();
this
.
model
.
save
(
field
,
newVal
,
{
error
:
CMS
.
ServerError
});
return
true
;
}
else
return
false
;
},
// these should perhaps go into a superclass but lack of event hash inheritance demotivates me
inputFocus
:
function
(
event
)
{
$
(
"label[for='"
+
event
.
currentTarget
.
id
+
"']"
).
addClass
(
"is-focused"
);
},
inputUnfocus
:
function
(
event
)
{
$
(
"label[for='"
+
event
.
currentTarget
.
id
+
"']"
).
removeClass
(
"is-focused"
);
}
});
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