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
OpenEdx
edx-platform
Commits
fd67c387
Commit
fd67c387
authored
Sep 27, 2017
by
Adam Palay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
keep track of number of components in a vertical
parent
649f3ccd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
16 deletions
+34
-16
cms/static/js/views/components/add_xblock.js
+21
-14
cms/static/js/views/pages/container.js
+6
-2
cms/templates/js/add-xblock-component-nudge.underscore
+6
-0
cms/templates/js/add-xblock-component.underscore
+1
-0
No files found.
cms/static/js/views/components/add_xblock.js
View file @
fd67c387
...
@@ -15,25 +15,30 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo
...
@@ -15,25 +15,30 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo
initialize
:
function
(
options
)
{
initialize
:
function
(
options
)
{
BaseView
.
prototype
.
initialize
.
call
(
this
,
options
);
BaseView
.
prototype
.
initialize
.
call
(
this
,
options
);
that
=
this
;
this
.
template
=
this
.
loadTemplate
(
'add-xblock-component'
);
this
.
template
=
this
.
loadTemplate
(
'add-xblock-component'
);
this
.
model
.
set
({
number_children
:
$
(
'.level-element'
).
length
});
// this.model.on('change:number_children', function(model){
// console.log('number of children changed!');
// console.log(model.get('number_children'));
// }, this.model);
this
.
model
.
on
(
'change:number_children'
,
this
.
render
,
this
);
},
},
render
:
function
()
{
render
:
function
()
{
if
(
!
this
.
$el
.
html
())
{
var
that
=
this
;
var
that
=
this
;
this
.
$el
.
html
(
this
.
template
({
numberChildren
:
that
.
model
.
get
(
'number_children'
)}));
this
.
$el
.
html
(
this
.
template
({}));
this
.
collection
.
each
(
this
.
collection
.
each
(
function
(
componentModel
)
{
function
(
componentModel
)
{
var
view
,
menu
;
var
view
,
menu
;
view
=
new
AddXBlockButton
({
model
:
componentModel
});
view
=
new
AddXBlockButton
({
model
:
componentModel
});
that
.
$el
.
find
(
'.new-component-type'
).
append
(
view
.
render
().
el
);
that
.
$el
.
find
(
'.new-component-type'
).
append
(
view
.
render
().
el
);
menu
=
new
AddXBlockMenu
({
model
:
componentModel
});
menu
=
new
AddXBlockMenu
({
model
:
componentModel
});
that
.
$el
.
append
(
menu
.
render
().
el
);
that
.
$el
.
append
(
menu
.
render
().
el
);
}
}
);
);
}
},
},
showComponentTemplates
:
function
(
event
)
{
showComponentTemplates
:
function
(
event
)
{
...
@@ -65,7 +70,9 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo
...
@@ -65,7 +70,9 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo
ViewUtils
.
runOperationShowingMessage
(
ViewUtils
.
runOperationShowingMessage
(
gettext
(
'Adding'
),
gettext
(
'Adding'
),
_
.
bind
(
this
.
options
.
createComponent
,
this
,
saveData
,
element
)
_
.
bind
(
this
.
options
.
createComponent
,
this
,
saveData
,
element
)
).
always
(
function
()
{
).
success
(
function
(){
self
.
model
.
set
({
number_children
:
self
.
model
.
get
(
'number_children'
)
+
1
});
}).
always
(
function
()
{
// Restore the scroll position of the buttons so that the new
// Restore the scroll position of the buttons so that the new
// component appears above them.
// component appears above them.
ViewUtils
.
setScrollOffset
(
self
.
$el
,
oldOffset
);
ViewUtils
.
setScrollOffset
(
self
.
$el
,
oldOffset
);
...
...
cms/static/js/views/pages/container.js
View file @
fd67c387
...
@@ -170,7 +170,8 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
...
@@ -170,7 +170,8 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
var
component
=
new
AddXBlockComponent
({
var
component
=
new
AddXBlockComponent
({
el
:
element
,
el
:
element
,
createComponent
:
_
.
bind
(
self
.
createComponent
,
self
),
createComponent
:
_
.
bind
(
self
.
createComponent
,
self
),
collection
:
self
.
options
.
templates
collection
:
self
.
options
.
templates
,
model
:
self
.
model
});
});
component
.
render
();
component
.
render
();
});
});
...
@@ -288,13 +289,16 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
...
@@ -288,13 +289,16 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
onDelete
:
function
(
xblockElement
)
{
onDelete
:
function
(
xblockElement
)
{
// get the parent so we can remove this component from its parent.
// get the parent so we can remove this component from its parent.
var
xblockView
=
this
.
xblockView
,
var
xblockView
=
this
.
xblockView
,
parent
=
this
.
findXBlockElement
(
xblockElement
.
parent
());
parent
=
this
.
findXBlockElement
(
xblockElement
.
parent
()),
model
=
this
.
model
;
xblockElement
.
remove
();
xblockElement
.
remove
();
// Inform the runtime that the child has been deleted in case
// Inform the runtime that the child has been deleted in case
// other views are listening to deletion events.
// other views are listening to deletion events.
xblockView
.
acknowledgeXBlockDeletion
(
parent
.
data
(
'locator'
));
xblockView
.
acknowledgeXBlockDeletion
(
parent
.
data
(
'locator'
));
model
.
set
({
number_children
:
model
.
get
(
'number_children'
)
-
1
});
// Update publish and last modified information from the server.
// Update publish and last modified information from the server.
this
.
model
.
fetch
();
this
.
model
.
fetch
();
},
},
...
...
cms/templates/js/add-xblock-component-nudge.underscore
0 → 100644
View file @
fd67c387
<div class="new-component">
<h5>This is the nudge</h5>
<p>There are <%= numberChildren %> components in this vertical</p>
<ul class="new-component-type">
</ul>
</div>
cms/templates/js/add-xblock-component.underscore
View file @
fd67c387
<div class="new-component">
<div class="new-component">
<h5><%= gettext("Add New Component") %></h5>
<h5><%= gettext("Add New Component") %></h5>
<p>There are <%= numberChildren %> components in this unit!</p>
<ul class="new-component-type">
<ul class="new-component-type">
</ul>
</ul>
</div>
</div>
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