|
@@ -1,3 +1,5 @@
|
|
1
|
+/*global jQuery */
|
|
2
|
+
|
1
|
3
|
var oscar = (function(o, $) {
|
2
|
4
|
|
3
|
5
|
o.getCsrfToken = function() {
|
|
@@ -5,7 +7,7 @@ var oscar = (function(o, $) {
|
5
|
7
|
var cookies = document.cookie.split(';');
|
6
|
8
|
var csrf_token = null;
|
7
|
9
|
$.each(cookies, function(index, cookie) {
|
8
|
|
- cookieParts = $.trim(cookie).split('=');
|
|
10
|
+ var cookieParts = $.trim(cookie).split('=');
|
9
|
11
|
if (cookieParts[0] == 'csrftoken') {
|
10
|
12
|
csrf_token = cookieParts[1];
|
11
|
13
|
}
|
|
@@ -47,7 +49,7 @@ var oscar = (function(o, $) {
|
47
|
49
|
|
48
|
50
|
$(".category-select ul").prev('a').on('click', function(){
|
49
|
51
|
var $this = $(this),
|
50
|
|
- plus = $this.hasClass('ico_expand');
|
|
52
|
+ plus = $this.hasClass('ico_expand');
|
51
|
53
|
if (plus) {
|
52
|
54
|
$this.removeClass('ico_expand').addClass('ico_contract');
|
53
|
55
|
} else {
|
|
@@ -58,8 +60,8 @@ var oscar = (function(o, $) {
|
58
|
60
|
|
59
|
61
|
// Adds error icon if there are errors in the product update form
|
60
|
62
|
$('[data-behaviour="affix-nav-errors"] .tab-pane').each(function(){
|
61
|
|
- var productErrorListener = $(this).find('[class*="error"]:not(:empty)').closest('.tab-pane').attr('id');
|
62
|
|
- $('[data-spy="affix"] a[href="#' + productErrorListener + '"]').append('<i class="icon-info-sign pull-right"></i>');
|
|
63
|
+ var productErrorListener = $(this).find('[class*="error"]:not(:empty)').closest('.tab-pane').attr('id');
|
|
64
|
+ $('[data-spy="affix"] a[href="#' + productErrorListener + '"]').append('<i class="icon-info-sign pull-right"></i>');
|
63
|
65
|
});
|
64
|
66
|
|
65
|
67
|
o.dashboard.filereader.init();
|
|
@@ -82,7 +84,7 @@ var oscar = (function(o, $) {
|
82
|
84
|
o.dashboard.initSelects(el);
|
83
|
85
|
},
|
84
|
86
|
initMasks: function(el) {
|
85
|
|
- $(el).find(':input').inputmask()
|
|
87
|
+ $(el).find(':input').inputmask();
|
86
|
88
|
},
|
87
|
89
|
initSelects: function(el) {
|
88
|
90
|
// Adds type/search for select fields
|
|
@@ -118,7 +120,7 @@ var oscar = (function(o, $) {
|
118
|
120
|
'language': o.dashboard.options.languageCode,
|
119
|
121
|
'minView': 2
|
120
|
122
|
};
|
121
|
|
- $dates = $(el).find('[data-oscarWidget="date"]').not('.no-widget-init').not('.no-widget-init *')
|
|
123
|
+ var $dates = $(el).find('[data-oscarWidget="date"]').not('.no-widget-init').not('.no-widget-init *');
|
122
|
124
|
$dates.each(function(ind, ele) {
|
123
|
125
|
var $ele = $(ele),
|
124
|
126
|
config = $.extend({}, defaultDatepickerConfig, {
|
|
@@ -134,12 +136,12 @@ var oscar = (function(o, $) {
|
134
|
136
|
'language': o.dashboard.options.languageCode,
|
135
|
137
|
'initialDate': o.dashboard.options.initialDate
|
136
|
138
|
};
|
137
|
|
- $datetimes = $(el).find('[data-oscarWidget="datetime"]').not('.no-widget-init').not('.no-widget-init *')
|
|
139
|
+ var $datetimes = $(el).find('[data-oscarWidget="datetime"]').not('.no-widget-init').not('.no-widget-init *');
|
138
|
140
|
$datetimes.each(function(ind, ele) {
|
139
|
141
|
var $ele = $(ele),
|
140
|
142
|
config = $.extend({}, defaultDatetimepickerConfig, {
|
141
|
|
- 'format': $ele.data('datetimeformat'),
|
142
|
|
- 'minuteStep': $ele.data('stepminute')
|
|
143
|
+ 'format': $ele.data('datetimeformat'),
|
|
144
|
+ 'minuteStep': $ele.data('stepminute')
|
143
|
145
|
});
|
144
|
146
|
$ele.datetimepicker(config);
|
145
|
147
|
});
|
|
@@ -151,15 +153,15 @@ var oscar = (function(o, $) {
|
151
|
153
|
'language': o.dashboard.options.languageCode,
|
152
|
154
|
'initialDate': o.dashboard.options.initialDate
|
153
|
155
|
};
|
154
|
|
- $times = $(el).find('[data-oscarWidget="time"]').not('.no-widget-init').not('.no-widget-init *')
|
|
156
|
+ var $times = $(el).find('[data-oscarWidget="time"]').not('.no-widget-init').not('.no-widget-init *');
|
155
|
157
|
$times.each(function(ind, ele) {
|
156
|
158
|
var $ele = $(ele),
|
157
|
159
|
config = $.extend({}, defaultTimepickerConfig, {
|
158
|
|
- 'format': $ele.data('timeformat'),
|
159
|
|
- 'minuteStep': $ele.data('stepminute'),
|
160
|
|
- 'startView': 1,
|
161
|
|
- 'maxView': 1,
|
162
|
|
- 'formatViewType': 'time'
|
|
160
|
+ 'format': $ele.data('timeformat'),
|
|
161
|
+ 'minuteStep': $ele.data('stepminute'),
|
|
162
|
+ 'startView': 1,
|
|
163
|
+ 'maxView': 1,
|
|
164
|
+ 'formatViewType': 'time'
|
163
|
165
|
});
|
164
|
166
|
$ele.datetimepicker(config);
|
165
|
167
|
});
|
|
@@ -167,7 +169,7 @@ var oscar = (function(o, $) {
|
167
|
169
|
},
|
168
|
170
|
initWYSIWYG: function(el) {
|
169
|
171
|
// Use TinyMCE by default
|
170
|
|
- $textareas = $(el).find('textarea').not('.no-widget-init textarea').not('.no-widget-init');
|
|
172
|
+ var $textareas = $(el).find('textarea').not('.no-widget-init textarea').not('.no-widget-init');
|
171
|
173
|
$textareas.filter('form.wysiwyg textarea').tinymce(o.dashboard.options.tinyConfig);
|
172
|
174
|
$textareas.filter('.wysiwyg').tinymce(o.dashboard.options.tinyConfig);
|
173
|
175
|
},
|
|
@@ -205,11 +207,11 @@ var oscar = (function(o, $) {
|
205
|
207
|
init: function(){
|
206
|
208
|
var type_selects = $("select[name$=type]");
|
207
|
209
|
|
208
|
|
- type_selects.each(function(index){
|
|
210
|
+ type_selects.each(function(){
|
209
|
211
|
o.dashboard.product_attributes.toggleOptionGroup($(this));
|
210
|
212
|
});
|
211
|
213
|
|
212
|
|
- type_selects.change(function(e){
|
|
214
|
+ type_selects.change(function(){
|
213
|
215
|
o.dashboard.product_attributes.toggleOptionGroup($(this));
|
214
|
216
|
});
|
215
|
217
|
},
|
|
@@ -223,7 +225,7 @@ var oscar = (function(o, $) {
|
223
|
225
|
ranges: {
|
224
|
226
|
init: function() {
|
225
|
227
|
$('[data-behaviours~="remove"]').click(function() {
|
226
|
|
- $this = $(this);
|
|
228
|
+ var $this = $(this);
|
227
|
229
|
$this.parents('table').find('input').prop('checked', false);
|
228
|
230
|
$this.parents('tr').find('input').prop('checked', true);
|
229
|
231
|
$this.parents('form').submit();
|
|
@@ -252,48 +254,48 @@ var oscar = (function(o, $) {
|
252
|
254
|
},
|
253
|
255
|
reordering: (function() {
|
254
|
256
|
var options = {
|
255
|
|
- handle: '.btn-handle',
|
256
|
|
- submit_url: '#'
|
257
|
|
- },
|
258
|
|
- saveOrder = function(data) {
|
|
257
|
+ handle: '.btn-handle',
|
|
258
|
+ submit_url: '#'
|
|
259
|
+ },
|
|
260
|
+ saveOrder = function(data) {
|
259
|
261
|
// Get the csrf token, otherwise django will not accept the
|
260
|
262
|
// POST request.
|
261
|
|
- var csrf = o.getCsrfToken();
|
262
|
|
- $.ajax({
|
263
|
|
- type: 'POST',
|
264
|
|
- data: $.param(data),
|
265
|
|
- dataType: "json",
|
266
|
|
- url: options.submit_url,
|
267
|
|
- beforeSend: function(xhr, settings) {
|
268
|
|
- xhr.setRequestHeader("X-CSRFToken", csrf);
|
269
|
|
- }
|
270
|
|
- });
|
271
|
|
- },
|
272
|
|
- init = function(user_options) {
|
273
|
|
- options = $.extend(options, user_options);
|
274
|
|
- var group = $(options.wrapper).sortable({
|
275
|
|
- group: 'serialization',
|
276
|
|
- containerSelector: 'tbody',
|
277
|
|
- itemSelector: 'tr',
|
278
|
|
- handle: options.handle,
|
279
|
|
- vertical: true,
|
280
|
|
- onDrop: function ($item, container, _super) {
|
281
|
|
- var data = group.sortable("serialize");
|
282
|
|
- saveOrder(data);
|
283
|
|
- _super($item, container);
|
284
|
|
- },
|
285
|
|
- placeholder: '<tr class="placeholder"/>',
|
286
|
|
- serialize: function (parent, children, isContainer) {
|
287
|
|
- if (isContainer) {
|
288
|
|
- return children;
|
|
263
|
+ var csrf = o.getCsrfToken();
|
|
264
|
+ $.ajax({
|
|
265
|
+ type: 'POST',
|
|
266
|
+ data: $.param(data),
|
|
267
|
+ dataType: "json",
|
|
268
|
+ url: options.submit_url,
|
|
269
|
+ beforeSend: function(xhr) {
|
|
270
|
+ xhr.setRequestHeader("X-CSRFToken", csrf);
|
289
|
271
|
}
|
290
|
|
- else {
|
291
|
|
- var parts = parent.attr('id').split('_');
|
292
|
|
- return {'name': parts[0], 'value': parts[1]};
|
|
272
|
+ });
|
|
273
|
+ },
|
|
274
|
+ init = function(user_options) {
|
|
275
|
+ options = $.extend(options, user_options);
|
|
276
|
+ var group = $(options.wrapper).sortable({
|
|
277
|
+ group: 'serialization',
|
|
278
|
+ containerSelector: 'tbody',
|
|
279
|
+ itemSelector: 'tr',
|
|
280
|
+ handle: options.handle,
|
|
281
|
+ vertical: true,
|
|
282
|
+ onDrop: function ($item, container, _super) {
|
|
283
|
+ var data = group.sortable("serialize");
|
|
284
|
+ saveOrder(data);
|
|
285
|
+ _super($item, container);
|
|
286
|
+ },
|
|
287
|
+ placeholder: '<tr class="placeholder"/>',
|
|
288
|
+ serialize: function (parent, children, isContainer) {
|
|
289
|
+ if (isContainer) {
|
|
290
|
+ return children;
|
|
291
|
+ }
|
|
292
|
+ else {
|
|
293
|
+ var parts = parent.attr('id').split('_');
|
|
294
|
+ return {'name': parts[0], 'value': parts[1]};
|
|
295
|
+ }
|
293
|
296
|
}
|
294
|
|
- }
|
295
|
|
- });
|
296
|
|
- };
|
|
297
|
+ });
|
|
298
|
+ };
|
297
|
299
|
|
298
|
300
|
return {
|
299
|
301
|
init: init,
|
|
@@ -305,7 +307,7 @@ var oscar = (function(o, $) {
|
305
|
307
|
var searchForm = $(".orders_search"),
|
306
|
308
|
searchLink = $('.pull_out'),
|
307
|
309
|
doc = $('document');
|
308
|
|
- searchForm.each(function(index) {
|
|
310
|
+ searchForm.each(function() {
|
309
|
311
|
doc.css('height', doc.height());
|
310
|
312
|
});
|
311
|
313
|
searchLink.on('click', function() {
|
|
@@ -314,7 +316,7 @@ var oscar = (function(o, $) {
|
314
|
316
|
.toggleClass('no-float')
|
315
|
317
|
.end().end()
|
316
|
318
|
.slideToggle("fast");
|
317
|
|
- }
|
|
319
|
+ }
|
318
|
320
|
);
|
319
|
321
|
}
|
320
|
322
|
},
|