-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1580 from mtomov/ajax-update-image-variant
Allow users to inline update the variant of an image in admin
- Loading branch information
Showing
19 changed files
with
203 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
backend/app/assets/javascripts/spree/backend/components/editable_table.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Spree.ready -> | ||
$('.inline-editable-table tr').each -> | ||
Spree.Views.Tables.EditableTable.add $(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
backend/app/assets/javascripts/spree/backend/views/tables/editable_table.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Spree.Views.Tables ||= {} | ||
|
||
class Spree.Views.Tables.EditableTable | ||
@add: ($el) -> | ||
new Spree.Views.Tables.EditableTableRow el: $el | ||
|
||
@append: (html) -> | ||
$row = $(html) | ||
|
||
$('#images-table').removeClass('hidden').find('tbody').append($row) | ||
$row.find('.select2').select2() | ||
$('.no-objects-found').hide() | ||
|
||
@add($row) |
45 changes: 45 additions & 0 deletions
45
backend/app/assets/javascripts/spree/backend/views/tables/editable_table_row.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Spree.Views.Tables.EditableTableRow = Backbone.View.extend | ||
events: | ||
"select2-open": "onEdit" | ||
"focus input": "onEdit" | ||
"click [data-action=save]": "onSave" | ||
"click [data-action=cancel]": "onCancel" | ||
'keyup input': 'onKeypress' | ||
|
||
onEdit: (e) -> | ||
return if @$el.hasClass('editing') | ||
@$el.addClass('editing') | ||
|
||
@$el.find('input, select').each -> | ||
$input = $(this) | ||
$input.data 'original-value', $input.val() | ||
|
||
onCancel: (e) -> | ||
e.preventDefault() | ||
@$el.removeClass("editing") | ||
|
||
@$el.find('input, select').each -> | ||
$input = $(this) | ||
originalValue = $input.data('original-value') | ||
$input.val(originalValue).change() | ||
|
||
onSave: (e) -> | ||
e.preventDefault() | ||
|
||
Spree.ajax @$el.find('.actions [data-action=save]').attr('href'), | ||
data: @$el.find('select, input').serialize() | ||
dataType: 'json' | ||
method: 'put' | ||
success: (response) => | ||
@$el.removeClass("editing") | ||
error: (response) => | ||
show_flash 'error', response.responseJSON.error | ||
|
||
ENTER_KEY: 13 | ||
ESC_KEY: 27 | ||
|
||
onKeypress: (e) -> | ||
key = e.keyCode || e.which | ||
switch key | ||
when @ENTER_KEY then @onSave(e) | ||
when @ESC_KEY then @onCancel(e) |
37 changes: 37 additions & 0 deletions
37
backend/app/assets/stylesheets/spree/backend/components/_editable_table.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.inline-editable-table tr:not(:hover):not(.editing) { | ||
input { | ||
border: 1px solid transparent; | ||
color: inherit; | ||
background-color: transparent; | ||
} | ||
|
||
.select2-arrow { | ||
display: none; | ||
} | ||
|
||
.select2-choice { | ||
background-color: transparent; | ||
border-color: transparent; | ||
color: inherit; | ||
} | ||
|
||
.select2-chosen { | ||
color: inherit; | ||
} | ||
} | ||
|
||
.inline-editable-table tr { | ||
.fa-check, .fa-cancel { | ||
display: none !important; | ||
} | ||
|
||
&.editing { | ||
.fa-check, .fa-cancel { | ||
display: inline-block !important; | ||
} | ||
|
||
.fa { | ||
display: none; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
backend/app/assets/stylesheets/spree/backend/sections/_payments.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
var uploadedRow = $('[data-upload-id="<%= params[:upload_id] %>"]'); | ||
var $uploadEl = $('[data-upload-id="<%= params[:upload_id] %>"]'); | ||
|
||
<% if @image.persisted? %> | ||
uploadedRow.trigger('clear'); | ||
$('#images-table').removeClass('hidden').find('tbody').append('<%= j render partial: "image_row", locals: {image: @image } %>'); | ||
$('.no-objects-found').hide(); | ||
|
||
$uploadEl.trigger('clear'); | ||
Spree.Views.Tables.EditableTable.append('<%= j render "image_row", image: @image %>'); | ||
|
||
<% else %> | ||
uploadedRow.find('error').removeClass('hidden').html('<%= j @image.errors.full_messages.join("<br>").html_safe %>'); | ||
|
||
$uploadEl.find('error').removeClass('hidden').html('<%= j @image.errors.full_messages.join("<br>").html_safe %>'); | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.