Commit 2cbdaaee by cahrens

Updates based on switching to checkbox for locking.

parent 79c2cdc7
...@@ -125,20 +125,17 @@ def modify_upload(_step, file_name): ...@@ -125,20 +125,17 @@ def modify_upload(_step, file_name):
def lock_unlock_file(_step, _lock_state, file_name): def lock_unlock_file(_step, _lock_state, file_name):
index = get_index(file_name) index = get_index(file_name)
assert index != -1 assert index != -1
lock_css = "a.lock-asset-button" lock_css = "input.lock-checkbox"
world.css_click(lock_css, index=index) world.css_find(lock_css)[index].click()
@step(u'Then "([^"]*)" is (locked|unlocked)$') @step(u'Then "([^"]*)" is (locked|unlocked)$')
def verify_lock_unlock_file(_step, file_name, lock_state): def verify_lock_unlock_file(_step, file_name, lock_state):
index = get_index(file_name) index = get_index(file_name)
assert index != -1 assert index != -1
lock_css = "a.lock-asset-button" lock_css = "input.lock-checkbox"
text = world.css_text(lock_css, index=index) checked = world.css_find(lock_css)[index]._element.get_attribute('checked')
if lock_state == "locked": assert_equal(lock_state == "locked", bool(checked))
assert_equal("Unlock this asset", text)
else:
assert_equal("Lock this asset", text)
@step(u'I have opened a course with a (locked|unlocked) asset "([^"]*)"$') @step(u'I have opened a course with a (locked|unlocked) asset "([^"]*)"$')
......
...@@ -77,7 +77,7 @@ describe "CMS.Views.Asset", -> ...@@ -77,7 +77,7 @@ describe "CMS.Views.Asset", ->
expect(@collection.contains(@model)).toBeTruthy() expect(@collection.contains(@model)).toBeTruthy()
it "should lock the asset on confirmation", -> it "should lock the asset on confirmation", ->
@view.render().$(".lock-asset-button").click() @view.render().$(".lock-checkbox").click()
# AJAX request has been sent, but not yet returned # AJAX request has been sent, but not yet returned
expect(@model.save).toHaveBeenCalled() expect(@model.save).toHaveBeenCalled()
expect(@requests.length).toEqual(1) expect(@requests.length).toEqual(1)
...@@ -92,7 +92,7 @@ describe "CMS.Views.Asset", -> ...@@ -92,7 +92,7 @@ describe "CMS.Views.Asset", ->
expect(@model.get("locked")).toBeTruthy() expect(@model.get("locked")).toBeTruthy()
it "should not lock the asset if server errors", -> it "should not lock the asset if server errors", ->
@view.render().$(".lock-asset-button").click() @view.render().$(".lock-checkbox").click()
# return an error response # return an error response
@requests[0].respond(404) @requests[0].respond(404)
# Don't call hide because that closes the notification showing the server error. # Don't call hide because that closes the notification showing the server error.
......
CMS.Views.Asset = Backbone.View.extend({ CMS.Views.Asset = Backbone.View.extend({
initialize: function() { initialize: function() {
this.template = _.template($("#asset-tpl").text()); this.template = _.template($("#asset-tpl").text());
this.listenTo(this.model, "change", this.render); this.listenTo(this.model, "change:locked", this.updateLockState);
}, },
tagName: "tr", tagName: "tr",
events: { events: {
"click .remove-asset-button": "confirmDelete", "click .remove-asset-button": "confirmDelete",
"click .lock-asset-button": "lockAsset" "click .lock-checkbox": "lockAsset"
}, },
render: function() { render: function() {
this.$el.removeClass(); var uniqueId = _.uniqueId('lock_asset_');
this.$el.html(this.template({ this.$el.html(this.template({
display_name: this.model.get('display_name'), display_name: this.model.get('display_name'),
...@@ -20,16 +20,28 @@ CMS.Views.Asset = Backbone.View.extend({ ...@@ -20,16 +20,28 @@ CMS.Views.Asset = Backbone.View.extend({
date_added: this.model.get('date_added'), date_added: this.model.get('date_added'),
url: this.model.get('url'), url: this.model.get('url'),
portable_url: this.model.get('portable_url'), portable_url: this.model.get('portable_url'),
locked: this.model.get('locked')})); uniqueId: uniqueId}));
// Add a class of "locked" to the tr element if appropriate. this.updateLockState();
if (this.model.get('locked')) {
this.$el.addClass('is-locked');
}
return this; return this;
}, },
updateLockState: function () {
var locked_class = "is-locked";
// Add a class of "locked" to the tr element if appropriate,
// and toggle locked state of hidden checkbox.
if (this.model.get('locked')) {
this.$el.addClass(locked_class);
this.$el.find('.lock-checkbox').attr('checked','checked');
}
else {
this.$el.removeClass(locked_class);
this.$el.find('.lock-checkbox').removeAttr('checked');
}
},
confirmDelete: function(e) { confirmDelete: function(e) {
if(e && e.preventDefault) { e.preventDefault(); } if(e && e.preventDefault) { e.preventDefault(); }
var asset = this.model; var asset = this.model;
...@@ -67,7 +79,6 @@ CMS.Views.Asset = Backbone.View.extend({ ...@@ -67,7 +79,6 @@ CMS.Views.Asset = Backbone.View.extend({
}, },
lockAsset: function(e) { lockAsset: function(e) {
if(e && e.preventDefault) { e.preventDefault(); }
var asset = this.model; var asset = this.model;
var saving = new CMS.Views.Notification.Mini({ var saving = new CMS.Views.Notification.Mini({
title: gettext("Saving…") title: gettext("Saving…")
......
...@@ -94,6 +94,10 @@ body.course.uploads { ...@@ -94,6 +94,10 @@ body.course.uploads {
.thumb-col { .thumb-col {
padding: ($baseline/2) $baseline; padding: ($baseline/2) $baseline;
.thumb {
width: 100px;
}
img { img {
width: 100%; width: 100%;
} }
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
<a href="#" data-tooltip="<%= gettext('Delete this asset') %>" class="remove-asset-button action-button"><i class="icon-remove-sign"></i> <span class="sr"><%= gettext('Delete this asset') %></span></a> <a href="#" data-tooltip="<%= gettext('Delete this asset') %>" class="remove-asset-button action-button"><i class="icon-remove-sign"></i> <span class="sr"><%= gettext('Delete this asset') %></span></a>
</li> </li>
<li class="action-item action-lock"> <li class="action-item action-lock">
<label for="lock-asset"><span class="sr"><%= gettext('Lock this asset') %></span></label> <label for="<%= uniqueId %>"><span class="sr"><%= gettext('Lock this asset') %></span></label>
<input type="checkbox" name="lock-asset" class="lock-checkbox" data-tooltip="<%= gettext('Lock/unlock file') %>" /> <input type="checkbox" id="<%= uniqueId %>" class="lock-checkbox" data-tooltip="<%= gettext('Lock/unlock file') %>" />
<div class="action-button"><i class="icon-lock"></i><i class="icon-unlock-alt"></i></div> <div class="action-button"><i class="icon-lock"></i><i class="icon-unlock-alt"></i></div>
</li> </li>
</ul> </ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment