Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert trivial coffee to plain JS #2546

Merged
merged 13 commits into from
Feb 5, 2018
Merged
26 changes: 26 additions & 0 deletions backend/app/assets/javascripts/spree/backend/adjustments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Spree.ready(function() {
$('[data-hook=adjustments_new_coupon_code] #add_coupon_code').click(function() {
if ($("#coupon_code").val().length === 0) {
return;
}

Spree.ajax({
type: 'PUT',
url: Spree.routes.apply_coupon_code(window.order_number),
data: {
coupon_code: $("#coupon_code").val(),
token: Spree.api_key
},
success: function() {
window.location.reload();
},
error: function(msg) {
if (msg.responseJSON["error"]) {
show_flash('error', msg.responseJSON["error"]);
} else {
show_flash('error', "There was a problem adding this coupon code.");
}
}
});
});
});
17 changes: 0 additions & 17 deletions backend/app/assets/javascripts/spree/backend/adjustments.js.coffee

This file was deleted.

25 changes: 25 additions & 0 deletions backend/app/assets/javascripts/spree/backend/backbone-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Backbone.ajax = Spree.ajax;

Backbone._sync = Backbone.sync;

Backbone.sync = function(method, model, options) {
var beforeSend = options.beforeSend;
options.beforeSend = function(xhr) {
var token = $('meta[name="csrf-token"]').attr('content');
if (token) {
xhr.setRequestHeader('X-CSRF-Token', token);
}
if (beforeSend) {
return beforeSend.apply(this, arguments);
}
};

if (options.data == null && model && model.paramRoot && (method === 'create' || method === 'update' || method === 'patch')) {
options.contentType = "application/json";
var data = {};
data[model.paramRoot] = model.toJSON(options);
options.data = JSON.stringify(data);
}

return Backbone._sync(method, model, options);
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Spree.ready(function() {
$('.inline-editable-table tr').each(function() {
Spree.Views.Tables.EditableTable.add($(this));
});
});

This file was deleted.

17 changes: 0 additions & 17 deletions backend/app/assets/javascripts/spree/backend/flash.coffee

This file was deleted.

20 changes: 20 additions & 0 deletions backend/app/assets/javascripts/spree/backend/flash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
var showTime = 5000;

var fadeOutTime = 500;

Spree.ready(function() {
var $initialFlash;
$initialFlash = $(".flash");
setTimeout((function() {
$initialFlash.fadeOut(fadeOutTime);
}), showTime);
});

window.show_flash = function(type, message) {
var $flashWrapper = $(".js-flash-wrapper");
var flash_div = $("<div class=\"flash " + type + "\" />");
$flashWrapper.prepend(flash_div);
flash_div.html(message).show().delay(showTime).fadeOut(fadeOutTime);
};
})();
22 changes: 22 additions & 0 deletions backend/app/assets/javascripts/spree/backend/gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Spree.ready(function() {
var $gateway_type = $('select.js-gateway-type');
var $preference_source = $('select.js-preference-source');
var original_gateway_type = $gateway_type.val();
var original_preference_source = $preference_source.val();

var render = function() {
var gateway_type = $gateway_type.val();
var preference_source = $preference_source.val();
$('.js-preference-source-wrapper').toggle(gateway_type === original_gateway_type);
if (gateway_type === original_gateway_type && preference_source === original_preference_source) {
$('.js-gateway-settings').show();
$('.js-gateway-settings-warning').hide();
} else {
$('.js-gateway-settings').hide();
$('.js-gateway-settings-warning').show();
}
};
$gateway_type.change(render);
$preference_source.change(render);
render();
});
21 changes: 0 additions & 21 deletions backend/app/assets/javascripts/spree/backend/gateway.js.coffee

This file was deleted.

3 changes: 2 additions & 1 deletion backend/app/assets/javascripts/spree/backend/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _.extend(window.Spree, {
Order: {},
Cart: {},
Zones: {},
Payment: {}
Payment: {},
Tables: {}
}
})
10 changes: 0 additions & 10 deletions backend/app/assets/javascripts/spree/backend/navigation.coffee

This file was deleted.

14 changes: 14 additions & 0 deletions backend/app/assets/javascripts/spree/backend/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Spree.ready(function() {
var navHeight = function() {
return $('.admin-nav-header').outerHeight() + $('.admin-nav-menu').outerHeight() + $('.admin-nav-footer').outerHeight();
};

var checkSideBarFit = function() {
$('.admin-nav').toggleClass('fits', navHeight() < $(window).height());
};

$(".admin-nav-sticky, .admin-nav").stick_in_parent();

checkSideBarFit();
$(window).on('resize', checkSideBarFit);
});
16 changes: 16 additions & 0 deletions backend/app/assets/javascripts/spree/backend/payments/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Spree.ready(function() {
var order_id = $('#payments').data('order-id');

$('tr.payment').each(function() {
var payment_id = $(this).data('payment-id');
var model = new Spree.Models.Payment({
id: payment_id,
order_id: order_id
});

new Spree.Views.Payment.PaymentRow({
el: this,
model: model
});
});
});

This file was deleted.

7 changes: 0 additions & 7 deletions backend/app/assets/javascripts/spree/backend/progress.coffee

This file was deleted.

9 changes: 9 additions & 0 deletions backend/app/assets/javascripts/spree/backend/progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Spree.ready(function() {
$(document).ajaxStart(function() {
$("#progress").show();
});

$(document).ajaxStop(function() {
$("#progress").hide();
});
});

This file was deleted.

3 changes: 3 additions & 0 deletions backend/app/assets/javascripts/spree/backend/style_guide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Spree.ready(function() {
$(".style-guide-nav, .style-guide-sidebar").stick_in_parent();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(function() {
var variantTemplate = HandlebarsTemplates["variants/autocomplete"];

var formatVariantResult = function(variant) {
return variantTemplate({
variant: variant
});
};

$.fn.variantAutocomplete = function(searchOptions) {
if (searchOptions == null) {
searchOptions = {};
}
this.select2({
placeholder: Spree.translations.variant_placeholder,
minimumInputLength: 3,
initSelection: function(element, callback) {
Spree.ajax({
url: Spree.routes.variants_api + "/" + element.val(),
success: callback
});
},
ajax: {
url: Spree.routes.variants_api,
datatype: "json",
quietMillis: 500,
params: {
"headers": {
"X-Spree-Token": Spree.api_key
}
},
data: function(term, page) {
var searchData = {
q: {
product_name_or_sku_cont: term
},
token: Spree.api_key
};
return _.extend(searchData, searchOptions);
},

results: function(data, page) {
window.variants = data["variants"];
return {
results: data["variants"]
};
}
},

formatResult: formatVariantResult,
formatSelection: function(variant, container, escapeMarkup) {
if (variant.options_text) {
return Select2.util.escapeMarkup(variant.name + " (" + variant.options_text + ")");
} else {
return Select2.util.escapeMarkup(variant.name);
}
}
});
};
})();

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Spree.Views.Tables.EditableTable = {
add: function($el) {
return new Spree.Views.Tables.EditableTableRow({
el: $el
});
},

append: function(html) {
var $row = $(html);
$('#images-table').removeClass('hidden').find('tbody').append($row);
$row.find('.select2').select2();
$('.no-objects-found').hide();
return this.add($row);
}
};
Loading