Вход Регистрация
Файл: templates/modern/js/images-upload.js
Строк: 286
<?php
var icms icms || {};

icms.images = (function ($) {

    var 
self this;

    
this.uploadCallback null;
    
this.removeCallback null;

    
this._onMultiSubmit = function(field_name){
        var 
widget = $('#widget_image_'+field_name);
        $(
'.previews_list'widget).append($('.preview_template'widget).clone().removeClass('preview_template').addClass('loading').attr('id''img-multi-submit').show());
    };

    
this._onSubmit = function(field_name){
        var 
widget = $('#widget_image_'+field_name);
        $(
'.upload'widget).hide();
        $(
'.loading'widget).show();
    };

    
this._showButton = function(field_name){
        var 
widget = $('#widget_image_'+field_name);
        $(
'.upload'widget).show();
        $(
'.loading'widget).hide();
    };

    
this._onComplete = function(field_nameresult){

        var 
widget = $('#widget_image_'+field_name);

        if(!
result.success) {
            
icms.modal.alert(result.error);
            
self._showButton(field_name);
            return;
        }

        var 
preview_img_src null;
        var 
image_data = {};

        $(
'.data'widget).html('');

        var 
_input_name field_name.replace(/_l_/g'[');
        
_input_name _input_name.replace(/_r_/g']');

        for(var 
path in result.paths){
            
preview_img_src preview_img_src || result.paths[path].url;
            $(
'.data'widget).append('<input type="hidden" name="'+_input_name+'['+path+']" value="'+result.paths[path].path+'" />');
            
image_data[path] = result.paths[path].path;
        }

        $(
'.preview img'widget).attr('src'preview_img_src);
        $(
'.preview'widget).show().data('paths'image_data);
        $(
'.loading'widget).hide();

        if (
typeof(self.uploadCallback) === 'function'){
            
self.uploadCallback(field_nameresult);
        }
    };

    
this._onMultiComplete = function (field_nameresult){

        $(
'#img-multi-submit'widget).remove();

        var 
widget = $('#widget_image_'+field_name);

        if(!
result.success) {
            return;
        }

        var 
idx = $('.data input:last'widget).attr('rel');
        if (
typeof(idx) === 'undefined') { idx 0; } else { idx++; }

        var 
preview_block = $('.preview_template'widget).clone().removeClass('preview_template').attr('rel'idx).show();

        var 
preview_img_src null;

        var 
image_data = {};

        var 
_input_name field_name.replace(/_l_/g'[');
        
_input_name _input_name.replace(/_r_/g']');

        for(var 
path in result.paths){
            
preview_img_src preview_img_src || result.paths[path].url;
            $(
'.data'widget).append('<input type="hidden" name="'+_input_name+'['+idx+']['+path+']" value="'+result.paths[path].path+'" rel="'+idx+'" />');
            
image_data[path] = result.paths[path].path;
        }

        $(
preview_block).data('paths'image_data);
        $(
'img'preview_block).attr('src'preview_img_src);
        $(
'a'preview_block).data('id'idx).click(function() { self.removeOne(field_namethis); });

        $(
'.previews_list'widget).append(preview_block);

    };

    
this.uploadByLink = function(field_nameupload_urllink){
        
self._onSubmit(field_name);
        var 
post_params = {}; post_params[field_name] = link;
        $.
post(upload_urlpost_params, function(result){
            
self._onComplete(field_nameresult);
        }, 
'json');
    };

    
this.uploadMultyByLink = function(field_nameupload_urllinkmax_imagesLANG_UPLOAD_ERR_MAX_IMAGES){
        
max_images = +(max_images || 0);
        if(
max_images && self.incrementUploadedCount(field_name) > max_images){
            
self.decrementUploadedCount(field_name);
            
icms.modal.alert(LANG_UPLOAD_ERR_MAX_IMAGES);
            return 
false;
        }
        
self._onMultiSubmit(field_name);
        var 
post_params = {}; post_params[field_name] = link;
        $.
post(upload_urlpost_params, function(result){
            
self._onMultiComplete(field_nameresult);
        }, 
'json');
    };

    
this.upload = function(field_nameupload_url){

        var 
uploader = new qq.FileUploader({
            
elementdocument.getElementById('file-uploader-'+field_name),
            
actionupload_url,
            
multiplefalse,
            
debugfalse,
            
showMessage: function(message){
                
icms.modal.alert(message);
            },
            
onSubmit: function(idfileName){
                var 
ftitle = $('#title').val();
                if(
ftitle){
                    
this.params = {
                        
file_name: $('#title').val()+' '+field_name
                    
};
                }
                
self._onSubmit(field_name);
            },

            
onComplete: function(idfile_nameresult){
                
self._onComplete(field_nameresult);
            }

        });

    };

    
this.incrementUploadedCount = function (field_name){

        var 
current_count = +$('#file-uploader-'+field_name).data('uploaded_count');

        
current_count += 1;

        $(
'#file-uploader-'+field_name).data('uploaded_count'current_count);

        return 
current_count;

    };

    
this.decrementUploadedCount = function (field_name){

        var 
current_count = +$('#file-uploader-'+field_name).data('uploaded_count');

        
current_count -= 1;

        $(
'#file-uploader-'+field_name).data('uploaded_count'current_count);

        return 
current_count;

    };

    
this.createUploader = function(field_nameupload_urlmax_imagesLANG_UPLOAD_ERR_MAX_IMAGES){

        
max_images = +(max_images || 0);

        var 
uploader = new qq.FileUploader({
            
elementdocument.getElementById('file-uploader-'+field_name),
            
actionupload_url,
            
debugfalse,
            
showMessage: function(message){
                
icms.modal.alert(message);
            },
            
onSubmit: function(idfileName){
                if(
max_images && self.incrementUploadedCount(field_name) > max_images){
                    
self.decrementUploadedCount(field_name);
                    
icms.modal.alert(LANG_UPLOAD_ERR_MAX_IMAGES);
                    return 
false;
                }
                var 
ftitle = $('#title').val();
                if(
ftitle){
                    
this.params = {
                        
file_name: $('#title').val()+' '+field_name
                    
};
                }
                
self._onMultiSubmit(field_name);
            },
            
onComplete: function(idfile_nameresult){
                
self._onMultiComplete(field_nameresult);
            }
        });

    };

    
this.initSortable = function (field_name){
        var 
widget = $('#widget_image_'+field_name);
        var 
_input_name field_name.replace(/_l_/g'[');
        
_input_name _input_name.replace(/_r_/g']');
        $(
'.previews_list'widget).sortable({
            
items'.preview',
            
cursor'move',
            
cancel'a',
            
reverttrue,
            
opacity0.9,
            
delay150,
            
placeholder'colplaceholder',
            
start: function(eventui) {
                $(
ui.placeholder).addClass($(ui.item).attr('class'));
                $(
ui.placeholder).height($(ui.item).height());
                $(
ui.placeholder).width($(ui.item).width());
            },
            
update: function(eventui) {
                $(
'.data'widget).html('');
                $(
'.previews_list .preview'widget).each(function(index){
                    $(
this).attr('rel'index).find('a').data('id'index);
                    var 
paths = $(this).data('paths');
                    for(var 
path in paths){
                        $(
'.data'widget).append('<input type="hidden" name="'+_input_name+'['+index+']['+path+']" value="'+paths[path]+'" rel="'+index+'" />');
                    }

                });
            }
        });
    };

    
this.remove = function(field_name){

        var 
widget = $('#widget_image_'+field_name);

        $(
'.preview > .btn'widget).addClass('is-busy');

        var 
delete_url = $(widget).data('delete_url');
        var 
paths = $('.preview'widget).data('paths');

        $.
post(delete_url, {pathspathscsrf_tokenicms.forms.getCsrfToken()}, function(result){

            $(
'.preview > .btn'widget).removeClass('is-busy');

            if (
result.error){
                
alert(result.message);
                return 
false;
            }

            $(
'.preview'widget).hide().data('paths', {});
            $(
'.preview img'widget).attr('src''');
            $(
'.upload'widget).show();
            $(
'.loading'widget).hide();
            $(
'.data'widget).html('');

            if (
typeof(self.removeCallback) === 'function'){
                
self.removeCallback(field_name);
            }
        }, 
'json');

        return 
false;
    };

    
this.removeOne = function(field_namelink){

        $(
link).addClass('is-busy');

        var 
idx = $(link).data('id');

        var 
widget = $('#widget_image_'+field_name);

        var 
delete_url = $(widget).data('delete_url');
        var 
paths = $('.preview[rel='+idx+']'widget).data('paths');

        $.
post(delete_url, {pathspathscsrf_tokenicms.forms.getCsrfToken()}, function(result){

            $(
link).removeClass('is-busy');

            if (
result.error){
                
alert(result.message);
                return 
false;
            }

            $(
'.data input[rel='+idx+']'widget).remove();
            $(
'.preview[rel='+idx+']'widget).remove();

            
self.decrementUploadedCount(field_name);

            if (
typeof(self.removeCallback) === 'function'){
                
self.removeCallback(field_nameidx);
            }
        }, 
'json');

        return 
false;
    };

    return 
this;

}).
call(icms.images || {},jQuery);
?>
Онлайн: 2
Реклама