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
24707f8f
Commit
24707f8f
authored
May 29, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Jasmine test for views.
parent
625c6b51
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
4 deletions
+51
-4
cms/static/coffee/fixtures/metadata-editor.underscore
+2
-0
cms/static/coffee/fixtures/metadata-number-entry.underscore
+2
-0
cms/static/coffee/fixtures/metadata-option-entry.underscore
+2
-0
cms/static/coffee/fixtures/metadata-string-entry.underscore
+2
-0
cms/static/coffee/spec/views/metadata_edit_spec.coffee
+0
-0
cms/static/js/views/metadata_editor_view.js
+43
-4
No files found.
cms/static/coffee/fixtures/metadata-editor.underscore
0 → 120000
View file @
24707f8f
../../../templates/js/metadata-editor.underscore
\ No newline at end of file
cms/static/coffee/fixtures/metadata-number-entry.underscore
0 → 120000
View file @
24707f8f
../../../templates/js/metadata-number-entry.underscore
\ No newline at end of file
cms/static/coffee/fixtures/metadata-option-entry.underscore
0 → 120000
View file @
24707f8f
../../../templates/js/metadata-option-entry.underscore
\ No newline at end of file
cms/static/coffee/fixtures/metadata-string-entry.underscore
0 → 120000
View file @
24707f8f
../../../templates/js/metadata-string-entry.underscore
\ No newline at end of file
cms/static/coffee/spec/views/metadata_edit_spec.coffee
View file @
24707f8f
This diff is collapsed.
Click to expand it.
cms/static/js/views/metadata_editor_view.js
View file @
24707f8f
...
...
@@ -3,7 +3,6 @@ if (!CMS.Views['Metadata']) CMS.Views.Metadata = {};
CMS
.
Views
.
Metadata
.
Editor
=
Backbone
.
View
.
extend
({
// Model is simply a Backbone.Model instance.
initialize
:
function
()
{
var
tpl
=
$
(
"#metadata-editor-tpl"
).
text
();
if
(
!
tpl
)
{
...
...
@@ -45,6 +44,9 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
});
},
/**
* Returns the just the modified metadata values, in the format used to persist to the server.
*/
getModifiedMetadataValues
:
function
()
{
var
modified_values
=
{};
_
.
each
(
this
.
models
,
...
...
@@ -57,8 +59,16 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
return
modified_values
;
},
/**
* Returns a display name for the component related to this metadata. This method looks to see
* if there is a metadata entry called 'display_name', and if so, it returns its value. If there
* is no such entry, or if display_name does not have a value set, it returns an empty string.
*/
getDisplayName
:
function
()
{
// It is possible that there is no display name set. In that case, return empty string.
if
(
this
.
model
.
get
(
'display_name'
)
===
undefined
)
{
return
''
;
}
var
displayNameValue
=
this
.
model
.
get
(
'display_name'
).
value
;
return
displayNameValue
?
displayNameValue
:
''
;
}
...
...
@@ -67,7 +77,6 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
CMS
.
Views
.
Metadata
.
AbstractEditor
=
Backbone
.
View
.
extend
({
// Model is CMS.Models.Metadata.
initialize
:
function
()
{
var
self
=
this
;
var
templateName
=
this
.
getTemplateName
();
...
...
@@ -82,22 +91,42 @@ CMS.Views.Metadata.AbstractEditor = Backbone.View.extend({
this
.
render
();
},
/**
* Returns the ID/name of the template. Subclasses should implement this method.
*/
getTemplateName
:
function
()
{},
/**
* Returns the value currently displayed in the editor/view. Subclasses should implement this method.
*/
getValueFromEditor
:
function
()
{},
/**
* Sets the value currently displayed in the editor/view. Subclasses should implement this method.
*/
setValueInEditor
:
function
(
value
)
{},
/**
* Sets the value in the model, using the value currently displayed in the view. Afterward,
* this method re-renders to update the clear button.
*/
updateModel
:
function
()
{
this
.
model
.
setValue
(
this
.
getValueFromEditor
());
this
.
render
();
},
/**
* Clears the value currently set in the model (reverting to the default). Afterward, this method
* re-renders the view.
*/
clear
:
function
()
{
this
.
model
.
clear
();
this
.
render
();
},
/**
* Shows the clear button, if it is not already showing.
*/
showClearButton
:
function
()
{
if
(
!
this
.
$el
.
hasClass
(
'is-set'
))
{
this
.
$el
.
addClass
(
'is-set'
);
...
...
@@ -106,10 +135,17 @@ CMS.Views.Metadata.AbstractEditor = Backbone.View.extend({
}
},
/**
* Returns the clear button.
*/
getClearButton
:
function
()
{
return
this
.
$el
.
find
(
'.setting-clear'
);
},
/**
* Renders the editor, updating the value displayed in the view, as well as the state of
* the clear button.
*/
render
:
function
()
{
if
(
!
this
.
template
)
return
;
...
...
@@ -172,7 +208,7 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({
}
if
(
options
.
hasOwnProperty
(
max
))
{
this
.
max
=
Number
(
options
[
max
]);
this
.
$el
.
find
(
'input'
).
attr
(
max
,
numToString
(
this
.
max
.
toFixed
));
this
.
$el
.
find
(
'input'
).
attr
(
max
,
numToString
(
this
.
max
));
}
var
stepValue
=
undefined
;
if
(
options
.
hasOwnProperty
(
step
))
{
...
...
@@ -208,6 +244,9 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({
this
.
$el
.
find
(
'input'
).
val
(
value
);
},
/**
* Returns true if this view is restricted to integers, as opposed to floating points values.
*/
isIntegerField
:
function
()
{
return
this
.
model
.
getType
()
===
'Integer'
;
},
...
...
@@ -275,7 +314,7 @@ CMS.Views.Metadata.Option = CMS.Views.Metadata.AbstractEditor.extend({
value
=
modelValue
[
'display_name'
];
}
});
$
(
'#'
+
this
.
uniqueId
+
" option"
).
filter
(
function
()
{
this
.
$el
.
find
(
'#'
+
this
.
uniqueId
+
" option"
).
filter
(
function
()
{
return
$
(
this
).
text
()
===
value
;
}).
prop
(
'selected'
,
true
);
}
...
...
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