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
a02ca255
Commit
a02ca255
authored
Dec 09, 2015
by
Amir Qayyum Khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring: Fixed indentation in ccx/schedule.js plus path of momemt.js for requireJs
parent
e0ef89ed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
452 additions
and
461 deletions
+452
-461
lms/static/js/ccx/schedule.js
+451
-460
lms/static/lms/js/require-config.js
+1
-1
No files found.
lms/static/js/ccx/schedule.js
View file @
a02ca255
var
edx
=
edx
||
{};
var
edx
=
edx
||
{};
(
function
(
$
,
_
,
Backbone
,
gettext
)
{
(
function
(
$
,
_
,
Backbone
,
gettext
)
{
'use strict'
;
'use strict'
;
edx
.
ccx
=
edx
.
ccx
||
{};
edx
.
ccx
=
edx
.
ccx
||
{};
edx
.
ccx
.
schedule
=
edx
.
ccx
.
schedule
||
{};
edx
.
ccx
.
schedule
=
edx
.
ccx
.
schedule
||
{};
var
self
;
var
self
;
edx
.
ccx
.
schedule
.
reloadPage
=
function
()
{
edx
.
ccx
.
schedule
.
reloadPage
=
function
()
{
location
.
reload
();
location
.
reload
();
};
};
edx
.
ccx
.
schedule
.
UnitModel
=
Backbone
.
Model
.
extend
({
edx
.
ccx
.
schedule
.
UnitModel
=
Backbone
.
Model
.
extend
({
defaults
:
{
defaults
:
{
location
:
''
,
location
:
''
,
display_name
:
''
,
display_name
:
''
,
start
:
null
,
start
:
null
,
due
:
null
,
due
:
null
,
category
:
''
,
category
:
''
,
hidden
:
false
,
hidden
:
false
,
children
:
[]
children
:
[]
}
},
});
});
edx
.
ccx
.
schedule
.
Schedule
=
Backbone
.
Collection
.
extend
({
model
:
edx
.
ccx
.
schedule
.
UnitModel
,
edx
.
ccx
.
schedule
.
Schedule
=
Backbone
.
Collection
.
extend
({
url
:
'ccx_schedule'
});
model
:
edx
.
ccx
.
schedule
.
UnitModel
,
url
:
'ccx_schedule'
edx
.
ccx
.
schedule
.
ScheduleView
=
Backbone
.
View
.
extend
({
});
initialize
:
function
()
{
_
.
bindAll
(
this
,
'render'
);
edx
.
ccx
.
schedule
.
ScheduleView
=
Backbone
.
View
.
extend
({
this
.
schedule_collection
=
new
edx
.
ccx
.
schedule
.
Schedule
();
this
.
schedule
=
{};
initialize
:
function
()
{
this
.
schedule_collection
.
bind
(
'reset'
,
this
.
render
);
_
.
bindAll
(
this
,
'render'
);
this
.
schedule_collection
.
fetch
({
reset
:
true
});
this
.
schedule_collection
=
new
edx
.
ccx
.
schedule
.
Schedule
();
this
.
chapter_select
=
$
(
'form#add-unit select[name="chapter"]'
);
this
.
schedule
=
{};
this
.
sequential_select
=
$
(
'form#add-unit select[name="sequential"]'
);
this
.
schedule_collection
.
bind
(
'reset'
,
this
.
render
);
this
.
vertical_select
=
$
(
'form#add-unit select[name="vertical"]'
);
this
.
schedule_collection
.
fetch
({
reset
:
true
});
this
.
dirty
=
false
;
this
.
chapter_select
=
$
(
'form#add-unit select[name="chapter"]'
);
self
=
this
;
this
.
sequential_select
=
$
(
'form#add-unit select[name="sequential"]'
);
$
(
'#add-all'
).
on
(
'click'
,
function
(
event
)
{
this
.
vertical_select
=
$
(
'form#add-unit select[name="vertical"]'
);
event
.
preventDefault
();
this
.
dirty
=
false
;
self
.
schedule_apply
(
self
.
schedule
,
self
.
show
);
self
=
this
;
self
.
dirty
=
true
;
$
(
'#add-all'
).
on
(
'click'
,
function
(
event
)
{
self
.
schedule_collection
.
set
(
self
.
schedule
);
event
.
preventDefault
();
self
.
render
();
self
.
schedule_apply
(
self
.
schedule
,
self
.
show
);
});
self
.
dirty
=
true
;
self
.
schedule_collection
.
set
(
self
.
schedule
);
// Add unit handlers
self
.
render
();
this
.
chapter_select
.
on
(
'change'
,
function
()
{
});
var
chapter_location
=
self
.
chapter_select
.
val
();
self
.
vertical_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
// Add unit handlers
if
(
chapter_location
!==
'none'
)
{
this
.
chapter_select
.
on
(
'change'
,
function
()
{
var
chapter
=
self
.
find_unit
(
self
.
hidden
,
chapter_location
);
var
chapter_location
=
self
.
chapter_select
.
val
();
self
.
sequential_select
.
html
(
''
)
self
.
vertical_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
.
append
(
'<option value="all">'
+
gettext
(
"All subsections"
)
+
'</option>'
)
if
(
chapter_location
!==
'none'
)
{
.
append
(
self
.
schedule_options
(
chapter
.
children
));
var
chapter
=
self
.
find_unit
(
self
.
hidden
,
chapter_location
);
self
.
sequential_select
.
prop
(
'disabled'
,
false
);
self
.
sequential_select
.
html
(
''
)
$
(
'#add-unit-button'
).
prop
(
'disabled'
,
false
);
.
append
(
'<option value="all">'
+
gettext
(
"All subsections"
)
+
'</option>'
)
self
.
set_datetime
(
'start'
,
chapter
.
start
);
.
append
(
self
.
schedule_options
(
chapter
.
children
));
self
.
set_datetime
(
'due'
,
chapter
.
due
);
self
.
sequential_select
.
prop
(
'disabled'
,
false
);
}
else
{
$
(
'#add-unit-button'
).
prop
(
'disabled'
,
false
);
self
.
sequential_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
self
.
set_datetime
(
'start'
,
chapter
.
start
);
}
self
.
set_datetime
(
'due'
,
chapter
.
due
);
});
}
else
{
this
.
sequential_select
.
on
(
'change'
,
function
()
{
self
.
sequential_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
var
sequential_location
=
self
.
sequential_select
.
val
();
}
if
(
sequential_location
!==
'all'
)
{
});
var
chapter
=
self
.
chapter_select
.
val
(),
sequential
=
self
.
find_unit
(
self
.
hidden
,
chapter
,
sequential_location
);
this
.
sequential_select
.
on
(
'change'
,
function
()
{
self
.
vertical_select
.
html
(
''
)
var
sequential_location
=
self
.
sequential_select
.
val
();
.
append
(
'<option value="all">'
+
gettext
(
"All units"
)
+
'</option>'
)
if
(
sequential_location
!==
'all'
)
{
.
append
(
self
.
schedule_options
(
sequential
.
children
));
var
chapter
=
self
.
chapter_select
.
val
(),
self
.
vertical_select
.
prop
(
'disabled'
,
false
);
sequential
=
self
.
find_unit
(
self
.
hidden
,
chapter
,
sequential_location
);
self
.
set_datetime
(
'start'
,
sequential
.
start
);
self
.
vertical_select
.
html
(
''
)
self
.
set_datetime
(
'due'
,
sequential
.
due
);
.
append
(
'<option value="all">'
+
gettext
(
"All units"
)
+
'</option>'
)
}
else
{
.
append
(
self
.
schedule_options
(
sequential
.
children
));
self
.
vertical_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
self
.
vertical_select
.
prop
(
'disabled'
,
false
);
}
self
.
set_datetime
(
'start'
,
sequential
.
start
);
});
self
.
set_datetime
(
'due'
,
sequential
.
due
);
}
this
.
vertical_select
.
on
(
'change'
,
function
()
{
else
{
var
vertical_location
=
self
.
vertical_select
.
val
();
self
.
vertical_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
if
(
vertical_location
!==
'all'
)
{
}
var
chapter
=
self
.
chapter_select
.
val
(),
});
sequential
=
self
.
sequential_select
.
val
();
var
vertical
=
self
.
find_unit
(
this
.
vertical_select
.
on
(
'change'
,
function
()
{
self
.
hidden
,
chapter
,
sequential
,
vertical_location
);
var
vertical_location
=
self
.
vertical_select
.
val
();
self
.
set_datetime
(
'start'
,
vertical
.
start
);
if
(
vertical_location
!==
'all'
)
{
self
.
set_datetime
(
'due'
,
vertical
.
due
);
var
chapter
=
self
.
chapter_select
.
val
(),
}
sequential
=
self
.
sequential_select
.
val
();
});
var
vertical
=
self
.
find_unit
(
self
.
hidden
,
chapter
,
sequential
,
vertical_location
);
// Add unit handler
self
.
set_datetime
(
'start'
,
vertical
.
start
);
$
(
'#add-unit-button'
).
on
(
'click'
,
function
(
event
)
{
self
.
set_datetime
(
'due'
,
vertical
.
due
);
event
.
preventDefault
();
}
// Default value of time is 00:00.
});
var
start
,
chapter
,
sequential
,
vertical
,
units
,
due
;
start
=
self
.
get_datetime
(
'start'
);
// Add unit handler
chapter
=
self
.
chapter_select
.
val
();
$
(
'#add-unit-button'
).
on
(
'click'
,
function
(
event
)
{
sequential
=
self
.
sequential_select
.
val
();
event
.
preventDefault
();
vertical
=
self
.
vertical_select
.
val
();
// Default value of time is 00:00.
units
=
self
.
find_lineage
(
var
start
,
chapter
,
sequential
,
vertical
,
units
,
due
;
self
.
schedule
,
start
=
self
.
get_datetime
(
'start'
);
chapter
,
chapter
=
self
.
chapter_select
.
val
();
sequential
===
'all'
?
null
:
sequential
,
sequential
=
self
.
sequential_select
.
val
();
vertical
===
'all'
?
null
:
vertical
vertical
=
self
.
vertical_select
.
val
();
);
units
=
self
.
find_lineage
(
due
=
self
.
get_datetime
(
'due'
);
self
.
schedule
,
var
errorMessage
=
self
.
valid_dates
(
start
,
due
);
chapter
,
if
(
_
.
isUndefined
(
errorMessage
))
{
sequential
===
'all'
?
null
:
sequential
,
units
.
map
(
self
.
show
);
vertical
===
'all'
?
null
:
vertical
var
unit
=
units
[
units
.
length
-
1
];
);
if
(
!
_
.
isUndefined
(
unit
))
{
due
=
self
.
get_datetime
(
'due'
);
if
(
!
_
.
isNull
(
start
))
{
var
errorMessage
=
self
.
valid_dates
(
start
,
due
);
unit
.
start
=
start
;
if
(
_
.
isUndefined
(
errorMessage
))
{
}
units
.
map
(
self
.
show
);
if
(
!
_
.
isNull
(
due
))
{
var
unit
=
units
[
units
.
length
-
1
];
unit
.
due
=
due
;
if
(
!
_
.
isUndefined
(
unit
))
{
}
if
(
!
_
.
isNull
(
start
))
{
}
unit
.
start
=
start
;
self
.
schedule_apply
([
unit
],
self
.
show
);
}
self
.
schedule_collection
.
set
(
self
.
schedule
);
if
(
!
_
.
isNull
(
due
))
{
self
.
dirty
=
true
;
unit
.
due
=
due
;
self
.
render
();
}
}
else
{
}
self
.
dirty
=
false
;
self
.
schedule_apply
([
unit
],
self
.
show
);
$
(
'#ccx_schedule_error_message'
).
text
(
errorMessage
);
self
.
schedule_collection
.
set
(
self
.
schedule
);
$
(
'#ajax-error'
).
show
().
focus
();
self
.
dirty
=
true
;
$
(
'#dirty-schedule'
).
hide
();
self
.
render
();
}
}
else
{
});
self
.
dirty
=
false
;
$
(
'#ccx_schedule_error_message'
).
text
(
errorMessage
);
// Handle save button
$
(
'#ajax-error'
).
show
().
focus
();
$
(
'#dirty-schedule #save-changes'
).
on
(
'click'
,
function
(
event
)
{
$
(
'#dirty-schedule'
).
hide
();
event
.
preventDefault
();
}
self
.
save
();
});
});
},
// end initialization
// Handle save button
$
(
'#dirty-schedule #save-changes'
).
on
(
'click'
,
function
(
event
)
{
render
:
function
()
{
event
.
preventDefault
();
self
.
schedule
=
this
.
schedule_collection
.
toJSON
();
self
.
save
();
self
.
hidden
=
this
.
pruned
(
self
.
schedule
,
function
(
node
)
{
});
return
node
.
hidden
||
node
.
category
!==
'vertical'
;
});
this
.
showing
=
this
.
pruned
(
self
.
schedule
,
function
(
node
)
{
return
!
node
.
hidden
;
});
// schedule_template defined globally in ccx\schedule.html
/* globals schedule_template */
this
.
$el
.
html
(
schedule_template
({
chapters
:
this
.
showing
}));
$
(
'table.ccx-schedule .sequential,.vertical'
).
hide
();
$
(
'table.ccx-schedule .unit .toggle-collapse'
).
on
(
'click'
,
this
.
toggle_collapse
);
// Hidden hover fields for empty date fields
$
(
'table.ccx-schedule .date button'
).
each
(
function
()
{
if
(
$
(
this
).
text
().
trim
()
===
gettext
(
"Click to change"
))
{
$
(
this
).
html
(
'Set date <span class="sr"> '
+
gettext
(
"Click to change"
)
+
'</span>'
);
}
});
// Handle date edit clicks
$
(
'table.ccx-schedule .date button'
).
attr
(
'href'
,
'#enter-date-modal'
)
.
leanModal
({
closeButton
:
'.close-modal'
});
$
(
'table.ccx-schedule .due-date button'
).
on
(
'click'
,
this
.
enterNewDate
(
'due'
));
$
(
'table.ccx-schedule .start-date button'
).
on
(
'click'
,
this
.
enterNewDate
(
'start'
));
// click handler for expand all
$
(
'#ccx_expand_all_btn'
).
on
(
'click'
,
self
.
expandAll
);
// click handler for collapse all
$
(
'#ccx_collapse_all_btn'
).
on
(
'click'
,
self
.
collapseAll
);
// Click handler for remove all
$
(
'table.ccx-schedule button#remove-all'
).
on
(
'click'
,
function
(
event
)
{
event
.
preventDefault
();
self
.
schedule_apply
(
self
.
schedule
,
self
.
hide
);
self
.
dirty
=
true
;
self
.
schedule_collection
.
set
(
self
.
schedule
);
self
.
render
();
});
// Remove unit handler
$
(
'table.ccx-schedule button.remove-unit'
).
on
(
'click'
,
function
()
{
var
row
=
$
(
this
).
closest
(
'tr'
),
path
=
row
.
data
(
'location'
).
split
(
' '
),
unit
=
self
.
find_unit
(
self
.
schedule
,
path
[
0
],
path
[
1
],
path
[
2
]);
self
.
schedule_apply
([
unit
],
self
.
hide
);
self
.
schedule_collection
.
set
(
self
.
schedule
);
self
.
dirty
=
true
;
self
.
render
();
});
// Show or hide form
if
(
this
.
hidden
.
length
)
{
// Populate chapters select, depopulate others
this
.
chapter_select
.
html
(
''
)
.
append
(
'<option value="none">'
+
gettext
(
"Select a chapter"
)
+
'...</option>'
)
.
append
(
self
.
schedule_options
(
this
.
hidden
));
this
.
sequential_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
this
.
vertical_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
$
(
'form#add-unit'
).
show
();
$
(
'#all-units-added'
).
hide
();
$
(
'#add-unit-button'
).
prop
(
'disabled'
,
true
);
}
else
{
$
(
'form#add-unit'
).
hide
();
$
(
'#all-units-added'
).
show
();
}
// Show or hide save button
if
(
this
.
dirty
)
{
$
(
'#dirty-schedule'
).
show
();
$
(
'html, body'
).
animate
(
{
scrollTop
:
$
(
'#dirty-schedule'
).
offset
().
top
},
'slow'
,
function
()
{
$
(
'#dirty-schedule'
).
focus
();
});
}
else
{
$
(
'#dirty-schedule'
).
hide
();
}
$
(
'#ajax-error'
).
hide
();
return
this
;
},
// end render
save
:
function
()
{
self
.
schedule_collection
.
set
(
self
.
schedule
);
var
button
=
$
(
'#dirty-schedule #save-changes'
);
button
.
prop
(
'disabled'
,
true
).
text
(
gettext
(
"Saving"
));
// save_url defined globally in ccx\schedule.html
/* globals save_url */
$
.
ajax
({
url
:
save_url
,
type
:
'POST'
,
contentType
:
'application/json'
,
data
:
JSON
.
stringify
(
self
.
schedule
),
success
:
function
(
data
)
{
self
.
dirty
=
false
;
self
.
render
();
button
.
prop
(
'disabled'
,
false
).
text
(
gettext
(
"Save changes"
));
// Update textarea with grading policy JSON, since grading policy
// may have changed.
$
(
'#grading-policy'
).
text
(
data
.
grading_policy
);
},
},
error
:
function
(
jqXHR
)
{
console
.
log
(
jqXHR
.
responseText
);
$
(
'#ajax-error'
).
show
().
focus
();
$
(
'#dirty-schedule'
).
hide
();
$
(
'form#add-unit select,input,button'
).
prop
(
'disabled'
,
true
);
button
.
prop
(
'disabled'
,
false
).
text
(
gettext
(
"Save changes"
));
}
});
},
// end save
hide
:
function
(
unit
)
{
if
(
unit
!==
undefined
)
{
unit
.
hidden
=
true
;
}
},
render
:
function
()
{
show
:
function
(
unit
)
{
self
.
schedule
=
this
.
schedule_collection
.
toJSON
();
if
(
unit
!==
undefined
)
{
self
.
hidden
=
this
.
pruned
(
self
.
schedule
,
function
(
node
)
{
unit
.
hidden
=
false
;
return
node
.
hidden
||
node
.
category
!==
'vertical'
;});
this
.
showing
=
this
.
pruned
(
self
.
schedule
,
function
(
node
)
{
return
!
node
.
hidden
;});
this
.
$el
.
html
(
schedule_template
({
chapters
:
this
.
showing
}));
$
(
'table.ccx-schedule .sequential,.vertical'
).
hide
();
$
(
'table.ccx-schedule .unit .toggle-collapse'
).
on
(
'click'
,
this
.
toggle_collapse
);
//
// Hidden hover fields for empty date fields
$
(
'table.ccx-schedule .date button'
).
each
(
function
()
{
if
(
$
(
this
).
text
().
trim
()
===
gettext
(
"Click to change"
))
{
$
(
this
).
html
(
'Set date <span class="sr"> '
+
gettext
(
"Click to change"
)
+
'</span>'
);
}
});
// Handle date edit clicks
$
(
'table.ccx-schedule .date button'
).
attr
(
'href'
,
'#enter-date-modal'
)
.
leanModal
({
closeButton
:
'.close-modal'
});
$
(
'table.ccx-schedule .due-date button'
).
on
(
'click'
,
this
.
enterNewDate
(
'due'
));
$
(
'table.ccx-schedule .start-date button'
).
on
(
'click'
,
this
.
enterNewDate
(
'start'
));
// click handler for expand all
$
(
'#ccx_expand_all_btn'
).
on
(
'click'
,
self
.
expandAll
);
// click handler for collapse all
$
(
'#ccx_collapse_all_btn'
).
on
(
'click'
,
self
.
collapseAll
);
// Click handler for remove all
$
(
'table.ccx-schedule button#remove-all'
).
on
(
'click'
,
function
(
event
)
{
event
.
preventDefault
();
self
.
schedule_apply
(
self
.
schedule
,
self
.
hide
);
self
.
dirty
=
true
;
self
.
schedule_collection
.
set
(
self
.
schedule
);
self
.
render
();
});
// Remove unit handler
$
(
'table.ccx-schedule button.remove-unit'
).
on
(
'click'
,
function
()
{
var
row
=
$
(
this
).
closest
(
'tr'
),
path
=
row
.
data
(
'location'
).
split
(
' '
),
unit
=
self
.
find_unit
(
self
.
schedule
,
path
[
0
],
path
[
1
],
path
[
2
]);
self
.
schedule_apply
([
unit
],
self
.
hide
);
self
.
schedule_collection
.
set
(
self
.
schedule
);
self
.
dirty
=
true
;
self
.
render
();
});
// Show or hide form
if
(
this
.
hidden
.
length
)
{
// Populate chapters select, depopulate others
this
.
chapter_select
.
html
(
''
)
.
append
(
'<option value="none">'
+
gettext
(
"Select a chapter"
)
+
'...</option>'
)
.
append
(
self
.
schedule_options
(
this
.
hidden
));
this
.
sequential_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
this
.
vertical_select
.
html
(
''
).
prop
(
'disabled'
,
true
);
$
(
'form#add-unit'
).
show
();
$
(
'#all-units-added'
).
hide
();
$
(
'#add-unit-button'
).
prop
(
'disabled'
,
true
);
}
else
{
$
(
'form#add-unit'
).
hide
();
$
(
'#all-units-added'
).
show
();
}
// Show or hide save button
if
(
this
.
dirty
)
{
$
(
'#dirty-schedule'
).
show
();
$
(
'html, body'
).
animate
(
{
scrollTop
:
$
(
'#dirty-schedule'
).
offset
().
top
},
'slow'
,
function
()
{
$
(
'#dirty-schedule'
).
focus
();}
);
}
}
else
{
$
(
'#dirty-schedule'
).
hide
();}
},
$
(
'#ajax-error'
).
hide
();
valid_dates
:
function
(
start
,
due
)
{
var
errorMessage
;
return
this
;
// Start date is compulsory and due date is optional.
},
if
(
_
.
isEmpty
(
start
)
&&
!
_
.
isEmpty
(
due
))
{
errorMessage
=
gettext
(
"Please enter valid start date and time."
);
save
:
function
(
)
{
}
else
if
(
!
_
.
isEmpty
(
start
)
&&
!
_
.
isEmpty
(
due
)
)
{
self
.
schedule_collection
.
set
(
self
.
schedule
)
;
var
requirejs
=
window
.
require
||
RequireJS
.
require
;
var
button
=
$
(
'#dirty-schedule #save-changes'
);
var
moment
=
requirejs
(
"moment"
);
button
.
prop
(
'disabled'
,
true
).
text
(
gettext
(
"Saving"
)
);
var
parsedDueDate
=
moment
(
due
,
'YYYY-MM-DD HH:mm'
);
var
parsedStartDate
=
moment
(
start
,
'YYYY-MM-DD HH:mm'
);
$
.
ajax
(
{
if
(
parsedDueDate
.
isBefore
(
parsedStartDate
))
{
url
:
save_url
,
errorMessage
=
gettext
(
"Due date cannot be before start date."
);
type
:
'POST'
,
}
contentType
:
'application/json'
,
}
data
:
JSON
.
stringify
(
self
.
schedule
),
return
errorMessage
;
success
:
function
(
data
)
{
},
self
.
dirty
=
false
;
self
.
render
();
get_datetime
:
function
(
which
)
{
button
.
prop
(
'disabled'
,
false
).
text
(
gettext
(
"Save changes"
)
);
var
date
=
$
(
'form#add-unit input[name='
+
which
+
'_date]'
).
val
(
);
var
time
=
$
(
'form#add-unit input[name='
+
which
+
'_time]'
).
val
();
// Update textarea with grading policy JSON, since grading policy
time
=
_
.
isEmpty
(
time
)
?
"00:00"
:
time
;
// may have changed.
if
(
date
&&
time
)
{
$
(
'#grading-policy'
).
text
(
data
.
grading_policy
)
;
return
date
+
' '
+
time
;
},
}
error
:
function
(
jqXHR
)
{
return
null
;
console
.
log
(
jqXHR
.
responseText
);
},
$
(
'#ajax-error'
).
show
().
focus
();
$
(
'#dirty-schedule'
).
hide
();
set_datetime
:
function
(
which
,
value
)
{
$
(
'form#add-unit select,input,button'
).
prop
(
'disabled'
,
true
);
var
parts
=
value
?
value
.
split
(
' '
)
:
[
''
,
''
],
button
.
prop
(
'disabled'
,
false
).
text
(
gettext
(
"Save changes"
));
date
=
parts
[
0
],
}
time
=
parts
[
1
];
}
);
$
(
'form#add-unit input[name='
+
which
+
'_date]'
).
val
(
date
);
},
$
(
'form#add-unit input[name='
+
which
+
'_time]'
).
val
(
time
);
},
hide
:
function
(
unit
)
{
if
(
unit
!==
undefined
)
{
schedule_options
:
function
(
nodes
)
{
unit
.
hidden
=
true
;
return
nodes
.
map
(
function
(
node
)
{
}
return
$
(
'<option>'
)
},
.
attr
(
'value'
,
node
.
location
)
.
text
(
node
.
display_name
)[
0
];
show
:
function
(
unit
)
{
});
if
(
unit
!==
undefined
)
{
},
unit
.
hidden
=
false
;
}
schedule_apply
:
function
(
nodes
,
f
)
{
},
nodes
.
map
(
function
(
node
)
{
f
(
node
);
valid_dates
:
function
(
start
,
due
)
{
if
(
node
!==
undefined
&&
node
.
children
!==
undefined
)
{
var
errorMessage
;
self
.
schedule_apply
(
node
.
children
,
f
)
;
// Start date is compulsory and due date is optional.
}
if
(
_
.
isEmpty
(
start
)
&&
!
_
.
isEmpty
(
due
))
{
});
errorMessage
=
gettext
(
"Please enter valid start date and time."
);
},
}
else
if
(
!
_
.
isEmpty
(
start
)
&&
!
_
.
isEmpty
(
due
))
{
var
requirejs
=
window
.
require
||
RequireJS
.
require
;
pruned
:
function
(
tree
,
filter
)
{
var
moment
=
requirejs
(
"moment"
);
return
tree
.
filter
(
filter
)
var
parsedDueDate
=
moment
(
due
,
'YYYY-MM-DD HH:mm'
);
.
map
(
function
(
node
)
{
var
parsedStartDate
=
moment
(
start
,
'YYYY-MM-DD HH:mm'
)
;
var
copy
=
{}
;
if
(
parsedDueDate
.
isBefore
(
parsedStartDate
))
{
$
.
extend
(
copy
,
node
);
errorMessage
=
gettext
(
"Due date cannot be before start date."
);
if
(
node
.
children
)
{
}
copy
.
children
=
self
.
pruned
(
node
.
children
,
filter
);
}
}
return
errorMessage
;
return
copy
;
},
}).
filter
(
function
(
node
)
{
return
node
.
children
===
undefined
||
node
.
children
.
length
;
get_datetime
:
function
(
which
)
{
});
var
date
=
$
(
'form#add-unit input[name='
+
which
+
'_date]'
).
val
();
},
var
time
=
$
(
'form#add-unit input[name='
+
which
+
'_time]'
).
val
();
time
=
_
.
isEmpty
(
time
)
?
"00:00"
:
time
;
toggle_collapse
:
function
(
event
)
{
if
(
date
&&
time
)
{
event
.
preventDefault
();
return
date
+
' '
+
time
;
}
var
row
=
$
(
this
).
closest
(
'tr'
);
return
null
;
var
children
=
self
.
get_children
(
row
);
},
if
(
row
.
is
(
'.expanded'
))
{
set_datetime
:
function
(
which
,
value
)
{
$
(
this
).
attr
(
'aria-expanded'
,
'false'
);
var
parts
=
value
?
value
.
split
(
' '
)
:
[
''
,
''
],
$
(
this
).
find
(
".fa-caret-down"
).
removeClass
(
'fa-caret-down'
).
addClass
(
'fa-caret-right'
);
date
=
parts
[
0
],
row
.
removeClass
(
'expanded'
).
addClass
(
'collapsed'
);
time
=
parts
[
1
];
children
.
hide
();
$
(
'form#add-unit input[name='
+
which
+
'_date]'
).
val
(
date
);
}
else
{
$
(
'form#add-unit input[name='
+
which
+
'_time]'
).
val
(
time
);
$
(
this
).
attr
(
'aria-expanded'
,
'true'
);
},
$
(
this
).
find
(
".fa-caret-right"
).
removeClass
(
'fa-caret-right'
).
addClass
(
'fa-caret-down'
);
schedule_options
:
function
(
nodes
)
{
return
nodes
.
map
(
function
(
node
)
{
return
$
(
'<option>'
)
.
attr
(
'value'
,
node
.
location
)
.
text
(
node
.
display_name
)[
0
];
});
},
schedule_apply
:
function
(
nodes
,
f
)
{
nodes
.
map
(
function
(
node
)
{
f
(
node
);
if
(
node
!==
undefined
&&
node
.
children
!==
undefined
)
{
self
.
schedule_apply
(
node
.
children
,
f
);
}
});
},
pruned
:
function
(
tree
,
filter
)
{
return
tree
.
filter
(
filter
)
.
map
(
function
(
node
)
{
var
copy
=
{};
$
.
extend
(
copy
,
node
);
if
(
node
.
children
)
{
copy
.
children
=
self
.
pruned
(
node
.
children
,
filter
);}
return
copy
;
})
.
filter
(
function
(
node
)
{
return
node
.
children
===
undefined
||
node
.
children
.
length
;
});
},
toggle_collapse
:
function
(
event
)
{
event
.
preventDefault
();
var
row
=
$
(
this
).
closest
(
'tr'
);
var
children
=
self
.
get_children
(
row
);
if
(
row
.
is
(
'.expanded'
))
{
$
(
this
).
attr
(
'aria-expanded'
,
'false'
);
$
(
this
).
find
(
".fa-caret-down"
).
removeClass
(
'fa-caret-down'
).
addClass
(
'fa-caret-right'
);
row
.
removeClass
(
'expanded'
).
addClass
(
'collapsed'
);
children
.
hide
();
}
else
{
$
(
this
).
attr
(
'aria-expanded'
,
'true'
);
$
(
this
).
find
(
".fa-caret-right"
).
removeClass
(
'fa-caret-right'
).
addClass
(
'fa-caret-down'
);
row
.
removeClass
(
'collapsed'
).
addClass
(
'expanded'
);
children
.
filter
(
'.collapsed'
).
each
(
function
()
{
children
=
children
.
not
(
self
.
get_children
(
this
));
});
children
.
show
();
}
},
expandAll
:
function
()
{
$
(
'table.ccx-schedule > tbody > tr'
).
each
(
function
()
{
var
row
=
$
(
this
);
if
(
!
row
.
is
(
'.expanded'
))
{
var
children
=
self
.
get_children
(
row
);
row
.
find
(
".ccx_sr_alert"
).
attr
(
"aria-expanded"
,
"true"
);
row
.
find
(
".fa-caret-right"
).
removeClass
(
'fa-caret-right'
).
addClass
(
'fa-caret-down'
);
row
.
removeClass
(
'collapsed'
).
addClass
(
'expanded'
);
row
.
removeClass
(
'collapsed'
).
addClass
(
'expanded'
);
children
.
filter
(
'.collapsed'
).
each
(
function
()
{
children
.
filter
(
'.collapsed'
).
each
(
function
()
{
children
=
children
.
not
(
self
.
get_children
(
this
));
children
=
children
.
not
(
self
.
get_children
(
this
));
});
});
children
.
show
();
children
.
show
();
}
}
});
},
},
collapseAll
:
function
()
{
expandAll
:
function
()
{
$
(
'table.ccx-schedule > tbody > tr'
).
each
(
function
()
{
$
(
'table.ccx-schedule > tbody > tr'
).
each
(
function
()
{
var
row
=
$
(
this
);
var
row
=
$
(
this
);
if
(
row
.
is
(
'.expanded'
))
{
if
(
!
row
.
is
(
'.expanded'
))
{
$
(
row
).
find
(
'.ccx_sr_alert'
).
attr
(
'aria-expanded'
,
'false'
);
var
children
=
self
.
get_children
(
row
);
$
(
row
).
find
(
'.fa-caret-down'
).
removeClass
(
'fa-caret-down'
).
addClass
(
'fa-caret-right'
);
row
.
find
(
".ccx_sr_alert"
).
attr
(
"aria-expanded"
,
"true"
);
row
.
removeClass
(
'expanded'
).
addClass
(
'collapsed'
);
row
.
find
(
".fa-caret-right"
).
removeClass
(
'fa-caret-right'
).
addClass
(
'fa-caret-down'
);
$
(
'table.ccx-schedule .sequential,.vertical'
).
hide
();
row
.
removeClass
(
'collapsed'
).
addClass
(
'expanded'
);
}
children
.
filter
(
'.collapsed'
).
each
(
function
()
{
});
children
=
children
.
not
(
self
.
get_children
(
this
));
});
},
children
.
show
();
enterNewDate
:
function
(
what
)
{
}
return
function
()
{
});
var
row
=
$
(
this
).
closest
(
'tr'
);
},
var
modal
=
$
(
'#enter-date-modal'
)
.
data
(
'what'
,
what
)
collapseAll
:
function
()
{
.
data
(
'location'
,
row
.
data
(
'location'
));
$
(
'table.ccx-schedule > tbody > tr'
).
each
(
function
()
{
modal
.
find
(
'h2'
).
text
(
var
row
=
$
(
this
);
what
===
'due'
?
gettext
(
"Enter Due Date and Time"
)
:
if
(
row
.
is
(
'.expanded'
))
{
gettext
(
"Enter Start Date and Time"
));
$
(
row
).
find
(
'.ccx_sr_alert'
).
attr
(
'aria-expanded'
,
'false'
);
$
(
row
).
find
(
'.fa-caret-down'
).
removeClass
(
'fa-caret-down'
).
addClass
(
'fa-caret-right'
);
row
.
removeClass
(
'expanded'
).
addClass
(
'collapsed'
);
$
(
'table.ccx-schedule .sequential,.vertical'
).
hide
();
}
});
},
enterNewDate
:
function
(
what
)
{
return
function
()
{
var
row
=
$
(
this
).
closest
(
'tr'
);
var
modal
=
$
(
'#enter-date-modal'
)
.
data
(
'what'
,
what
)
.
data
(
'location'
,
row
.
data
(
'location'
));
modal
.
find
(
'h2'
).
text
(
what
===
'due'
?
gettext
(
"Enter Due Date and Time"
)
:
gettext
(
"Enter Start Date and Time"
)
);
modal
.
focus
();
modal
.
focus
();
$
(
document
).
on
(
'focusin'
,
function
(
event
)
{
$
(
document
).
on
(
'focusin'
,
function
(
event
)
{
try
{
try
{
if
(
!
_
.
isUndefined
(
event
.
target
.
closest
(
'.modal'
).
id
)
&&
if
(
!
_
.
isUndefined
(
event
.
target
.
closest
(
'.modal'
).
id
)
&&
event
.
target
.
closest
(
'.modal'
).
id
!==
'enter-date-modal'
&&
event
.
target
.
closest
(
'.modal'
).
id
!==
'enter-date-modal'
&&
event
.
target
.
id
!==
'enter-date-modal'
)
{
event
.
target
.
id
!==
'enter-date-modal'
)
{
event
.
preventDefault
();
event
.
preventDefault
();
modal
.
find
(
'.close-modal'
).
focus
();
modal
.
find
(
'.close-modal'
).
focus
();
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
event
.
preventDefault
();
event
.
preventDefault
();
modal
.
find
(
'.close-modal'
).
focus
();
modal
.
find
(
'.close-modal'
).
focus
();
...
@@ -407,79 +406,71 @@ var edx = edx || {};
...
@@ -407,79 +406,71 @@ var edx = edx || {};
modal
.
find
(
'.close-modal'
).
click
(
function
()
{
modal
.
find
(
'.close-modal'
).
click
(
function
()
{
$
(
document
).
off
(
'focusin'
);
$
(
document
).
off
(
'focusin'
);
});
});
var
path
=
row
.
data
(
'location'
).
split
(
' '
),
var
path
=
row
.
data
(
'location'
).
split
(
' '
),
unit
=
self
.
find_unit
(
self
.
schedule
,
path
[
0
],
path
[
1
],
path
[
2
]),
unit
=
self
.
find_unit
(
self
.
schedule
,
path
[
0
],
path
[
1
],
path
[
2
]),
parts
=
unit
[
what
]
?
unit
[
what
].
split
(
' '
)
:
[
''
,
''
],
parts
=
unit
[
what
]
?
unit
[
what
].
split
(
' '
)
:
[
''
,
''
],
date
=
parts
[
0
],
date
=
parts
[
0
],
time
=
parts
[
1
];
time
=
parts
[
1
];
modal
.
find
(
'input[name=date]'
).
val
(
date
);
modal
.
find
(
'input[name=date]'
).
val
(
date
);
modal
.
find
(
'input[name=time]'
).
val
(
time
);
modal
.
find
(
'input[name=time]'
).
val
(
time
);
modal
.
find
(
'form'
).
off
(
'submit'
).
on
(
'submit'
,
function
(
event
)
{
event
.
preventDefault
();
modal
.
find
(
'form'
).
off
(
'submit'
).
on
(
'submit'
,
function
(
event
)
{
var
date
=
$
(
this
).
find
(
'input[name=date]'
).
val
(),
event
.
preventDefault
();
time
=
$
(
this
).
find
(
'input[name=time]'
).
val
();
var
date
=
$
(
this
).
find
(
'input[name=date]'
).
val
(),
var
valid_date
=
new
Date
(
date
);
time
=
$
(
this
).
find
(
'input[name=time]'
).
val
();
if
(
isNaN
(
valid_date
.
valueOf
()))
{
var
valid_date
=
new
Date
(
date
);
alert
(
'Please enter a valid date'
);
if
(
isNaN
(
valid_date
.
valueOf
()))
{
return
;
alert
(
'Please enter a valid date'
);
}
return
;
var
valid_time
=
/^
\d{1,2}
:
\d{2}?
$/
;
}
if
(
!
time
.
match
(
valid_time
))
{
var
valid_time
=
/^
\d{1,2}
:
\d{2}?
$/
;
alert
(
'Please enter a valid time'
);
if
(
!
time
.
match
(
valid_time
))
{
return
;
alert
(
'Please enter a valid time'
);
}
return
;
if
(
what
===
'start'
)
{
}
unit
.
start
=
date
+
' '
+
time
;
if
(
what
===
'start'
)
{
}
else
{
unit
.
start
=
date
+
' '
+
time
;
unit
.
due
=
date
+
' '
+
time
;
}
else
{
}
unit
.
due
=
date
+
' '
+
time
;
modal
.
find
(
'.close-modal'
).
click
();
}
self
.
dirty
=
true
;
modal
.
find
(
'.close-modal'
).
click
();
self
.
schedule_collection
.
set
(
self
.
schedule
);
self
.
dirty
=
true
;
self
.
render
();
self
.
schedule_collection
.
set
(
self
.
schedule
);
});
self
.
render
();
};
});
},
};
},
find_unit
:
function
(
tree
,
chapter
,
sequential
,
vertical
)
{
var
units
=
self
.
find_lineage
(
tree
,
chapter
,
sequential
,
vertical
);
find_unit
:
function
(
tree
,
chapter
,
sequential
,
vertical
)
{
return
units
[
units
.
length
-
1
];
var
units
=
self
.
find_lineage
(
tree
,
chapter
,
sequential
,
vertical
);
},
return
units
[
units
.
length
-
1
];
},
find_lineage
:
function
(
tree
,
chapter
,
sequential
,
vertical
)
{
function
find_in
(
seq
,
location
)
{
find_lineage
:
function
(
tree
,
chapter
,
sequential
,
vertical
)
{
for
(
var
i
=
0
;
i
<
seq
.
length
;
i
++
)
{
function
find_in
(
seq
,
location
)
{
if
(
seq
[
i
].
location
===
location
)
{
for
(
var
i
=
0
;
i
<
seq
.
length
;
i
++
)
{
return
seq
[
i
];
if
(
seq
[
i
].
location
===
location
)
{
}
return
seq
[
i
];}
}
}}
}
var
units
=
[],
var
units
=
[],
unit
=
find_in
(
tree
,
chapter
);
unit
=
find_in
(
tree
,
chapter
);
units
[
units
.
length
]
=
unit
;
units
[
units
.
length
]
=
unit
;
if
(
sequential
)
{
if
(
sequential
)
{
units
[
units
.
length
]
=
unit
=
find_in
(
unit
.
children
,
sequential
);
units
[
units
.
length
]
=
unit
=
find_in
(
unit
.
children
,
sequential
);
if
(
vertical
)
{
if
(
vertical
)
{
units
[
units
.
length
]
=
unit
=
find_in
(
unit
.
children
,
vertical
);
units
[
units
.
length
]
=
unit
=
find_in
(
unit
.
children
,
vertical
);}
}
}
}
return
units
;
return
units
;
},
},
get_children
:
function
(
row
)
{
var
depth
=
$
(
row
).
data
(
'depth'
);
get_children
:
function
(
row
)
{
return
$
(
row
).
nextUntil
(
var
depth
=
$
(
row
).
data
(
'depth'
);
$
(
row
).
siblings
().
filter
(
function
()
{
return
$
(
row
).
nextUntil
(
return
$
(
this
).
data
(
'depth'
)
<=
depth
;
$
(
row
).
siblings
().
filter
(
function
()
{
})
return
$
(
this
).
data
(
'depth'
)
<=
depth
;
);
})
}
);
});
}
});
})(
jQuery
,
_
,
Backbone
,
gettext
);
})(
jQuery
,
_
,
Backbone
,
gettext
);
lms/static/lms/js/require-config.js
View file @
a02ca255
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
"annotator_1.2.9"
:
"js/vendor/edxnotes/annotator-full.min"
,
"annotator_1.2.9"
:
"js/vendor/edxnotes/annotator-full.min"
,
"date"
:
"js/vendor/date"
,
"date"
:
"js/vendor/date"
,
"moment"
:
"js/vendor/moment.min"
,
"moment"
:
"js/vendor/moment.min"
,
"moment-with-locales"
:
"js/vendor/moment-with-locales.min"
,
"moment-with-locales"
:
"
xmodule_js/common_static/
js/vendor/moment-with-locales.min"
,
"text"
:
"js/vendor/requirejs/text"
,
"text"
:
"js/vendor/requirejs/text"
,
"logger"
:
"js/src/logger"
,
"logger"
:
"js/src/logger"
,
"backbone"
:
"js/vendor/backbone-min"
,
"backbone"
:
"js/vendor/backbone-min"
,
...
...
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