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
0083cfc4
Commit
0083cfc4
authored
Aug 01, 2014
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always call refresh on parent of drag and drop operation.
STUD-2048
parent
b392e96d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
cms/static/js/spec/utils/drag_and_drop_spec.js
+27
-2
cms/static/js/utils/drag_and_drop.js
+9
-5
No files found.
cms/static/js/spec/utils/drag_and_drop_spec.js
View file @
0083cfc4
...
@@ -241,7 +241,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
...
@@ -241,7 +241,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
});
});
it
(
"calls handleReorder on a successful drag"
,
function
()
{
it
(
"calls handleReorder on a successful drag"
,
function
()
{
ContentDragger
.
dragState
.
dropDestination
=
$
(
'#unit-2'
);
ContentDragger
.
dragState
.
dropDestination
=
$
(
'#unit-2'
);
ContentDragger
.
dragState
.
attachMethod
=
"
before
"
;
ContentDragger
.
dragState
.
attachMethod
=
"
after
"
;
ContentDragger
.
dragState
.
parentList
=
$
(
'#subsection-1'
);
ContentDragger
.
dragState
.
parentList
=
$
(
'#subsection-1'
);
$
(
'#unit-1'
).
offset
({
$
(
'#unit-1'
).
offset
({
top
:
$
(
'#unit-1'
).
offset
().
top
+
10
,
top
:
$
(
'#unit-1'
).
offset
().
top
+
10
,
...
@@ -298,7 +298,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
...
@@ -298,7 +298,7 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
afterEach
(
function
()
{
afterEach
(
function
()
{
this
.
clock
.
restore
();
this
.
clock
.
restore
();
});
});
it
(
"should send an update on reorder"
,
function
()
{
it
(
"should send an update on reorder
from one parent to another
"
,
function
()
{
var
requests
,
savingOptions
;
var
requests
,
savingOptions
;
requests
=
create_sinon
[
"requests"
](
this
);
requests
=
create_sinon
[
"requests"
](
this
);
ContentDragger
.
dragState
.
dropDestination
=
$
(
'#unit-4'
);
ContentDragger
.
dragState
.
dropDestination
=
$
(
'#unit-4'
);
...
@@ -333,6 +333,31 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
...
@@ -333,6 +333,31 @@ define(["js/utils/drag_and_drop", "js/views/feedback_notification", "js/spec_hel
// target
// target
expect
(
$
(
'#subsection-2'
).
data
(
'refresh'
)).
toHaveBeenCalled
();
expect
(
$
(
'#subsection-2'
).
data
(
'refresh'
)).
toHaveBeenCalled
();
});
});
it
(
"should send an update on reorder within the same parent"
,
function
()
{
var
requests
=
create_sinon
[
"requests"
](
this
);
ContentDragger
.
dragState
.
dropDestination
=
$
(
'#unit-2'
);
ContentDragger
.
dragState
.
attachMethod
=
"after"
;
ContentDragger
.
dragState
.
parentList
=
$
(
'#subsection-1'
);
$
(
'#unit-1'
).
offset
({
top
:
$
(
'#unit-1'
).
offset
().
top
+
10
,
left
:
$
(
'#unit-1'
).
offset
().
left
});
ContentDragger
.
onDragEnd
({
element
:
$
(
'#unit-1'
)
},
null
,
{
clientX
:
$
(
'#unit-1'
).
offset
().
left
});
expect
(
requests
.
length
).
toEqual
(
1
);
expect
(
$
(
'#unit-1'
)).
toHaveClass
(
'was-dropped'
);
expect
(
requests
[
0
].
requestBody
).
toEqual
(
'{"children":["second-unit-id","first-unit-id","third-unit-id"]}'
);
requests
[
0
].
respond
(
200
);
this
.
clock
.
tick
(
1001
);
expect
(
$
(
'#unit-1'
)).
not
.
toHaveClass
(
'was-dropped'
);
// parent
expect
(
$
(
'#subsection-1'
).
data
(
'refresh'
)).
toHaveBeenCalled
();
});
});
});
});
});
});
});
...
...
cms/static/js/utils/drag_and_drop.js
View file @
0083cfc4
...
@@ -273,7 +273,13 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
...
@@ -273,7 +273,13 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
newParentEle
=
element
.
parents
(
parentSelector
).
first
(),
newParentEle
=
element
.
parents
(
parentSelector
).
first
(),
newParentLocator
=
newParentEle
.
data
(
'locator'
),
newParentLocator
=
newParentEle
.
data
(
'locator'
),
oldParentLocator
=
element
.
data
(
'parent'
),
oldParentLocator
=
element
.
data
(
'parent'
),
oldParentEle
,
saving
;
oldParentEle
,
saving
,
refreshParent
;
refreshParent
=
function
(
element
)
{
var
refresh
=
element
.
data
(
'refresh'
);
if
(
_
.
isFunction
(
refresh
))
{
refresh
();
}
};
// If the parent has changed, update the children of the old parent.
// If the parent has changed, update the children of the old parent.
if
(
newParentLocator
!==
oldParentLocator
)
{
if
(
newParentLocator
!==
oldParentLocator
)
{
// Find the old parent element.
// Find the old parent element.
...
@@ -282,10 +288,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
...
@@ -282,10 +288,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
});
});
this
.
saveItem
(
oldParentEle
,
childrenSelector
,
function
()
{
this
.
saveItem
(
oldParentEle
,
childrenSelector
,
function
()
{
element
.
data
(
'parent'
,
newParentLocator
);
element
.
data
(
'parent'
,
newParentLocator
);
_
.
each
([
oldParentEle
,
newParentEle
],
function
(
element
)
{
refreshParent
(
oldParentEle
);
var
refresh
=
element
.
data
(
'refresh'
);
if
(
_
.
isFunction
(
refresh
))
{
refresh
();
}
});
});
});
}
}
saving
=
new
NotificationView
.
Mini
({
saving
=
new
NotificationView
.
Mini
({
...
@@ -299,6 +302,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
...
@@ -299,6 +302,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notif
},
1000
);
},
1000
);
this
.
saveItem
(
newParentEle
,
childrenSelector
,
function
()
{
this
.
saveItem
(
newParentEle
,
childrenSelector
,
function
()
{
saving
.
hide
();
saving
.
hide
();
refreshParent
(
newParentEle
);
});
});
},
},
...
...
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