Skip to content

Commit

Permalink
Fix asset manager for multi-image blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Vetter committed Jun 19, 2014
1 parent d22989f commit ace714f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions fancypages/assets/forms/widgets.py
Expand Up @@ -43,6 +43,7 @@ def render(self, name, value, attrs=None):
return tmpl.render(Context({
'rendered_widgets': rendered_widgets,
'asset': self.get_asset(*value),
'input_name': name,
}))

def get_widget_id(self, name, idx):
Expand Down
3 changes: 2 additions & 1 deletion fancypages/static/fancypages/dist/js/dashboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion fancypages/static/fancypages/dist/js/fancypages.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion fancypages/static/fancypages/dist/js/libs.min.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions fancypages/static/fancypages/src/js/views.js
Expand Up @@ -385,13 +385,24 @@ FancypageApp.module('Views', function (Views, FancypageApp, Backbone, Marionette
selectAsset: function () {
var button = $('a', this.$el);
this.$el.addClass('editing');
this.origin = button.data('input-name');

this.trigger('select-image-clicked', button.data('heading'), button.data('iframe-src'));
this.trigger(
'select-image-clicked',
button.data('heading'),
button.data('iframe-src'),
this.origin
);
},
setSelectedAsset: function (type, id, url) {
setSelectedAsset: function (type, id, url, origin) {
this.$el.removeClass('editing');

$("input", this.$el).attr('value', id);
if (origin !== this.origin) {
return false;
}

$("input[name=" + this.origin + "]", this.$el).attr('value', id);
$("input[name=" + this.origin + "_type]", this.$el).attr('value', type);
$("img", this.$el).attr('src', url);
}
});
Expand Down Expand Up @@ -468,15 +479,18 @@ FancypageApp.module('Views', function (Views, FancypageApp, Backbone, Marionette
_.bindAll(this, 'hideModal');
_.bindAll(this, 'triggerAssetUpdatedEvent');

this.origin = null;
this.$iframe = null;
this.template = _.template($('#fullscreen-modal-template').html() || '');
this.iframeTemplate = _.template("<iframe frameborder='0' width='99%' height='360'></iframe>");

this.on("image-asset-updated", this.hideModal);
},
showModal: function (heading, url) {
showModal: function (heading, url, inputId) {
var self = this;

this.origin = inputId;

this.$el.html(this.template({
heading: heading,
bodyHtml: this.iframeTemplate()
Expand Down Expand Up @@ -509,7 +523,8 @@ FancypageApp.module('Views', function (Views, FancypageApp, Backbone, Marionette
id = target.data('asset-id'),
url = $('img', target).attr('src');

this.trigger("image-asset-updated", type, id, url);
this.trigger("image-asset-updated", type, id, url, this.origin);
this.origin = null;
}
});

Expand Down
Expand Up @@ -15,7 +15,7 @@
<a data-behaviours="load-asset-modal"
data-target="#fullscreen-modal"
data-heading="Select or upload an image"
data-iframe-id="asset-manager"
data-input-name="{{ input_name }}"
data-iframe-src="{% url "fp-dashboard:image-list" %}"
class="fp-btn-danger fp-btn fp-btn-block">
{% trans "Library" %}
Expand Down

0 comments on commit ace714f

Please sign in to comment.