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
37ab2fc1
Commit
37ab2fc1
authored
Apr 27, 2015
by
David Baumgold
Committed by
Sarina Canelake
May 18, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap block with license info in LMS only
parent
ca2fee12
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
539 additions
and
589 deletions
+539
-589
cms/static/js/models/license.js
+86
-86
cms/static/js/spec/models/license_spec.js
+60
-60
cms/static/js/spec/views/license_spec.js
+143
-143
cms/static/js/views/license.js
+124
-124
cms/static/js/views/metadata.js
+2
-1
cms/templates/js/license-selector.underscore
+97
-98
common/lib/xmodule/xmodule/capa_base.py
+0
-9
common/lib/xmodule/xmodule/discussion_module.py
+0
-9
common/lib/xmodule/xmodule/editing_module.py
+9
-0
common/lib/xmodule/xmodule/html_module.py
+0
-36
common/lib/xmodule/xmodule/mixin.py
+11
-0
common/lib/xmodule/xmodule/raw_module.py
+0
-12
common/templates/license_wrapper.html
+3
-0
common/templates/xblock_wrapper.html
+0
-5
lms/djangoapps/courseware/module_render.py
+4
-0
openedx/core/lib/xblock_utils.py
+0
-6
No files found.
cms/static/js/models/license.js
View file @
37ab2fc1
define
([
"backbone"
,
"underscore"
],
function
(
Backbone
,
_
)
{
define
([
"backbone"
,
"underscore"
],
function
(
Backbone
,
_
)
{
var
LicenseModel
=
Backbone
.
Model
.
extend
({
var
LicenseModel
=
Backbone
.
Model
.
extend
({
defaults
:
{
defaults
:
{
"type"
:
null
,
"type"
:
null
,
"options"
:
{},
"options"
:
{},
"custom"
:
false
// either `false`, or a string
"custom"
:
false
// either `false`, or a string
},
},
initialize
:
function
(
attributes
)
{
initialize
:
function
(
attributes
)
{
if
(
attributes
&&
attributes
.
asString
)
{
if
(
attributes
&&
attributes
.
asString
)
{
this
.
setFromString
(
attributes
.
asString
);
this
.
setFromString
(
attributes
.
asString
);
this
.
unset
(
"asString"
);
this
.
unset
(
"asString"
);
}
}
},
},
toString
:
function
()
{
toString
:
function
()
{
var
custom
=
this
.
get
(
"custom"
);
var
custom
=
this
.
get
(
"custom"
);
if
(
custom
)
{
if
(
custom
)
{
return
custom
;
return
custom
;
}
}
var
type
=
this
.
get
(
"type"
),
var
type
=
this
.
get
(
"type"
),
options
=
this
.
get
(
"options"
);
options
=
this
.
get
(
"options"
);
if
(
_
.
isEmpty
(
options
))
{
if
(
_
.
isEmpty
(
options
))
{
return
type
||
""
;
return
type
||
""
;
}
}
// options are where it gets tricky
// options are where it gets tricky
var
optionStrings
=
_
.
map
(
options
,
function
(
value
,
key
)
{
var
optionStrings
=
_
.
map
(
options
,
function
(
value
,
key
)
{
if
(
_
.
isBoolean
(
value
))
{
if
(
_
.
isBoolean
(
value
))
{
return
value
?
key
:
null
return
value
?
key
:
null
}
else
{
}
else
{
return
key
+
"="
+
value
return
key
+
"="
+
value
}
}
});
});
// filter out nulls
// filter out nulls
optionStrings
=
_
.
filter
(
optionStrings
,
_
.
identity
);
optionStrings
=
_
.
filter
(
optionStrings
,
_
.
identity
);
// build license string and return
// build license string and return
return
type
+
": "
+
optionStrings
.
join
(
" "
);
return
type
+
": "
+
optionStrings
.
join
(
" "
);
},
},
setFromString
:
function
(
string
,
options
)
{
setFromString
:
function
(
string
,
options
)
{
if
(
!
string
)
{
if
(
!
string
)
{
// reset to defaults
// reset to defaults
return
this
.
set
(
this
.
defaults
,
options
);
return
this
.
set
(
this
.
defaults
,
options
);
}
}
var
colonIndex
=
string
.
indexOf
(
":"
),
var
colonIndex
=
string
.
indexOf
(
":"
),
spaceIndex
=
string
.
indexOf
(
" "
);
spaceIndex
=
string
.
indexOf
(
" "
);
// a string without a colon could be a custom license, or a license
// a string without a colon could be a custom license, or a license
// type without options
// type without options
if
(
colonIndex
==
-
1
)
{
if
(
colonIndex
==
-
1
)
{
if
(
spaceIndex
==
-
1
)
{
if
(
spaceIndex
==
-
1
)
{
// if there's no space, it's a license type without options
// if there's no space, it's a license type without options
return
this
.
set
({
return
this
.
set
({
"type"
:
string
,
"type"
:
string
,
"options"
:
{},
"options"
:
{},
"custom"
:
false
"custom"
:
false
},
options
);
},
options
);
}
else
{
}
else
{
// if there is a space, it's a custom license
// if there is a space, it's a custom license
return
this
.
set
({
return
this
.
set
({
"type"
:
null
,
"type"
:
null
,
"options"
:
{},
"options"
:
{},
"custom"
:
string
"custom"
:
string
},
options
);
},
options
);
}
}
}
}
// there is a colon, which indicates a license type with options.
// there is a colon, which indicates a license type with options.
var
type
=
string
.
substring
(
0
,
colonIndex
),
var
type
=
string
.
substring
(
0
,
colonIndex
),
optionsObj
=
{},
optionsObj
=
{},
optionsString
=
string
.
substring
(
colonIndex
+
1
);
optionsString
=
string
.
substring
(
colonIndex
+
1
);
_
.
each
(
optionsString
.
split
(
" "
),
function
(
optionString
)
{
_
.
each
(
optionsString
.
split
(
" "
),
function
(
optionString
)
{
if
(
_
.
isEmpty
(
optionString
))
{
if
(
_
.
isEmpty
(
optionString
))
{
return
;
return
;
}
}
var
eqIndex
=
optionString
.
indexOf
(
"="
);
var
eqIndex
=
optionString
.
indexOf
(
"="
);
if
(
eqIndex
==
-
1
)
{
if
(
eqIndex
==
-
1
)
{
// this is a boolean flag
// this is a boolean flag
optionsObj
[
optionString
]
=
true
;
optionsObj
[
optionString
]
=
true
;
}
else
{
}
else
{
// this is a key-value pair
// this is a key-value pair
var
optionKey
=
optionString
.
substring
(
0
,
eqIndex
);
var
optionKey
=
optionString
.
substring
(
0
,
eqIndex
);
var
optionVal
=
optionString
.
substring
(
eqIndex
+
1
);
var
optionVal
=
optionString
.
substring
(
eqIndex
+
1
);
optionsObj
[
optionKey
]
=
optionVal
;
optionsObj
[
optionKey
]
=
optionVal
;
}
}
});
});
return
this
.
set
({
return
this
.
set
({
"type"
:
type
,
"options"
:
optionsObj
,
"custom"
:
false
,
"type"
:
type
,
"options"
:
optionsObj
,
"custom"
:
false
,
},
options
);
},
options
);
}
}
});
});
return
LicenseModel
;
return
LicenseModel
;
});
});
cms/static/js/spec/models/license_spec.js
View file @
37ab2fc1
define
([
"js/models/license"
],
function
(
LicenseModel
)
{
define
([
"js/models/license"
],
function
(
LicenseModel
)
{
describe
(
"License model constructor"
,
function
()
{
describe
(
"License model constructor"
,
function
()
{
it
(
"accepts no arguments"
,
function
()
{
it
(
"accepts no arguments"
,
function
()
{
var
model
=
new
LicenseModel
()
var
model
=
new
LicenseModel
()
expect
(
model
.
get
(
"type"
)).
toBeNull
();
expect
(
model
.
get
(
"type"
)).
toBeNull
();
expect
(
model
.
get
(
"options"
)).
toEqual
({});
expect
(
model
.
get
(
"options"
)).
toEqual
({});
expect
(
model
.
get
(
"custom"
)).
toBeFalsy
();
expect
(
model
.
get
(
"custom"
)).
toBeFalsy
();
});
});
it
(
"accepts normal arguments"
,
function
()
{
it
(
"accepts normal arguments"
,
function
()
{
var
model
=
new
LicenseModel
({
var
model
=
new
LicenseModel
({
"type"
:
"creative-commons"
,
"type"
:
"creative-commons"
,
"options"
:
{
"fake-boolean"
:
true
,
"version"
:
"your momma"
}
"options"
:
{
"fake-boolean"
:
true
,
"version"
:
"your momma"
}
});
});
expect
(
model
.
get
(
"type"
)).
toEqual
(
"creative-commons"
);
expect
(
model
.
get
(
"type"
)).
toEqual
(
"creative-commons"
);
expect
(
model
.
get
(
"options"
)).
toEqual
({
"fake-boolean"
:
true
,
"version"
:
"your momma"
});
expect
(
model
.
get
(
"options"
)).
toEqual
({
"fake-boolean"
:
true
,
"version"
:
"your momma"
});
})
})
it
(
"accepts a license string argument"
,
function
()
{
it
(
"accepts a license string argument"
,
function
()
{
var
model
=
new
LicenseModel
({
"asString"
:
"all-rights-reserved"
});
var
model
=
new
LicenseModel
({
"asString"
:
"all-rights-reserved"
});
expect
(
model
.
get
(
"type"
)).
toEqual
(
"all-rights-reserved"
);
expect
(
model
.
get
(
"type"
)).
toEqual
(
"all-rights-reserved"
);
expect
(
model
.
get
(
"options"
)).
toEqual
({});
expect
(
model
.
get
(
"options"
)).
toEqual
({});
expect
(
model
.
get
(
"custom"
)).
toBeFalsy
();
expect
(
model
.
get
(
"custom"
)).
toBeFalsy
();
});
});
it
(
"accepts a custom license argument"
,
function
()
{
it
(
"accepts a custom license argument"
,
function
()
{
var
model
=
new
LicenseModel
({
"asString"
:
"Mozilla Public License 2.0"
})
var
model
=
new
LicenseModel
({
"asString"
:
"Mozilla Public License 2.0"
})
expect
(
model
.
get
(
"type"
)).
toBeNull
();
expect
(
model
.
get
(
"type"
)).
toBeNull
();
expect
(
model
.
get
(
"options"
)).
toEqual
({});
expect
(
model
.
get
(
"options"
)).
toEqual
({});
expect
(
model
.
get
(
"custom"
)).
toEqual
(
"Mozilla Public License 2.0"
);
expect
(
model
.
get
(
"custom"
)).
toEqual
(
"Mozilla Public License 2.0"
);
});
});
});
});
describe
(
"License model"
,
function
()
{
describe
(
"License model"
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
model
=
new
LicenseModel
();
this
.
model
=
new
LicenseModel
();
});
});
it
(
"can parse license strings"
,
function
()
{
it
(
"can parse license strings"
,
function
()
{
this
.
model
.
setFromString
(
"creative-commons: BY"
)
this
.
model
.
setFromString
(
"creative-commons: BY"
)
expect
(
this
.
model
.
get
(
"type"
)).
toEqual
(
"creative-commons"
)
expect
(
this
.
model
.
get
(
"type"
)).
toEqual
(
"creative-commons"
)
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
({
"BY"
:
true
})
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
({
"BY"
:
true
})
expect
(
this
.
model
.
get
(
"custom"
)).
toBeFalsy
();
expect
(
this
.
model
.
get
(
"custom"
)).
toBeFalsy
();
});
});
it
(
"can stringify a null license"
,
function
()
{
it
(
"can stringify a null license"
,
function
()
{
expect
(
this
.
model
.
toString
()).
toEqual
(
""
);
expect
(
this
.
model
.
toString
()).
toEqual
(
""
);
});
});
it
(
"can stringify a simple license"
,
function
()
{
it
(
"can stringify a simple license"
,
function
()
{
this
.
model
.
set
(
"type"
,
"foobie thinger"
);
this
.
model
.
set
(
"type"
,
"foobie thinger"
);
expect
(
this
.
model
.
toString
()).
toEqual
(
"foobie thinger"
);
expect
(
this
.
model
.
toString
()).
toEqual
(
"foobie thinger"
);
});
});
it
(
"can stringify a license with options"
,
function
()
{
it
(
"can stringify a license with options"
,
function
()
{
this
.
model
.
set
({
this
.
model
.
set
({
"type"
:
"abc"
,
"type"
:
"abc"
,
"options"
:
{
"ping"
:
"pong"
,
"bing"
:
true
,
"buzz"
:
true
,
"beep"
:
false
}}
"options"
:
{
"ping"
:
"pong"
,
"bing"
:
true
,
"buzz"
:
true
,
"beep"
:
false
}}
);
);
expect
(
this
.
model
.
toString
()).
toEqual
(
"abc: ping=pong bing buzz"
);
expect
(
this
.
model
.
toString
()).
toEqual
(
"abc: ping=pong bing buzz"
);
});
});
it
(
"can stringify a custom license"
,
function
()
{
it
(
"can stringify a custom license"
,
function
()
{
this
.
model
.
set
({
this
.
model
.
set
({
"type"
:
"doesn't matter"
,
"type"
:
"doesn't matter"
,
"options"
:
{
"ignore"
:
"me"
},
"options"
:
{
"ignore"
:
"me"
},
"custom"
:
"this is my super cool license"
"custom"
:
"this is my super cool license"
});
});
expect
(
this
.
model
.
toString
()).
toEqual
(
"this is my super cool license"
);
expect
(
this
.
model
.
toString
()).
toEqual
(
"this is my super cool license"
);
});
});
})
})
})
})
cms/static/js/spec/views/license_spec.js
View file @
37ab2fc1
define
([
"js/views/license"
,
"js/models/license"
,
"js/common_helpers/template_helpers"
],
define
([
"js/views/license"
,
"js/models/license"
,
"js/common_helpers/template_helpers"
],
function
(
LicenseView
,
LicenseModel
,
TemplateHelpers
)
{
function
(
LicenseView
,
LicenseModel
,
TemplateHelpers
)
{
describe
(
"License view"
,
function
()
{
describe
(
"License view"
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
TemplateHelpers
.
installTemplate
(
"license-selector"
,
true
);
TemplateHelpers
.
installTemplate
(
"license-selector"
,
true
);
this
.
model
=
new
LicenseModel
();
this
.
model
=
new
LicenseModel
();
this
.
view
=
new
LicenseView
({
model
:
this
.
model
});
this
.
view
=
new
LicenseView
({
model
:
this
.
model
});
});
});
it
(
"renders with no license"
,
function
()
{
it
(
"renders with no license"
,
function
()
{
this
.
view
.
render
();
this
.
view
.
render
();
expect
(
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
))
expect
(
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
))
.
toHaveText
(
"All Rights Reserved"
);
.
toHaveText
(
"All Rights Reserved"
);
expect
(
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
))
expect
(
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
))
.
not
.
toHaveClass
(
"is-selected"
);
.
not
.
toHaveClass
(
"is-selected"
);
expect
(
this
.
view
.
$
(
"li[data-license=creative-commons] button"
))
expect
(
this
.
view
.
$
(
"li[data-license=creative-commons] button"
))
.
toHaveText
(
"Creative Commons"
);
.
toHaveText
(
"Creative Commons"
);
expect
(
this
.
view
.
$
(
"li[data-license=creative-commons] button"
))
expect
(
this
.
view
.
$
(
"li[data-license=creative-commons] button"
))
.
not
.
toHaveClass
(
"is-selected"
);
.
not
.
toHaveClass
(
"is-selected"
);
});
});
it
(
"renders with the right license selected"
,
function
()
{
it
(
"renders with the right license selected"
,
function
()
{
this
.
model
.
set
(
"type"
,
"all-rights-reserved"
);
this
.
model
.
set
(
"type"
,
"all-rights-reserved"
);
expect
(
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
))
expect
(
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
))
.
toHaveClass
(
"is-selected"
);
.
toHaveClass
(
"is-selected"
);
expect
(
this
.
view
.
$
(
"li[data-license=creative-commons] button"
))
expect
(
this
.
view
.
$
(
"li[data-license=creative-commons] button"
))
.
not
.
toHaveClass
(
"is-selected"
);
.
not
.
toHaveClass
(
"is-selected"
);
});
});
it
(
"switches license type on click"
,
function
()
{
it
(
"switches license type on click"
,
function
()
{
var
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
var
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
expect
(
this
.
model
.
get
(
"type"
)).
toBeNull
();
expect
(
this
.
model
.
get
(
"type"
)).
toBeNull
();
arrBtn
.
click
();
arrBtn
.
click
();
expect
(
this
.
model
.
get
(
"type"
)).
toEqual
(
"all-rights-reserved"
);
expect
(
this
.
model
.
get
(
"type"
)).
toEqual
(
"all-rights-reserved"
);
// view has re-rendered, so get a new reference to the button
// view has re-rendered, so get a new reference to the button
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
expect
(
arrBtn
).
toHaveClass
(
"is-selected"
);
expect
(
arrBtn
).
toHaveClass
(
"is-selected"
);
// now switch to creative commons
// now switch to creative commons
var
ccBtn
=
this
.
view
.
$
(
"li[data-license=creative-commons] button"
);
var
ccBtn
=
this
.
view
.
$
(
"li[data-license=creative-commons] button"
);
ccBtn
.
click
();
ccBtn
.
click
();
expect
(
this
.
model
.
get
(
"type"
)).
toEqual
(
"creative-commons"
);
expect
(
this
.
model
.
get
(
"type"
)).
toEqual
(
"creative-commons"
);
// update references again
// update references again
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
ccBtn
=
this
.
view
.
$
(
"li[data-license=creative-commons] button"
);
ccBtn
=
this
.
view
.
$
(
"li[data-license=creative-commons] button"
);
expect
(
arrBtn
).
not
.
toHaveClass
(
"is-selected"
);
expect
(
arrBtn
).
not
.
toHaveClass
(
"is-selected"
);
expect
(
ccBtn
).
toHaveClass
(
"is-selected"
);
expect
(
ccBtn
).
toHaveClass
(
"is-selected"
);
});
});
it
(
"sets default license options when switching license types"
,
function
()
{
it
(
"sets default license options when switching license types"
,
function
()
{
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
({});
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
({});
var
ccBtn
=
this
.
view
.
$
(
"li[data-license=creative-commons] button"
);
var
ccBtn
=
this
.
view
.
$
(
"li[data-license=creative-commons] button"
);
ccBtn
.
click
()
ccBtn
.
click
()
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
);
);
var
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
var
arrBtn
=
this
.
view
.
$
(
"li[data-license=all-rights-reserved] button"
);
arrBtn
.
click
()
arrBtn
.
click
()
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
({});
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
({});
});
});
it
(
"renders license options"
,
function
()
{
it
(
"renders license options"
,
function
()
{
this
.
model
.
set
({
"type"
:
"creative-commons"
})
this
.
model
.
set
({
"type"
:
"creative-commons"
})
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=BY]"
))
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=BY]"
))
.
toContainText
(
"Attribution"
);
.
toContainText
(
"Attribution"
);
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=NC]"
))
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=NC]"
))
.
toContainText
(
"Noncommercial"
);
.
toContainText
(
"Noncommercial"
);
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=ND]"
))
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=ND]"
))
.
toContainText
(
"No Derivatives"
);
.
toContainText
(
"No Derivatives"
);
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=SA]"
))
expect
(
this
.
view
.
$
(
"ul.license-options li[data-option=SA]"
))
.
toContainText
(
"Share Alike"
);
.
toContainText
(
"Share Alike"
);
expect
(
this
.
view
.
$
(
"ul.license-options li"
).
length
).
toEqual
(
4
);
expect
(
this
.
view
.
$
(
"ul.license-options li"
).
length
).
toEqual
(
4
);
});
});
it
(
"toggles boolean options on click"
,
function
()
{
it
(
"toggles boolean options on click"
,
function
()
{
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
);
);
// toggle NC option
// toggle NC option
this
.
view
.
$
(
"li[data-option=NC]"
).
click
();
this
.
view
.
$
(
"li[data-option=NC]"
).
click
();
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
false
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
false
,
"ND"
:
true
,
"SA"
:
false
}
);
);
});
});
it
(
"doesn't toggle disabled options"
,
function
()
{
it
(
"doesn't toggle disabled options"
,
function
()
{
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
);
);
var
BY
=
this
.
view
.
$
(
"li[data-option=BY]"
);
var
BY
=
this
.
view
.
$
(
"li[data-option=BY]"
);
expect
(
BY
).
toHaveClass
(
"is-disabled"
);
expect
(
BY
).
toHaveClass
(
"is-disabled"
);
// try to toggle BY option
// try to toggle BY option
BY
.
click
()
BY
.
click
()
// no change
// no change
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
);
);
});
});
it
(
"doesn't allow simultaneous conflicting options"
,
function
()
{
it
(
"doesn't allow simultaneous conflicting options"
,
function
()
{
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
);
);
// SA and ND conflict
// SA and ND conflict
var
SA
=
this
.
view
.
$
(
"li[data-option=SA]"
);
var
SA
=
this
.
view
.
$
(
"li[data-option=SA]"
);
expect
(
SA
).
toHaveClass
(
"is-disabled"
);
expect
(
SA
).
toHaveClass
(
"is-disabled"
);
// try to turn on SA option, fail
// try to turn on SA option, fail
SA
.
click
()
SA
.
click
()
// no change
// no change
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
true
,
"SA"
:
false
}
);
);
// turn off ND
// turn off ND
var
ND
=
this
.
view
.
$
(
"li[data-option=ND]"
);
var
ND
=
this
.
view
.
$
(
"li[data-option=ND]"
);
expect
(
ND
).
not
.
toHaveClass
(
"is-disabled"
);
expect
(
ND
).
not
.
toHaveClass
(
"is-disabled"
);
ND
.
click
()
ND
.
click
()
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
false
,
"SA"
:
false
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
false
,
"SA"
:
false
}
);
);
// turn on SA
// turn on SA
SA
=
this
.
view
.
$
(
"li[data-option=SA]"
);
SA
=
this
.
view
.
$
(
"li[data-option=SA]"
);
expect
(
SA
).
not
.
toHaveClass
(
"is-disabled"
);
expect
(
SA
).
not
.
toHaveClass
(
"is-disabled"
);
SA
.
click
()
SA
.
click
()
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
false
,
"SA"
:
true
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
false
,
"SA"
:
true
}
);
);
// try to turn on ND option, fail
// try to turn on ND option, fail
ND
=
this
.
view
.
$
(
"li[data-option=ND]"
);
ND
=
this
.
view
.
$
(
"li[data-option=ND]"
);
expect
(
ND
).
toHaveClass
(
"is-disabled"
);
expect
(
ND
).
toHaveClass
(
"is-disabled"
);
ND
.
click
();
ND
.
click
();
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
expect
(
this
.
model
.
get
(
"options"
)).
toEqual
(
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
false
,
"SA"
:
true
}
{
"ver"
:
"4.0"
,
"BY"
:
true
,
"NC"
:
true
,
"ND"
:
false
,
"SA"
:
true
}
);
);
});
});
it
(
"has no preview by default"
,
function
()
{
it
(
"has no preview by default"
,
function
()
{
this
.
view
.
render
();
this
.
view
.
render
();
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
0
)
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
0
)
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
0
)
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
0
)
});
});
it
(
"displays a preview if showPreview is true"
,
function
()
{
it
(
"displays a preview if showPreview is true"
,
function
()
{
this
.
view
=
new
LicenseView
({
model
:
this
.
model
,
showPreview
:
true
});
this
.
view
=
new
LicenseView
({
model
:
this
.
model
,
showPreview
:
true
});
this
.
view
.
render
()
this
.
view
.
render
()
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
1
)
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
1
)
expect
(
this
.
view
.
$
(
"#license-preview"
)).
toHaveText
(
""
);
expect
(
this
.
view
.
$
(
"#license-preview"
)).
toHaveText
(
""
);
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
this
.
view
.
$
(
"li[data-license=creative-commons] button"
).
click
();
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
1
)
expect
(
this
.
view
.
$
(
"#license-preview"
).
length
).
toEqual
(
1
)
expect
(
this
.
view
.
$
(
"#license-preview"
)).
toContainText
(
"Some Rights Reserved"
);
expect
(
this
.
view
.
$
(
"#license-preview"
)).
toContainText
(
"Some Rights Reserved"
);
});
});
})
})
})
})
cms/static/js/views/license.js
View file @
37ab2fc1
define
([
"js/views/baseview"
,
"underscore"
],
function
(
BaseView
,
_
)
{
define
([
"js/views/baseview"
,
"underscore"
],
function
(
BaseView
,
_
)
{
var
defaultLicenseInfo
=
{
var
defaultLicenseInfo
=
{
"all-rights-reserved"
:
{
"all-rights-reserved"
:
{
"name"
:
gettext
(
"All Rights Reserved"
),
"name"
:
gettext
(
"All Rights Reserved"
),
"tooltip"
:
gettext
(
"You reserve all rights for your work"
)
"tooltip"
:
gettext
(
"You reserve all rights for your work"
)
},
"creative-commons"
:
{
"name"
:
gettext
(
"Creative Commons"
),
"tooltip"
:
gettext
(
"You waive some rights for your work, such that others can use it too"
),
"url"
:
"//creativecommons.org/about"
,
"options"
:
{
"ver"
:
{
"name"
:
gettext
(
"Version"
),
"type"
:
"string"
,
"default"
:
"4.0"
,
},
},
"BY"
:
{
"creative-commons"
:
{
"name"
:
gettext
(
"Attribution"
),
"name"
:
gettext
(
"Creative Commons"
),
"type"
:
"boolean"
,
"tooltip"
:
gettext
(
"You waive some rights for your work, such that others can use it too"
),
"default"
:
true
,
"url"
:
"//creativecommons.org/about"
,
"help"
:
gettext
(
"Allow others to copy, distribute, display and perform "
+
"options"
:
{
"your copyrighted work but only if they give credit the way you request."
),
"ver"
:
{
"disabled"
:
true
,
"name"
:
gettext
(
"Version"
),
},
"type"
:
"string"
,
"NC"
:
{
"default"
:
"4.0"
,
"name"
:
gettext
(
"Noncommercial"
),
},
"type"
:
"boolean"
,
"BY"
:
{
"default"
:
true
,
"name"
:
gettext
(
"Attribution"
),
"help"
:
gettext
(
"Allow others to copy, distribute, display and perform "
+
"type"
:
"boolean"
,
"your work - and derivative works based upon it - but for noncommercial purposes only."
),
"default"
:
true
,
},
"help"
:
gettext
(
"Allow others to copy, distribute, display and perform "
+
"ND"
:
{
"your copyrighted work but only if they give credit the way you request."
),
"name"
:
gettext
(
"No Derivatives"
),
"disabled"
:
true
,
"type"
:
"boolean"
,
},
"default"
:
true
,
"NC"
:
{
"help"
:
gettext
(
"Allow others to copy, distribute, display and perform "
+
"name"
:
gettext
(
"Noncommercial"
),
"only verbatim copies of your work, not derivative works based upon it."
),
"type"
:
"boolean"
,
"conflictsWith"
:
[
"SA"
]
"default"
:
true
,
},
"help"
:
gettext
(
"Allow others to copy, distribute, display and perform "
+
"SA"
:
{
"your work - and derivative works based upon it - but for noncommercial purposes only."
),
"name"
:
gettext
(
"Share Alike"
),
},
"type"
:
"boolean"
,
"ND"
:
{
"default"
:
false
,
"name"
:
gettext
(
"No Derivatives"
),
"help"
:
gettext
(
"Allow others to distribute derivative works only under "
+
"type"
:
"boolean"
,
"a license identical to the license that governs your work."
),
"default"
:
true
,
"conflictsWith"
:
[
"ND"
]
"help"
:
gettext
(
"Allow others to copy, distribute, display and perform "
+
"only verbatim copies of your work, not derivative works based upon it."
),
"conflictsWith"
:
[
"SA"
]
},
"SA"
:
{
"name"
:
gettext
(
"Share Alike"
),
"type"
:
"boolean"
,
"default"
:
false
,
"help"
:
gettext
(
"Allow others to distribute derivative works only under "
+
"a license identical to the license that governs your work."
),
"conflictsWith"
:
[
"ND"
]
}
},
"option_order"
:
[
"BY"
,
"NC"
,
"ND"
,
"SA"
]
}
}
},
"option_order"
:
[
"BY"
,
"NC"
,
"ND"
,
"SA"
]
}
}
}
var
LicenseView
=
BaseView
.
extend
({
var
LicenseView
=
BaseView
.
extend
({
events
:
{
events
:
{
"click ul.license-types li button"
:
"onLicenseClick"
,
"click ul.license-types li button"
:
"onLicenseClick"
,
"click ul.license-options li"
:
"onOptionClick"
"click ul.license-options li"
:
"onOptionClick"
},
},
initialize
:
function
(
options
)
{
initialize
:
function
(
options
)
{
this
.
licenseInfo
=
options
.
licenseInfo
||
defaultLicenseInfo
;
this
.
licenseInfo
=
options
.
licenseInfo
||
defaultLicenseInfo
;
this
.
showPreview
=
!!
options
.
showPreview
;
// coerce to boolean
this
.
showPreview
=
!!
options
.
showPreview
;
// coerce to boolean
this
.
template
=
this
.
loadTemplate
(
"license-selector"
);
this
.
template
=
this
.
loadTemplate
(
"license-selector"
);
// Rerender when the model changes
// Rerender when the model changes
this
.
listenTo
(
this
.
model
,
'change'
,
this
.
render
);
this
.
listenTo
(
this
.
model
,
'change'
,
this
.
render
);
this
.
render
();
this
.
render
();
},
},
getDefaultOptionsForLicenseType
:
function
(
licenseType
)
{
getDefaultOptionsForLicenseType
:
function
(
licenseType
)
{
if
(
!
this
.
licenseInfo
[
licenseType
])
{
if
(
!
this
.
licenseInfo
[
licenseType
])
{
// custom license type, no options
// custom license type, no options
return
{};
return
{};
}
}
if
(
!
this
.
licenseInfo
[
licenseType
].
options
)
{
if
(
!
this
.
licenseInfo
[
licenseType
].
options
)
{
// defined license type without options
// defined license type without options
return
{};
return
{};
}
}
var
defaults
=
{};
var
defaults
=
{};
_
.
each
(
this
.
licenseInfo
[
licenseType
].
options
,
function
(
value
,
key
)
{
_
.
each
(
this
.
licenseInfo
[
licenseType
].
options
,
function
(
value
,
key
)
{
defaults
[
key
]
=
value
.
default
;
defaults
[
key
]
=
value
.
default
;
})
})
return
defaults
;
return
defaults
;
},
},
render
:
function
()
{
render
:
function
()
{
this
.
$el
.
html
(
this
.
template
({
this
.
$el
.
html
(
this
.
template
({
model
:
this
.
model
.
attributes
,
model
:
this
.
model
.
attributes
,
licenseString
:
this
.
model
.
toString
()
||
""
,
licenseString
:
this
.
model
.
toString
()
||
""
,
licenseInfo
:
this
.
licenseInfo
,
licenseInfo
:
this
.
licenseInfo
,
showPreview
:
this
.
showPreview
,
showPreview
:
this
.
showPreview
,
previewButton
:
false
,
previewButton
:
false
,
}));
}));
return
this
;
return
this
;
},
},
onLicenseClick
:
function
(
e
)
{
onLicenseClick
:
function
(
e
)
{
var
$li
=
$
(
e
.
srcElement
||
e
.
target
).
closest
(
'li'
);
var
$li
=
$
(
e
.
srcElement
||
e
.
target
).
closest
(
'li'
);
var
licenseType
=
$li
.
data
(
"license"
);
var
licenseType
=
$li
.
data
(
"license"
);
this
.
model
.
set
({
this
.
model
.
set
({
"type"
:
licenseType
,
"type"
:
licenseType
,
"options"
:
this
.
getDefaultOptionsForLicenseType
(
licenseType
)
"options"
:
this
.
getDefaultOptionsForLicenseType
(
licenseType
)
});
});
},
},
onOptionClick
:
function
(
e
)
{
onOptionClick
:
function
(
e
)
{
var
licenseType
=
this
.
model
.
get
(
"type"
),
var
licenseType
=
this
.
model
.
get
(
"type"
),
licenseOptions
=
$
.
extend
({},
this
.
model
.
get
(
"options"
)),
licenseOptions
=
$
.
extend
({},
this
.
model
.
get
(
"options"
)),
$li
=
$
(
e
.
srcElement
||
e
.
target
).
closest
(
'li'
);
$li
=
$
(
e
.
srcElement
||
e
.
target
).
closest
(
'li'
);
var
optionKey
=
$li
.
data
(
"option"
)
var
optionKey
=
$li
.
data
(
"option"
)
var
licenseInfo
=
this
.
licenseInfo
[
licenseType
];
var
licenseInfo
=
this
.
licenseInfo
[
licenseType
];
var
optionInfo
=
licenseInfo
.
options
[
optionKey
];
var
optionInfo
=
licenseInfo
.
options
[
optionKey
];
if
(
optionInfo
.
disabled
)
{
if
(
optionInfo
.
disabled
)
{
// we're done here
// we're done here
return
;
return
;
}
}
var
currentOptionValue
=
licenseOptions
[
optionKey
];
var
currentOptionValue
=
licenseOptions
[
optionKey
];
if
(
optionInfo
.
type
===
"boolean"
)
{
if
(
optionInfo
.
type
===
"boolean"
)
{
// toggle current value
// toggle current value
currentOptionValue
=
!
currentOptionValue
;
currentOptionValue
=
!
currentOptionValue
;
licenseOptions
[
optionKey
]
=
currentOptionValue
;
licenseOptions
[
optionKey
]
=
currentOptionValue
;
}
}
// check for conflicts
// check for conflicts
if
(
currentOptionValue
&&
optionInfo
.
conflictsWith
&&
if
(
currentOptionValue
&&
optionInfo
.
conflictsWith
&&
_
.
any
(
optionInfo
.
conflictsWith
,
function
(
key
)
{
return
licenseOptions
[
key
];}))
{
_
.
any
(
optionInfo
.
conflictsWith
,
function
(
key
)
{
return
licenseOptions
[
key
];}))
{
// conflict! don't set new options
// conflict! don't set new options
// need some feedback here
// need some feedback here
return
;
return
;
}
else
{
}
else
{
this
.
model
.
set
({
"options"
:
licenseOptions
})
this
.
model
.
set
({
"options"
:
licenseOptions
})
// Backbone has trouble identifying when objects change, so we'll
// Backbone has trouble identifying when objects change, so we'll
// fire the change event manually.
// fire the change event manually.
this
.
model
.
trigger
(
"change change:options"
)
this
.
model
.
trigger
(
"change change:options"
)
}
}
}
}
});
});
return
LicenseView
;
return
LicenseView
;
});
});
cms/static/js/views/metadata.js
View file @
37ab2fc1
...
@@ -6,7 +6,8 @@ define(
...
@@ -6,7 +6,8 @@ define(
"js/views/video/transcripts/metadata_videolist"
,
"js/views/video/transcripts/metadata_videolist"
,
"js/views/video/translations_editor"
"js/views/video/translations_editor"
],
],
function
(
BaseView
,
_
,
MetadataModel
,
AbstractEditor
,
FileUpload
,
UploadDialog
,
LicenseModel
,
LicenseView
,
VideoList
,
VideoTranslations
)
{
function
(
BaseView
,
_
,
MetadataModel
,
AbstractEditor
,
FileUpload
,
UploadDialog
,
LicenseModel
,
LicenseView
,
VideoList
,
VideoTranslations
)
{
var
Metadata
=
{};
var
Metadata
=
{};
Metadata
.
Editor
=
BaseView
.
extend
({
Metadata
.
Editor
=
BaseView
.
extend
({
...
...
cms/templates/js/license-selector.underscore
View file @
37ab2fc1
<div class="license-wrapper">
<div class="license-wrapper">
<label class="label setting-label" for="list-license-types">
<label class="label setting-label" for="list-license-types">
<%= gettext("License Type") %>
<%= gettext("License Type") %>
</label>
</label>
<ul class="license-types" id="list-license-types">
<ul class="license-types" id="list-license-types">
<% var link_start_tpl = '<a href="{url}" target="_blank">'; %>
<% var link_start_tpl = '<a href="{url}" target="_blank">'; %>
<% _.each(licenseInfo, function(license, licenseType) { %>
<% _.each(licenseInfo, function(license, licenseType) { %>
<li data-license="<%- licenseType %>">
<li data-license="<%- licenseType %>">
<button name="license-<%- licenseType %>" class="action license-button
<button name="license-<%- licenseType %>"
<% if(model.type === licenseType) { print("is-selected"); } %>"
class="action license-button <% if(model.type === licenseType) { print("is-selected"); } %>"
name="license-<%- licenseType %>"
<% if (license.tooltip) { %>data-tooltip="<%- license.tooltip %>"<% } %>>
<% if (license.tooltip) { %>data-tooltip="<%- license.tooltip %>"<% } %>>
<%- license.name %>
<%- license.name %>
</button>
</button>
<p class="tip">
<p class="tip">
<% if(license.url) { %>
<% if(license.url) { %>
<a href="<%- license.url %>" target="_blank">
<a href="<%- license.url %>" target="_blank">
<%= gettext("Learn more about {license_name}")
<%= gettext("Learn more about {license_name}")
.replace("{license_name}", license.name)
.replace("{license_name}", license.name)
%>
%>
</a>
</a>
<% } else { %>
<% } else { %>
<% } %>
<% } %>
</p>
</p>
</li>
</li>
<% }) %>
<% }) %>
</ul>
</ul>
<% var license = licenseInfo[model.type]; %>
<% var license = licenseInfo[model.type]; %>
<% if(license && !_.isEmpty(license.options)) { %>
<% if(license && !_.isEmpty(license.options)) { %>
<div class="wrapper-license-options">
<div class="wrapper-license-options">
<label class="label setting-label" for="list-license-options">
<label class="label setting-label" for="list-license-options">
<%- gettext("Options for {license_name}").replace("{license_name}", license.name) %>
<%- gettext("Options for {license_name}").replace("{license_name}", license.name) %>
</label>
</label>
<p class='tip tip-inline'>
<p class='tip tip-inline'>
<%- gettext("The following options are available for the {license_name} license.")
<%- gettext("The following options are available for the {license_name} license.")
.replace("{license_name}", license.name) %>
.replace("{license_name}", license.name) %>
</p>
</p>
<ul class="license-options" id="list-license-options">
<ul class="license-options" id="list-license-options">
<% _.each(license.option_order, function(optionKey) { %>
<% _.each(license.option_order, function(optionKey) { %>
<% var optionInfo = license.options[optionKey]; %>
<% var optionInfo = license.options[optionKey]; %>
<% if (optionInfo.type == "boolean") { %>
<% if (optionInfo.type == "boolean") { %>
<% var optionSelected = model.options[optionKey]; %>
<% var optionSelected = model.options[optionKey]; %>
<% var optionDisabled = optionInfo.disabled ||
<% var optionDisabled = optionInfo.disabled ||
(optionInfo.conflictsWith && _.any(optionInfo.conflictsWith, function(key) {return model.options[key];}));
(optionInfo.conflictsWith && _.any(optionInfo.conflictsWith, function(key) {return model.options[key];}));
%>
%>
<li data-option="<%- optionKey %>"
<li data-option="<%- optionKey %>"
class="action-item license-button
class="action-item license-button
<% if (optionSelected) { print("is-selected"); } %>
<% if (optionSelected) { print("is-selected"); } %>
<% if (optionDisabled) { print("is-disabled"); } else { print("is-clickable"); } %>"
<% if (optionDisabled) { print("is-disabled"); } else { print("is-clickable"); } %>"
>
>
<i class="fa fa-fw
<i class="fa fa-fw
<% if(optionSelected) { print("fa-check-square-o"); } else { print("fa-square-o"); } %>
<% if(optionSelected) { print("fa-check-square-o"); } else { print("fa-square-o"); } %>
<% if(optionDisabled) { print("is-disabled"); } %>
<% if(optionDisabled) { print("is-disabled"); } %>
"></i>
"></i>
<h4 class="option-name"><%- optionInfo.name %></h4>
<h4 class="option-name"><%- optionInfo.name %></h4>
<div class="explanation"><%- optionInfo.help %></div>
<div class="explanation"><%- optionInfo.help %></div>
</li>
</li>
<% } // could implement other types here %>
<% } // could implement other types here %>
<% }) %>
<% }) %>
</ul>
</ul>
</div>
</div>
<% } %>
<% } %>
<% if (showPreview) { %>
<% if (showPreview) { %>
<div class="license-preview-wrapper">
<div class="license-preview-wrapper">
<label class="label setting-label" for="license-preview">
<label class="label setting-label" for="license-preview">
<%= gettext("License Display") %>
<%= gettext("License Display") %>
</label>
</label>
<p class="tip">
<p class="tip">
<%= gettext("The following message will be displayed at the bottom of the courseware pages within your course.") %>
<%= gettext("The following message will be displayed at the bottom of the courseware pages within your course.") %>
</p>
</p>
<div id="license-preview">
<div id="license-preview">
<% // keep this synchronized with the contents of common/templates/license.html %>
<% // keep this synchronized with the contents of common/templates/license.html %>
<% if (model.type === "all-rights-reserved") { %>
<% if (model.type === "all-rights-reserved") { %>
© <span class="license-text"><%= gettext("All Rights Reserved") %></span>
© <span class="license-text"><%= gettext("All Rights Reserved") %></span>
<% } else if (model.type === "creative-commons") {
<% } else if (model.type === "creative-commons") {
var possible = ["by", "nc", "nd", "sa"];
var possible = ["by", "nc", "nd", "sa"];
var enabled = _.filter(possible, function(option) {
var enabled = _.filter(possible, function(option) {
return model.options[option] === true || model.options[option.toUpperCase()] === true;
return model.options[option] === true || model.options[option.toUpperCase()] === true;
});
});
var version = model.options.ver || "4.0";
var version = model.options.ver || "4.0";
if (_.isEmpty(enabled)) {
if (_.isEmpty(enabled)) {
enabled = ["zero"];
enabled = ["zero"];
version = model.options.ver || "1.0";
version = model.options.ver || "1.0";
}
}
%>
%>
<a rel="license" href="//creativecommons.org/licenses/<%- enabled.join("-") %>/<%- version %>/">
<a rel="license" href="//creativecommons.org/licenses/<%- enabled.join("-") %>/<%- version %>/">
<% if (previewButton) { %>
<% if (previewButton) { %>
<img src="https://licensebuttons.net/l/<%- enabled.join("-") %>/<%- version %>/<%- typeof buttonSize == "string" ? buttonSize : "88x31" %>.png"
<img src="https://licensebuttons.net/l/<%- enabled.join("-") %>/<%- version %>/<%- typeof buttonSize == "string" ? buttonSize : "88x31" %>.png"
alt="<%- typeof licenseString == "string" ? licenseString : "" %>"
alt="<%- typeof licenseString == "string" ? licenseString : "" %>"
/>
/>
<% } else { %>
<% } else { %>
<i class="icon-cc"></i>
<i class="icon-cc"></i>
<% _.each(enabled, function(option) { %>
<% _.each(enabled, function(option) { %>
<i class="icon-cc-<%- option %>"></i>
<i class="icon-cc-<%- option %>"></i>
<% }); %>
<% }); %>
<span class="license-text"><%= gettext("Some Rights Reserved") %></span>
<span class="license-text"><%= gettext("Some Rights Reserved") %></span>
<% } %>
<% } %>
<% } else { %>
<% } else { %>
<%= typeof licenseString == "string" ? licenseString : "" %>
<%= typeof licenseString == "string" ? licenseString : "" %>
<% } %>
<% } %>
</a>
</a>
</div>
</div>
<% } %>
<% } %>
</div>
</div>
common/lib/xmodule/xmodule/capa_base.py
View file @
37ab2fc1
...
@@ -200,15 +200,6 @@ class CapaFields(object):
...
@@ -200,15 +200,6 @@ class CapaFields(object):
scope
=
Scope
.
settings
scope
=
Scope
.
settings
)
)
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
CapaFields
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
CapaFields
.
data
)
return
non_editable_fields
class
CapaMixin
(
CapaFields
):
class
CapaMixin
(
CapaFields
):
"""
"""
...
...
common/lib/xmodule/xmodule/discussion_module.py
View file @
37ab2fc1
...
@@ -41,15 +41,6 @@ class DiscussionFields(object):
...
@@ -41,15 +41,6 @@ class DiscussionFields(object):
)
)
sort_key
=
String
(
scope
=
Scope
.
settings
)
sort_key
=
String
(
scope
=
Scope
.
settings
)
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
DiscussionFields
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
DiscussionFields
.
data
)
return
non_editable_fields
class
DiscussionModule
(
DiscussionFields
,
XModule
):
class
DiscussionModule
(
DiscussionFields
,
XModule
):
js
=
{
js
=
{
...
...
common/lib/xmodule/xmodule/editing_module.py
View file @
37ab2fc1
...
@@ -22,6 +22,15 @@ class EditingDescriptor(EditingFields, MakoModuleDescriptor):
...
@@ -22,6 +22,15 @@ class EditingDescriptor(EditingFields, MakoModuleDescriptor):
"""
"""
mako_template
=
"widgets/raw-edit.html"
mako_template
=
"widgets/raw-edit.html"
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
EditingDescriptor
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
self
.
fields
[
'data'
])
return
non_editable_fields
# cdodge: a little refactoring here, since we're basically doing the same thing
# cdodge: a little refactoring here, since we're basically doing the same thing
# here as with our parent class, let's call into it to get the basic fields
# here as with our parent class, let's call into it to get the basic fields
# set and then add our additional fields. Trying to keep it DRY.
# set and then add our additional fields. Trying to keep it DRY.
...
...
common/lib/xmodule/xmodule/html_module.py
View file @
37ab2fc1
...
@@ -55,15 +55,6 @@ class HtmlFields(object):
...
@@ -55,15 +55,6 @@ class HtmlFields(object):
scope
=
Scope
.
settings
scope
=
Scope
.
settings
)
)
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
HtmlFields
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
HtmlFields
.
data
)
return
non_editable_fields
class
HtmlModuleMixin
(
HtmlFields
,
XModule
):
class
HtmlModuleMixin
(
HtmlFields
,
XModule
):
"""
"""
...
@@ -312,15 +303,6 @@ class AboutFields(object):
...
@@ -312,15 +303,6 @@ class AboutFields(object):
scope
=
Scope
.
content
scope
=
Scope
.
content
)
)
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
AboutFields
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
AboutFields
.
data
)
return
non_editable_fields
@XBlock.tag
(
"detached"
)
@XBlock.tag
(
"detached"
)
class
AboutModule
(
AboutFields
,
HtmlModuleMixin
):
class
AboutModule
(
AboutFields
,
HtmlModuleMixin
):
...
@@ -358,15 +340,6 @@ class StaticTabFields(object):
...
@@ -358,15 +340,6 @@ class StaticTabFields(object):
help
=
_
(
"HTML for the additional pages"
)
help
=
_
(
"HTML for the additional pages"
)
)
)
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
StaticTabFields
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
StaticTabFields
.
data
)
return
non_editable_fields
@XBlock.tag
(
"detached"
)
@XBlock.tag
(
"detached"
)
class
StaticTabModule
(
StaticTabFields
,
HtmlModuleMixin
):
class
StaticTabModule
(
StaticTabFields
,
HtmlModuleMixin
):
...
@@ -401,15 +374,6 @@ class CourseInfoFields(object):
...
@@ -401,15 +374,6 @@ class CourseInfoFields(object):
scope
=
Scope
.
content
scope
=
Scope
.
content
)
)
@property
def
non_editable_metadata_fields
(
self
):
"""
`data` should not be editable in the Studio settings editor.
"""
non_editable_fields
=
super
(
CourseInfoFields
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
CourseInfoFields
.
data
)
return
non_editable_fields
@XBlock.tag
(
"detached"
)
@XBlock.tag
(
"detached"
)
class
CourseInfoModule
(
CourseInfoFields
,
HtmlModuleMixin
):
class
CourseInfoModule
(
CourseInfoFields
,
HtmlModuleMixin
):
...
...
common/lib/xmodule/xmodule/mixin.py
View file @
37ab2fc1
...
@@ -51,3 +51,14 @@ class LicenseMixin(XBlockMixin):
...
@@ -51,3 +51,14 @@ class LicenseMixin(XBlockMixin):
"""
"""
if
getattr
(
self
,
"license"
,
None
):
if
getattr
(
self
,
"license"
,
None
):
node
.
set
(
'license'
,
self
.
license
)
node
.
set
(
'license'
,
self
.
license
)
def
wrap_with_license
(
block
,
view
,
frag
,
context
):
# pylint: disable=unused-argument
"""
In the LMS, display the custom license underneath the XBlock.
"""
license
=
getattr
(
block
,
"license"
,
None
)
# pylint: disable=redefined-builtin
if
license
:
context
=
{
"license"
:
license
}
frag
.
content
+=
block
.
runtime
.
render_template
(
'license_wrapper.html'
,
context
)
return
frag
common/lib/xmodule/xmodule/raw_module.py
View file @
37ab2fc1
...
@@ -15,12 +15,6 @@ class RawDescriptor(XmlDescriptor, XMLEditingDescriptor):
...
@@ -15,12 +15,6 @@ class RawDescriptor(XmlDescriptor, XMLEditingDescriptor):
"""
"""
data
=
String
(
help
=
"XML data for the module"
,
default
=
""
,
scope
=
Scope
.
content
)
data
=
String
(
help
=
"XML data for the module"
,
default
=
""
,
scope
=
Scope
.
content
)
@property
def
non_editable_metadata_fields
(
self
):
non_editable_fields
=
super
(
RawDescriptor
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
RawDescriptor
.
data
)
return
non_editable_fields
@classmethod
@classmethod
def
definition_from_xml
(
cls
,
xml_object
,
system
):
def
definition_from_xml
(
cls
,
xml_object
,
system
):
return
{
'data'
:
etree
.
tostring
(
xml_object
,
pretty_print
=
True
,
encoding
=
'unicode'
)},
[]
return
{
'data'
:
etree
.
tostring
(
xml_object
,
pretty_print
=
True
,
encoding
=
'unicode'
)},
[]
...
@@ -50,12 +44,6 @@ class EmptyDataRawDescriptor(XmlDescriptor, XMLEditingDescriptor):
...
@@ -50,12 +44,6 @@ class EmptyDataRawDescriptor(XmlDescriptor, XMLEditingDescriptor):
"""
"""
data
=
String
(
default
=
''
,
scope
=
Scope
.
content
)
data
=
String
(
default
=
''
,
scope
=
Scope
.
content
)
@property
def
non_editable_metadata_fields
(
self
):
non_editable_fields
=
super
(
EmptyDataRawDescriptor
,
self
)
.
non_editable_metadata_fields
non_editable_fields
.
append
(
EmptyDataRawDescriptor
.
data
)
return
non_editable_fields
@classmethod
@classmethod
def
definition_from_xml
(
cls
,
xml_object
,
system
):
def
definition_from_xml
(
cls
,
xml_object
,
system
):
if
len
(
xml_object
)
==
0
and
len
(
xml_object
.
items
())
==
0
:
if
len
(
xml_object
)
==
0
and
len
(
xml_object
.
items
())
==
0
:
...
...
common/templates/license_wrapper.html
0 → 100644
View file @
37ab2fc1
<div
class=
"xblock-license"
>
<
%
include
file=
"license.html"
args=
"license=license"
/>
</div>
common/templates/xblock_wrapper.html
View file @
37ab2fc1
...
@@ -5,9 +5,4 @@
...
@@ -5,9 +5,4 @@
</script>
</script>
% endif
% endif
${content}
${content}
% if license:
<div
class=
"xblock-license"
>
<
%
include
file=
"license.html"
args=
"license=license"
/>
</div>
% endif
</div>
</div>
lms/djangoapps/courseware/module_render.py
View file @
37ab2fc1
...
@@ -67,6 +67,7 @@ from openedx.core.lib.xblock_utils import (
...
@@ -67,6 +67,7 @@ from openedx.core.lib.xblock_utils import (
)
)
from
xmodule.lti_module
import
LTIModule
from
xmodule.lti_module
import
LTIModule
from
xmodule.x_module
import
XModuleDescriptor
from
xmodule.x_module
import
XModuleDescriptor
from
xmodule.mixin
import
wrap_with_license
from
xblock_django.user_service
import
DjangoXBlockUserService
from
xblock_django.user_service
import
DjangoXBlockUserService
from
util.json_request
import
JsonResponse
from
util.json_request
import
JsonResponse
from
util.sandboxing
import
can_execute_unsafe_code
,
get_python_lib_zip
from
util.sandboxing
import
can_execute_unsafe_code
,
get_python_lib_zip
...
@@ -533,6 +534,9 @@ def get_module_system_for_user(user, field_data_cache,
...
@@ -533,6 +534,9 @@ def get_module_system_for_user(user, field_data_cache,
# to the Fragment content coming out of the xblocks that are about to be rendered.
# to the Fragment content coming out of the xblocks that are about to be rendered.
block_wrappers
=
[]
block_wrappers
=
[]
if
settings
.
FEATURES
.
get
(
"LICENSING"
,
False
):
block_wrappers
.
append
(
wrap_with_license
)
# Wrap the output display in a single div to allow for the XModule
# Wrap the output display in a single div to allow for the XModule
# javascript to be bound correctly
# javascript to be bound correctly
if
wrap_xmodule_display
is
True
:
if
wrap_xmodule_display
is
True
:
...
...
openedx/core/lib/xblock_utils.py
View file @
37ab2fc1
...
@@ -122,18 +122,12 @@ def wrap_xblock(
...
@@ -122,18 +122,12 @@ def wrap_xblock(
if
block
.
name
:
if
block
.
name
:
data
[
'name'
]
=
block
.
name
data
[
'name'
]
=
block
.
name
if
settings
.
FEATURES
.
get
(
"LICENSING"
,
False
):
license
=
getattr
(
block
,
"license"
,
None
)
else
:
license
=
None
template_context
=
{
template_context
=
{
'content'
:
block
.
display_name
if
display_name_only
else
frag
.
content
,
'content'
:
block
.
display_name
if
display_name_only
else
frag
.
content
,
'classes'
:
css_classes
,
'classes'
:
css_classes
,
'display_name'
:
block
.
display_name_with_default
,
'display_name'
:
block
.
display_name_with_default
,
'data_attributes'
:
u' '
.
join
(
u'data-{}="{}"'
.
format
(
markupsafe
.
escape
(
key
),
markupsafe
.
escape
(
value
))
'data_attributes'
:
u' '
.
join
(
u'data-{}="{}"'
.
format
(
markupsafe
.
escape
(
key
),
markupsafe
.
escape
(
value
))
for
key
,
value
in
data
.
iteritems
()),
for
key
,
value
in
data
.
iteritems
()),
'license'
:
license
,
}
}
if
hasattr
(
frag
,
'json_init_args'
)
and
frag
.
json_init_args
is
not
None
:
if
hasattr
(
frag
,
'json_init_args'
)
and
frag
.
json_init_args
is
not
None
:
...
...
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