Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected.

Blades: Update behavior of start/end time fields. BLD-506.

Blades: Make LTI module not send grade_back_url if has_score=False. BLD-561.

Blades: Show answer for imageresponse. BLD-21.
Expand Down
14 changes: 12 additions & 2 deletions cms/djangoapps/contentstore/features/transcripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,18 @@ def open_tab(_step, tab_name):

@step('I set value "([^"]*)" to the field "([^"]*)"$')
def set_value_transcripts_field(_step, value, field_name):
field_id = '#' + world.browser.find_by_xpath('//label[text()="%s"]' % field_name.strip())[0]['for']
world.css_fill(field_id, value.strip())
XPATH = '//label[text()="{name}"]'.format(name=field_name)
SELECTOR = '#' + world.browser.find_by_xpath(XPATH)[0]['for']
element = world.css_find(SELECTOR).first
if element['type'] == 'text':
SCRIPT = '$("{selector}").val("{value}").change()'.format(
selector=SELECTOR,
value=value
)
world.browser.execute_script(SCRIPT)
assert world.css_has_value(SELECTOR, value)
else:
assert False, 'Incorrect element type.';
world.wait_for_ajax_complete()


Expand Down
5 changes: 0 additions & 5 deletions cms/static/coffee/spec/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ requirejs.config({
"jquery.iframe-transport": "xmodule_js/common_static/js/vendor/jQuery-File-Upload/js/jquery.iframe-transport",
"jquery.inputnumber": "xmodule_js/common_static/js/vendor/html5-input-polyfills/number-polyfill",
"jquery.immediateDescendents": "xmodule_js/common_static/coffee/src/jquery.immediateDescendents",
"jquery.maskedinput": "xmodule_js/common_static/js/vendor/jquery.maskedinput.min",
"datepair": "xmodule_js/common_static/js/vendor/timepicker/datepair",
"date": "xmodule_js/common_static/js/vendor/date",
"underscore": "xmodule_js/common_static/js/vendor/underscore-min",
Expand Down Expand Up @@ -98,10 +97,6 @@ requirejs.config({
deps: ["jquery"],
exports: "jQuery.fn.inputNumber"
},
"jquery.maskedinput": {
deps: ["jquery"],
exports: "jQuery.fn.mask"
},
"jquery.tinymce": {
deps: ["jquery", "tinymce"],
exports: "jQuery.fn.tinymce"
Expand Down
87 changes: 87 additions & 0 deletions cms/static/coffee/spec/views/metadata_edit_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,95 @@ define ["js/models/metadata", "js/collections/metadata", "js/views/metadata", "c
it "returns the intial value upon initialization", ->
assertValueInView(@view, '12:12:12')

it "value is converted correctly", ->
view = @view

cases = [
{
input: '23:100:0'
output: '23:59:59'
},
{
input: '100000000000000000'
output: '23:59:59'
},
{
input: '80000'
output: '22:13:20'
},
{
input: '-100'
output: '00:00:00'
},
{
input: '-100:-10'
output: '00:00:00'
},
{
input: '99:99'
output: '01:40:39'
},
{
input: '2'
output: '00:00:02'
},
{
input: '1:2'
output: '00:01:02'
},
{
input: '1:25'
output: '00:01:25'
},
{
input: '3:1:25'
output: '03:01:25'
},
{
input: ' 2 3 : 5 9 : 5 9 '
output: '23:59:59'
},
{
input: '9:1:25'
output: '09:01:25'
},
{
input: '77:72:77'
output: '23:59:59'
},
{
input: '22:100:100'
output: '23:41:40'
},
# negative value
{
input: '-22:22:22'
output: '00:22:22'
},
# simple string
{
input: 'simple text'
output: '00:00:00'
},
{
input: 'a10a:a10a:a10a'
output: '00:00:00'
},
# empty string
{
input: ''
output: '00:00:00'
}
]

$.each cases, (index, data) ->
expect(view.parseRelativeTime(data.input)).toBe(data.output)

it "can update its value in the view", ->
assertCanUpdateView(@view, "23:59:59")
@view.setValueInEditor("33:59:59")
@view.updateModel()
assertValueInView(@view, "23:59:59")

it "has a clear method to revert to the model default", ->
assertClear(@view, '00:00:00')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@polesye Please use 4 spaces indentation throughout the file.

Expand Down
85 changes: 52 additions & 33 deletions cms/static/js/views/metadata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
define(
[
"backbone", "underscore", "js/models/metadata", "js/views/abstract_editor",
"js/views/transcripts/metadata_videolist", "jquery.maskedinput"
"js/views/transcripts/metadata_videolist"
],
function(Backbone, _, MetadataModel, AbstractEditor, VideoList) {
var Metadata = {};
Expand Down Expand Up @@ -301,6 +301,11 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) {

Metadata.RelativeTime = AbstractEditor.extend({

defaultValue : '00:00:00',
// By default max value of RelativeTime field on Backend is 23:59:59,
// that is 86399 seconds.
maxTimeInSeconds : 86399,

events : {
"change input" : "updateModel",
"keypress .setting-input" : "showClearButton" ,
Expand All @@ -309,46 +314,60 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) {

templateName: "metadata-string-entry",

initialize: function () {
AbstractEditor.prototype.initialize.apply(this);

// This list of definitions is used for creating appropriate
// time format mask;
//
// For example, mask 'hH:mM:sS':
// min value: 00:00:00
// max value: 23:59:59
//
// With this mask user cannot set following values:
// 93:23:23, 23:60:60, 77:77:77, etc.
var definitions = {
h: '[0-2]',
H: '[0-3]',
m: '[0-5]',
s: '[0-5]',
M: '[0-9]',
S: '[0-9]'
};

$.each(definitions, function(key, value) {
$.mask.definitions[key] = value;
});
getValueFromEditor : function () {
var $input = this.$el.find('#' + this.uniqueId);

this.$el
.find('#' + this.uniqueId)
.mask('hH:mM:sS', { placeholder: '0' });
return $input.val();
},

getValueFromEditor : function () {
var $input = this.$el.find('#' + this.uniqueId),
value = $input.val();
updateModel: function () {
var value = this.getValueFromEditor(),
time = this.parseRelativeTime(value);

this.model.setValue(time);

// Sometimes, `parseRelativeTime` method returns the same value for
// the different inputs. In this case, model will not be
// updated (it already has the same value) and we should
// call `render` method manually.
// Examples:
// value => 23:59:59; parseRelativeTime => 23:59:59
// value => 44:59:59; parseRelativeTime => 23:59:59
if (value !== time && !this.model.hasChanged('value')) {
this.render();
}
},

return value;
parseRelativeTime: function (value) {
// This function ensure you have two-digits
var pad = function (number) {
return (number < 10) ? "0" + number : number;
},
// Removes all white-spaces and splits by `:`.
list = value.replace(/\s+/g, '').split(':'),
seconds, date;

list = _.map(list, function(num) {
return Math.max(0, parseInt(num, 10) || 0);
}).reverse();

seconds = _.reduce(list, function(memo, num, index) {
return memo + num * Math.pow(60, index);
}, 0);

// multiply by 1000 because Date() requires milliseconds
date = new Date(Math.min(seconds, this.maxTimeInSeconds) * 1000);

return [
pad(date.getUTCHours()),
pad(date.getUTCMinutes()),
pad(date.getUTCSeconds())
].join(':');
},

setValueInEditor : function (value) {
if (!value) {
value = '00:00:00';
value = this.defaultValue;
}

this.$el.find('input').val(value);
Expand Down
1 change: 0 additions & 1 deletion cms/static/js_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ lib_paths:
- xmodule_js/common_static/js/vendor/jasmine-stealth.js
- xmodule_js/common_static/js/vendor/jasmine-imagediff.js
- xmodule_js/common_static/js/vendor/jasmine.async.js
- xmodule_js/common_static/js/vendor/jquery.maskedinput.min.js
- xmodule_js/common_static/js/vendor/CodeMirror/codemirror.js
- xmodule_js/src/xmodule.js
- xmodule_js/common_static/js/test/i18n.js
Expand Down
5 changes: 0 additions & 5 deletions cms/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"jquery.qtip": "js/vendor/jquery.qtip.min",
"jquery.scrollTo": "js/vendor/jquery.scrollTo-1.4.2-min",
"jquery.flot": "js/vendor/flot/jquery.flot.min",
"jquery.maskedinput": "js/vendor/jquery.maskedinput.min",
"jquery.fileupload": "js/vendor/jQuery-File-Upload/js/jquery.fileupload",
"jquery.iframe-transport": "js/vendor/jQuery-File-Upload/js/jquery.iframe-transport",
"jquery.inputnumber": "js/vendor/html5-input-polyfills/number-polyfill",
Expand Down Expand Up @@ -138,10 +137,6 @@
deps: ["jquery"],
exports: "jQuery.fn.plot"
},
"jquery.maskedinput": {
deps: ["jquery"],
exports: "jQuery.fn.mask"
},
"jquery.fileupload": {
deps: ["jquery.iframe-transport"],
exports: "jQuery.fn.fileupload"
Expand Down
4 changes: 2 additions & 2 deletions common/lib/xmodule/xmodule/video_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class VideoFields(object):
default=""
)
start_time = RelativeTime( # datetime.timedelta object
help="Start time for the video (HH:MM:SS).",
help="Start time for the video (HH:MM:SS). Max value is 23:59:59.",
display_name="Start Time",
scope=Scope.settings,
default=datetime.timedelta(seconds=0)
)
end_time = RelativeTime( # datetime.timedelta object
help="End time for the video (HH:MM:SS).",
help="End time for the video (HH:MM:SS). Max value is 23:59:59.",
display_name="End Time",
scope=Scope.settings,
default=datetime.timedelta(seconds=0)
Expand Down
7 changes: 0 additions & 7 deletions common/static/js/vendor/jquery.maskedinput.min.js

This file was deleted.