diff --git a/cms/djangoapps/contentstore/features/upload.py b/cms/djangoapps/contentstore/features/upload.py index 405052b822..b94ccd114a 100644 --- a/cms/djangoapps/contentstore/features/upload.py +++ b/cms/djangoapps/contentstore/features/upload.py @@ -125,20 +125,17 @@ def modify_upload(_step, file_name): def lock_unlock_file(_step, _lock_state, file_name): index = get_index(file_name) assert index != -1 - lock_css = "a.lock-asset-button" - world.css_click(lock_css, index=index) + lock_css = "input.lock-checkbox" + world.css_find(lock_css)[index].click() @step(u'Then "([^"]*)" is (locked|unlocked)$') def verify_lock_unlock_file(_step, file_name, lock_state): index = get_index(file_name) assert index != -1 - lock_css = "a.lock-asset-button" - text = world.css_text(lock_css, index=index) - if lock_state == "locked": - assert_equal("Unlock this asset", text) - else: - assert_equal("Lock this asset", text) + lock_css = "input.lock-checkbox" + checked = world.css_find(lock_css)[index]._element.get_attribute('checked') + assert_equal(lock_state == "locked", bool(checked)) @step(u'I have opened a course with a (locked|unlocked) asset "([^"]*)"$') diff --git a/cms/static/coffee/spec/views/assets_spec.coffee b/cms/static/coffee/spec/views/assets_spec.coffee index dd06491af5..bd8858da42 100644 --- a/cms/static/coffee/spec/views/assets_spec.coffee +++ b/cms/static/coffee/spec/views/assets_spec.coffee @@ -77,7 +77,7 @@ describe "CMS.Views.Asset", -> expect(@collection.contains(@model)).toBeTruthy() 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 expect(@model.save).toHaveBeenCalled() expect(@requests.length).toEqual(1) @@ -92,7 +92,7 @@ describe "CMS.Views.Asset", -> expect(@model.get("locked")).toBeTruthy() it "should not lock the asset if server errors", -> - @view.render().$(".lock-asset-button").click() + @view.render().$(".lock-checkbox").click() # return an error response @requests[0].respond(404) # Don't call hide because that closes the notification showing the server error. diff --git a/cms/static/js/views/asset_view.js b/cms/static/js/views/asset_view.js index 0a2569a669..d158ba58d8 100644 --- a/cms/static/js/views/asset_view.js +++ b/cms/static/js/views/asset_view.js @@ -1,18 +1,18 @@ CMS.Views.Asset = Backbone.View.extend({ initialize: function() { this.template = _.template($("#asset-tpl").text()); - this.listenTo(this.model, "change", this.render); + this.listenTo(this.model, "change:locked", this.updateLockState); }, tagName: "tr", events: { "click .remove-asset-button": "confirmDelete", - "click .lock-asset-button": "lockAsset" + "click .lock-checkbox": "lockAsset" }, render: function() { - this.$el.removeClass(); + var uniqueId = _.uniqueId('lock_asset_'); this.$el.html(this.template({ display_name: this.model.get('display_name'), @@ -20,16 +20,28 @@ CMS.Views.Asset = Backbone.View.extend({ date_added: this.model.get('date_added'), url: this.model.get('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. - if (this.model.get('locked')) { - this.$el.addClass('is-locked'); - } + this.updateLockState(); 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) { if(e && e.preventDefault) { e.preventDefault(); } var asset = this.model; @@ -67,7 +79,6 @@ CMS.Views.Asset = Backbone.View.extend({ }, lockAsset: function(e) { - if(e && e.preventDefault) { e.preventDefault(); } var asset = this.model; var saving = new CMS.Views.Notification.Mini({ title: gettext("Saving…") diff --git a/cms/static/sass/views/_assets.scss b/cms/static/sass/views/_assets.scss index 3647f6ae47..983559d286 100644 --- a/cms/static/sass/views/_assets.scss +++ b/cms/static/sass/views/_assets.scss @@ -94,6 +94,10 @@ body.course.uploads { .thumb-col { padding: ($baseline/2) $baseline; + .thumb { + width: 100px; + } + img { width: 100%; } diff --git a/cms/templates/js/asset.underscore b/cms/templates/js/asset.underscore index 7d83935448..73f815f9e1 100644 --- a/cms/templates/js/asset.underscore +++ b/cms/templates/js/asset.underscore @@ -22,8 +22,8 @@ <%= gettext('Delete this asset') %>
  • - - + +