Skip to content

Commit 5b52664

Browse files
committed
Refactor code for better readability and maintainability in lioniteimages.js
1 parent 3b89ac4 commit 5b52664

File tree

1 file changed

+104
-104
lines changed

1 file changed

+104
-104
lines changed

src/CmsAdmin/Resource/web/js/tiny/plugins/lioniteimages/js/lioniteimages.js

Lines changed: 104 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@
7272
buttons: {
7373
'Usuń': function () {
7474
$.post(o.removeUrl, {cmsFileId: el.attr('data-id'), object: o.params.formObject, objectId: o.params.formObjectId}, 'json')
75-
.done(function (data) {
76-
if (data.result === 'OK') {
77-
el.parents('li:first').remove();
78-
} else {
75+
.done(function (data) {
76+
if (data.result === 'OK') {
77+
el.parents('li:first').remove();
78+
} else {
79+
$('#error').html('Usunięcie pliku nie powiodło się');
80+
}
81+
})
82+
.fail(function () {
7983
$('#error').html('Usunięcie pliku nie powiodło się');
80-
}
81-
})
82-
.fail(function () {
83-
$('#error').html('Usunięcie pliku nie powiodło się');
84-
});
84+
});
8585
$(this).dialog('close');
8686
},
8787
'Anuluj': function () {
@@ -136,87 +136,87 @@
136136

137137
//okienko edycji - pobieramy dane rekordu z bazy
138138
$.post('/cmsAdmin/upload/details', {cmsFileId: el.attr('data-id')}, 'json')
139-
.done(function (data) {
140-
if (data.result === 'OK' && data.record) {
141-
//przygotowujemy zawartość okienka edycji i pokazujemy go
142-
var edit = 'div#dialog-edit';
143-
144-
//video poster
145-
if( data.data['urlFile'] != undefined ){
146-
$('#video').find('#urlVideo').attr('src', data.data['urlFile']);
147-
$(edit + ' input[name="poster"]').val(data.data['poster']);
148-
new VideoFrameExtractor().initialize({
149-
input: '#poster',
150-
video: '#video',
151-
btn: '#frame-camera',
152-
output: '#output',
153-
dialog: '.ui-dialog'
154-
});
155-
}
139+
.done(function (data) {
140+
if (data.result === 'OK' && data.record) {
141+
//przygotowujemy zawartość okienka edycji i pokazujemy go
142+
var edit = 'div#dialog-edit';
143+
144+
//video poster
145+
if( data.data['urlFile'] != undefined ){
146+
$('#video').find('#urlVideo').attr('src', data.data['urlFile']);
147+
$(edit + ' input[name="poster"]').val(data.data['poster']);
148+
new VideoFrameExtractor().initialize({
149+
input: '#poster',
150+
video: '#video',
151+
btn: '#frame-camera',
152+
output: '#output',
153+
dialog: '.ui-dialog'
154+
});
155+
}
156156

157-
$(edit + ' input[name="title"]').val(data.data.title);
158-
$(edit + ' input[name="author"]').val(data.data.author);
159-
$(edit + ' .dialog-error').hide().find('p').text('');
157+
$(edit + ' input[name="title"]').val(data.data.title);
158+
$(edit + ' input[name="author"]').val(data.data.author);
159+
$(edit + ' .dialog-error').hide().find('p').text('');
160160

161-
$("div#dialog-edit select[name='source']").change(function () {
162-
$("div#dialog-edit #img-edit").attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
163-
if ($(this).val() != "") {
164-
$("div#dialog-edit #img-edit").attr('src', $(this).val());
165-
}
166-
});
161+
$("div#dialog-edit select[name='source']").change(function () {
162+
$("div#dialog-edit #img-edit").attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
163+
if ($(this).val() != "") {
164+
$("div#dialog-edit #img-edit").attr('src', $(this).val());
165+
}
166+
});
167167

168-
var editDialog = $(edit).dialog({
169-
width: ((screen.width * 0.5) * 0.8),
170-
height: ((screen.height * 0.8) * 0.8),
171-
maximiziable: true,
172-
modal: true,
173-
resizable: false,
174-
closeText: 'Zamknij',
175-
title: 'Edycja pliku',
176-
dialogClass: 'dialogEdit',
177-
buttons: {
178-
'Zapisz': function () {
179-
//trigger odświeżający dane
180-
//tinymce.triggerSave();
181-
$.post('/cmsAdmin/upload/describe',
182-
{cmsFileId: el.attr('data-id'),
183-
form: $(edit + ' input,' + edit + ' select,' + edit + ' textarea').serializeArray()
184-
}, 'json')
185-
.done(function (data) {
186-
if (data.result === 'OK') {
187-
editDialog.dialog('close');
188-
var posterSource = $("div#dialog-edit select[name='source']").val()
189-
|| $("div#dialog-edit input[name='poster']").val();
190-
el.parent().find('a.insert').attr('data-poster', posterSource);
191-
192-
//odswiezenie listy
193-
$.ajax({
194-
url: o.galleryUrl,
195-
success: function (response) {
196-
$('#lionite-gallery').html(response);
168+
var editDialog = $(edit).dialog({
169+
width: ((screen.width * 0.5) * 0.8),
170+
height: ((screen.height * 0.8) * 0.8),
171+
maximiziable: true,
172+
modal: true,
173+
resizable: false,
174+
closeText: 'Zamknij',
175+
title: 'Edycja pliku',
176+
dialogClass: 'dialogEdit',
177+
buttons: {
178+
'Zapisz': function () {
179+
//trigger odświeżający dane
180+
//tinymce.triggerSave();
181+
$.post('/cmsAdmin/upload/describe',
182+
{cmsFileId: el.attr('data-id'),
183+
form: $(edit + ' input,' + edit + ' select,' + edit + ' textarea').serializeArray()
184+
}, 'json')
185+
.done(function (data) {
186+
if (data.result === 'OK') {
187+
editDialog.dialog('close');
188+
var posterSource = $("div#dialog-edit select[name='source']").val()
189+
|| $("div#dialog-edit input[name='poster']").val();
190+
el.parent().find('a.insert').attr('data-poster', posterSource);
191+
192+
//odswiezenie listy
193+
$.ajax({
194+
url: o.galleryUrl,
195+
success: function (response) {
196+
$('#lionite-gallery').html(response);
197+
}
198+
});
199+
200+
} else {
201+
$(edit + ' .dialog-error p').text('Nie udało się zapisać zmian! Spróbuj ponownie!').parent().show();
197202
}
203+
})
204+
.fail(function () {
205+
$(edit + ' .dialog-error p').text('Nie udało się zapisać zmian! Spróbuj ponownie!').parent().show();
198206
});
199-
200-
} else {
201-
$(edit + ' .dialog-error p').text('Nie udało się zapisać zmian! Spróbuj ponownie!').parent().show();
202-
}
203-
})
204-
.fail(function () {
205-
$(edit + ' .dialog-error p').text('Nie udało się zapisać zmian! Spróbuj ponownie!').parent().show();
206-
});
207-
},
208-
'Anuluj': function () {
209-
$(this).dialog('close');
207+
},
208+
'Anuluj': function () {
209+
$(this).dialog('close');
210+
}
210211
}
211-
}
212-
});
213-
} else {
212+
});
213+
} else {
214+
alert('Pobranie opisu pliku nie powiodło się! Spróbuj ponownie');
215+
}
216+
})
217+
.fail(function () {
214218
alert('Pobranie opisu pliku nie powiodło się! Spróbuj ponownie');
215-
}
216-
})
217-
.fail(function () {
218-
alert('Pobranie opisu pliku nie powiodło się! Spróbuj ponownie');
219-
});
219+
});
220220

221221
}
222222

@@ -244,20 +244,20 @@
244244
ajaxUpload: function (el, connector) {
245245
var o = this.options;
246246
var url = connector,
247-
uploadButton = $('<button/>')
247+
uploadButton = $('<button/>')
248248
.addClass('btn btn-primary')
249249
.prop('disabled', true)
250250
.text('Processing...')
251251
.on('click', function () {
252252
var $this = $(this),
253-
data = $this.data();
253+
data = $this.data();
254254
$this
255-
.off('click')
256-
.text('Abort')
257-
.on('click', function () {
258-
$this.remove();
259-
data.abort();
260-
});
255+
.off('click')
256+
.text('Abort')
257+
.on('click', function () {
258+
$this.remove();
259+
data.abort();
260+
});
261261
data.submit().always(function () {
262262
$this.remove();
263263
});
@@ -309,40 +309,40 @@
309309
});
310310
$(el).on('fileuploadprocessalways', function (e, data) {
311311
var index = data.index,
312-
file = data.files[index],
313-
node = $(data.context.children()[index]);
312+
file = data.files[index],
313+
node = $(data.context.children()[index]);
314314

315315

316316
if (file.preview) {
317317
node
318-
.prepend('<br>')
319-
.prepend(file.preview);
318+
.prepend('<br>')
319+
.prepend(file.preview);
320320
}
321321
if (file.error) {
322322
var txt = file.error + ' : ' + file.name;
323323
$('#error')
324-
.append('<br>')
325-
.append($('<span class="text-danger"/>').text(txt));
324+
.append('<br>')
325+
.append($('<span class="text-danger"/>').text(txt));
326326
}
327327
if (index + 1 === data.files.length) {
328328
data.context.find('button')
329-
.text('Upload')
330-
.prop('disabled', !!data.files.error);
329+
.text('Upload')
330+
.prop('disabled', !!data.files.error);
331331
}
332332
});
333333
$(el).on('fileuploadprogressall', function (e, data) {
334334
var progress = parseInt(data.loaded / data.total * 100, 10);
335335
$('#progress .progress-bar').css(
336-
'width',
337-
progress + '%'
338-
);
336+
'width',
337+
progress + '%'
338+
);
339339
});
340340
$(el).on('fileuploadfail', function (e, data) {
341341
$.each(data.files, function (index, file) {
342342
var error = $('<span class="text-danger"/>').text('File upload failed.');
343343
$(data.context.children()[index])
344-
.append('<br>')
345-
.append(error);
344+
.append('<br>')
345+
.append(error);
346346
});
347347
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
348348

0 commit comments

Comments
 (0)