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
a82daf07
Commit
a82daf07
authored
May 31, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change to Backbone collection.
parent
57f8bbf6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
57 deletions
+62
-57
cms/static/coffee/spec/views/metadata_edit_spec.coffee
+33
-32
cms/static/coffee/src/views/module_edit.coffee
+5
-1
cms/static/js/models/metadata_model.js
+5
-0
cms/static/js/views/metadata_editor_view.js
+19
-24
No files found.
cms/static/coffee/spec/views/metadata_edit_spec.coffee
View file @
a82daf07
...
@@ -65,30 +65,32 @@ describe "Test Metadata Editor", ->
...
@@ -65,30 +65,32 @@ describe "Test Metadata Editor", ->
# Test for the editor that creates the individual views.
# Test for the editor that creates the individual views.
describe
"CMS.Views.Metadata.Editor creates editors for each field"
,
->
describe
"CMS.Views.Metadata.Editor creates editors for each field"
,
->
beforeEach
->
beforeEach
->
@
model
=
new
Backbone
.
Model
({
@
model
=
new
CMS
.
Models
.
MetadataCollection
(
num_inputs
:
integerEntry
,
[
weight
:
floatEntry
,
integerEntry
,
show_answer
:
selectEntry
,
floatEntry
,
display_name
:
genericEntry
,
selectEntry
,
unknown_type
:
{
genericEntry
,
default_value
:
null
,
{
display_name
:
"Unknown"
,
default_value
:
null
,
explicitly_set
:
true
,
display_name
:
"Unknown"
,
field_name
:
"unknown_type"
,
explicitly_set
:
true
,
help
:
"Mystery property."
,
field_name
:
"unknown_type"
,
inheritable
:
false
,
help
:
"Mystery property."
,
options
:
[
inheritable
:
false
,
{
"display_name"
:
"Always"
,
"value"
:
"always"
},
options
:
[
{
"display_name"
:
"Answered"
,
"value"
:
"answered"
},
{
"display_name"
:
"Always"
,
"value"
:
"always"
},
{
"display_name"
:
"Never"
,
"value"
:
"never"
}],
{
"display_name"
:
"Answered"
,
"value"
:
"answered"
},
type
:
"unknown type"
,
{
"display_name"
:
"Never"
,
"value"
:
"never"
}],
value
:
null
type
:
"unknown type"
,
}
value
:
null
})
}
]
)
it
"creates child views on initialize, and sorts them alphabetically"
,
->
it
"creates child views on initialize, and sorts them alphabetically"
,
->
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
model
:
@
model
})
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
collection
:
@
model
})
childModels
=
view
.
models
childModels
=
view
.
collection
.
models
expect
(
childModels
.
length
).
toBe
(
5
)
expect
(
childModels
.
length
).
toBe
(
5
)
childViews
=
view
.
$el
.
find
(
'.setting-input'
)
childViews
=
view
.
$el
.
find
(
'.setting-input'
)
expect
(
childViews
.
length
).
toBe
(
5
)
expect
(
childViews
.
length
).
toBe
(
5
)
...
@@ -104,16 +106,15 @@ describe "Test Metadata Editor", ->
...
@@ -104,16 +106,15 @@ describe "Test Metadata Editor", ->
verifyEntry
(
4
,
'Weight'
,
'number'
)
verifyEntry
(
4
,
'Weight'
,
'number'
)
it
"returns its display name"
,
->
it
"returns its display name"
,
->
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
model
:
@
model
})
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
collection
:
@
model
})
expect
(
view
.
getDisplayName
()).
toBe
(
"Word cloud"
)
expect
(
view
.
getDisplayName
()).
toBe
(
"Word cloud"
)
it
"returns an empty string if there is no display name property with a valid value"
,
->
it
"returns an empty string if there is no display name property with a valid value"
,
->
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
model
:
new
Backbone
.
Model
()})
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
collection
:
new
CMS
.
Models
.
MetadataCollection
()})
expect
(
view
.
getDisplayName
()).
toBe
(
""
)
expect
(
view
.
getDisplayName
()).
toBe
(
""
)
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
model
:
new
Backbone
.
Model
({
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
collection
:
new
CMS
.
Models
.
MetadataCollection
([
display_name
:
{
{
default_value
:
null
,
default_value
:
null
,
display_name
:
"Display Name"
,
display_name
:
"Display Name"
,
explicitly_set
:
false
,
explicitly_set
:
false
,
...
@@ -123,18 +124,18 @@ describe "Test Metadata Editor", ->
...
@@ -123,18 +124,18 @@ describe "Test Metadata Editor", ->
options
:
[],
options
:
[],
type
:
CMS
.
Models
.
Metadata
.
GENERIC_TYPE
,
type
:
CMS
.
Models
.
Metadata
.
GENERIC_TYPE
,
value
:
null
value
:
null
}
})
}
]
)
})
})
expect
(
view
.
getDisplayName
()).
toBe
(
""
)
expect
(
view
.
getDisplayName
()).
toBe
(
""
)
it
"has no modified values by default"
,
->
it
"has no modified values by default"
,
->
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
model
:
@
model
})
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
collection
:
@
model
})
expect
(
view
.
getModifiedMetadataValues
()).
toEqual
({})
expect
(
view
.
getModifiedMetadataValues
()).
toEqual
({})
it
"returns modified values only"
,
->
it
"returns modified values only"
,
->
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
model
:
@
model
})
view
=
new
CMS
.
Views
.
Metadata
.
Editor
({
collection
:
@
model
})
childModels
=
view
.
models
childModels
=
view
.
collection
.
models
childModels
[
0
].
setValue
(
'updated display name'
)
childModels
[
0
].
setValue
(
'updated display name'
)
childModels
[
1
].
setValue
(
20
)
childModels
[
1
].
setValue
(
20
)
expect
(
view
.
getModifiedMetadataValues
()).
toEqual
({
expect
(
view
.
getModifiedMetadataValues
()).
toEqual
({
...
...
cms/static/coffee/src/views/module_edit.coffee
View file @
a82daf07
...
@@ -24,9 +24,13 @@ class CMS.Views.ModuleEdit extends Backbone.View
...
@@ -24,9 +24,13 @@ class CMS.Views.ModuleEdit extends Backbone.View
@
module
=
XModule
.
loadModule
(
@
$el
.
find
(
'.xmodule_edit'
))
@
module
=
XModule
.
loadModule
(
@
$el
.
find
(
'.xmodule_edit'
))
# At this point, metadata-edit.html will be loaded, and the metadata (as JSON) is available.
# At this point, metadata-edit.html will be loaded, and the metadata (as JSON) is available.
metadataEditor
=
@
$el
.
find
(
'.metadata_edit'
)
metadataEditor
=
@
$el
.
find
(
'.metadata_edit'
)
metadataData
=
metadataEditor
.
data
(
'metadata'
)
models
=
[];
for
key
of
metadataData
models
.
push
(
metadataData
[
key
])
@
metadataEditor
=
new
CMS
.
Views
.
Metadata
.
Editor
({
@
metadataEditor
=
new
CMS
.
Views
.
Metadata
.
Editor
({
el
:
metadataEditor
,
el
:
metadataEditor
,
model
:
new
Backbone
.
Model
(
metadataEditor
.
data
(
'metadata'
)
)
collection
:
new
CMS
.
Models
.
MetadataCollection
(
models
)
})
})
# Need to update set "active" class on data editor if there is one.
# Need to update set "active" class on data editor if there is one.
...
...
cms/static/js/models/metadata_model.js
View file @
a82daf07
...
@@ -102,6 +102,11 @@ CMS.Models.Metadata = Backbone.Model.extend({
...
@@ -102,6 +102,11 @@ CMS.Models.Metadata = Backbone.Model.extend({
}
}
});
});
CMS
.
Models
.
MetadataCollection
=
Backbone
.
Collection
.
extend
({
model
:
CMS
.
Models
.
Metadata
,
comparator
:
"display_name"
});
CMS
.
Models
.
Metadata
.
SELECT_TYPE
=
"Select"
;
CMS
.
Models
.
Metadata
.
SELECT_TYPE
=
"Select"
;
CMS
.
Models
.
Metadata
.
INTEGER_TYPE
=
"Integer"
;
CMS
.
Models
.
Metadata
.
INTEGER_TYPE
=
"Integer"
;
CMS
.
Models
.
Metadata
.
FLOAT_TYPE
=
"Float"
;
CMS
.
Models
.
Metadata
.
FLOAT_TYPE
=
"Float"
;
...
...
cms/static/js/views/metadata_editor_view.js
View file @
a82daf07
...
@@ -2,7 +2,7 @@ if (!CMS.Views['Metadata']) CMS.Views.Metadata = {};
...
@@ -2,7 +2,7 @@ if (!CMS.Views['Metadata']) CMS.Views.Metadata = {};
CMS
.
Views
.
Metadata
.
Editor
=
Backbone
.
View
.
extend
({
CMS
.
Views
.
Metadata
.
Editor
=
Backbone
.
View
.
extend
({
// Model is
simply a Backbone.Model instance.
// Model is
CMS.Models.MetadataCollection,
initialize
:
function
()
{
initialize
:
function
()
{
var
tpl
=
$
(
"#metadata-editor-tpl"
).
text
();
var
tpl
=
$
(
"#metadata-editor-tpl"
).
text
();
if
(
!
tpl
)
{
if
(
!
tpl
)
{
...
@@ -10,31 +10,21 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
...
@@ -10,31 +10,21 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
}
}
this
.
template
=
_
.
template
(
tpl
);
this
.
template
=
_
.
template
(
tpl
);
this
.
$el
.
html
(
this
.
template
({
numEntries
:
this
.
model
.
keys
()
.
length
}));
this
.
$el
.
html
(
this
.
template
({
numEntries
:
this
.
collection
.
length
}));
var
counter
=
0
;
var
counter
=
0
;
// Sort entries by display name.
var
sortedObject
=
_
.
sortBy
(
this
.
model
.
attributes
,
function
(
val
)
{
return
val
.
display_name
});
this
.
models
=
[];
var
self
=
this
;
var
self
=
this
;
_
.
each
(
sortedObject
,
this
.
collection
.
each
(
function
(
item
)
{
function
(
model
)
{
var
model
=
new
CMS
.
Models
.
Metadata
(
item
);
self
.
models
.
push
(
model
);
var
data
=
{
var
data
=
{
el
:
self
.
$el
.
find
(
'.metadata_entry'
)[
counter
++
],
el
:
self
.
$el
.
find
(
'.metadata_entry'
)[
counter
++
],
model
:
model
model
:
model
};
};
if
(
item
.
type
===
CMS
.
Models
.
Metadata
.
SELECT_TYPE
)
{
if
(
model
.
getType
()
===
CMS
.
Models
.
Metadata
.
SELECT_TYPE
)
{
new
CMS
.
Views
.
Metadata
.
Option
(
data
);
new
CMS
.
Views
.
Metadata
.
Option
(
data
);
}
}
else
if
(
item
.
type
===
CMS
.
Models
.
Metadata
.
INTEGER_TYPE
||
else
if
(
model
.
getType
()
===
CMS
.
Models
.
Metadata
.
INTEGER_TYPE
||
item
.
type
===
CMS
.
Models
.
Metadata
.
FLOAT_TYPE
)
{
model
.
getType
()
===
CMS
.
Models
.
Metadata
.
FLOAT_TYPE
)
{
new
CMS
.
Views
.
Metadata
.
Number
(
data
);
new
CMS
.
Views
.
Metadata
.
Number
(
data
);
}
}
else
{
else
{
...
@@ -49,7 +39,7 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
...
@@ -49,7 +39,7 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
*/
*/
getModifiedMetadataValues
:
function
()
{
getModifiedMetadataValues
:
function
()
{
var
modified_values
=
{};
var
modified_values
=
{};
_
.
each
(
this
.
models
,
this
.
collection
.
each
(
function
(
model
)
{
function
(
model
)
{
if
(
model
.
isModified
())
{
if
(
model
.
isModified
())
{
modified_values
[
model
.
getFieldName
()]
=
model
.
getValue
();
modified_values
[
model
.
getFieldName
()]
=
model
.
getValue
();
...
@@ -65,12 +55,17 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
...
@@ -65,12 +55,17 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
* is no such entry, or if display_name does not have a value set, it returns an empty string.
* is no such entry, or if display_name does not have a value set, it returns an empty string.
*/
*/
getDisplayName
:
function
()
{
getDisplayName
:
function
()
{
// It is possible that there is no display name set. In that case, return empty string.
var
displayName
=
''
;
if
(
this
.
model
.
get
(
'display_name'
)
===
undefined
)
{
this
.
collection
.
each
(
return
''
;
function
(
model
)
{
}
if
(
model
.
get
(
'field_name'
)
===
'display_name'
)
{
var
displayNameValue
=
this
.
model
.
get
(
'display_name'
).
value
;
var
displayNameValue
=
model
.
get
(
'value'
);
return
displayNameValue
?
displayNameValue
:
''
;
// It is possible that there is no display name value set. In that case, return empty string.
displayName
=
displayNameValue
?
displayNameValue
:
''
;
}
}
);
return
displayName
;
}
}
});
});
...
...
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