sxFormFile = function(){
var self = this;
var url = '';
this.init = function(article_id, url){
this.article_id = article_id;
this.url = url || '/simpla/ajax/file.php';
this.$input = $('#art-files-input');
this.$filesDiv = $('.sx-form-images');
this.initFiles();
this.$filesDiv.on('click', '.sx-form-image-remove', function(){
self.removeFile($(this).attr('data-id'));
});
this.setFilesSortable();
}
this.saveFiles = function(dfd){
var i, flag = true;
dfd = dfd || $.Deferred();
for(i=0;i');
div.append(img);
div.append('
');
div.append('');
self.$filesDiv.append(div);
div.fadeIn('fast');
data.div = div;
data.uploaded = false;
});
}
this.reorder = function(){
var ids = [];
this.$filesDiv.find('.sx-form-preview').each(function(){
ids.push( $(this).attr('data-id') );
});
$.post(this.url, {action: 'reorder', ids: ids});
}
this.getPreview = function(file){
var dfd = $.Deferred();
dfd.resolve(file.preview);
return dfd.promise();
}
this.removeFile = function(id){
$('.sx-form-preview[data-id='+id+']').fadeOut('fast', function(){
$('.sx-form-preview[data-id='+id+']').remove();
});
$.post(this.url, {action: 'remove', id: id});
}
this.setFilesSortable = function(){
this.$filesDiv.sortable({
handle: '.sx-move-photo',
cursor: "move",
items: '.sx-form-preview',
stop: (event, ui) => {
self.reorder();
}
});
}
}