Файл: touchSpace/js/files_selector.js
Строк: 230
<?php
define("files_selector","init",function(){function e(e){p=extend({},S,e),i()}function i(){p.file_uploader&&require("files_uploader"),m={},f={},_=0,v=[],r(function(){var e=Spaces.view.modal.open();e.on("closewindow",function(e){h?(e.preventDefault(),o("Дождитесь завершения загрузки файла!")):_>0&&a()}),g=e.prop("content"),g.append('<div id="files_selector_error" class="error hide"></div>'),g.append('<div class="files_selector_files"></div>'),p.file_uploader&&t(),g.append('<div id="files_selector_list"></div>'),u=$("#files_selector_list"),u.on("click",".select_file_item",function(e){var i,t,a;e.preventDefault(),i=$(this),t=i.data("file_id"),h||(a=l(m[t]),p.maxFiles>1&&i.find('input[type="checkbox"]').prop("checked",a))}),u.on("click",".file_selector_backline",function(e){if(e.preventDefault(),v.length>0){var i=v.pop();n(i.dir,i.P)}}),u.on("click",".select_dir",function(e){e.preventDefault(),n($(this).data("dir_id"),!0)}),u.on("click",".list_type_selector",function(e){e.preventDefault(),v=[],p.dir=0,p.page=1,p.list=$(this).data("lt"),r()}),u.on("pagechange",function(e){e.preventDefault(),p.page=e.page,r()}),p.onRender&&p.onRender()})}function t(){var e=$("<div>");g.prepend(e),require("files_uploader",function(){Spaces.api("files.getUploadInfo",{Type:p.type},function(i){var t=new Url(i.url);p.attaches&&(t.query.Ss=1,t.query.Att=1),FileUploader.init({uploadWidget:e,name:"myFile",type:p.type,action:t.url(),maxSize:1024*i.maxSize*1024,autoSubmit:!0,mode:FileUploader.MODES.BUTTON,onSubmit:function(){h=!0;var e={dir:p.dir};p.attaches?(e.Ss=1,e.Att=1):e.dir=p.dir,FileUploader.setPostData(e)},onFileUpload:function(e){try{if(e.redirect_link&&!e.data)return void o('Загрузка файла заблокирована. <a href="'+e.redirect_link+'">Подробнее.</a>');l(e.data)}catch(i){alert("Очень страшная ошибка: "+i)}},onError:function(e){o(e)},onHideError:function(){o(!1)},onReset:function(){h=!1}})})})}function l(e){var i=!0;return Spaces.core.fixFile(e,p.type)?(e.show_preview=e.preview&&(e.type==Spaces.TYPES.VIDEO||e.type==Spaces.TYPES.PICTURE||w.test(e.fileext)),o(!1),p.maxFiles>1?(f[e.nid]?(--_,delete f[e.nid],i=!1):p.maxFiles<=_?(i=!1,o("Превышен лимит количества файлов!")):(++_,f[e.nid]=e),c()):(f[e.nid]=e,++_,a()),i):(console.error(e),o("Ошибка разбора файла!"))}function a(){var e,i,t;for(e in f)if(i=f[e],delete f[e],++_,p.onFileSelect&&(t=p.onFileSelect(i.nid,p.type,i),void 0!==t))return void o(t);tick(function(){s()})}function s(){u.remove(),Spaces.view.modal.close()}function n(e,i){i&&v.push({dir:p.dir,P:p.page}),p.dir=e,r()}function r(e){Spaces.api("files.select",{Type:p.type,Lt:p.list,P:p.page,Dir:p.dir},function(i){e&&e(),d(i.select_widget.listingW),Spaces.view.modal.scroll(0)})}function o(e){e?(e instanceof Array&&(e=e.join("<br />")),$("#files_selector_error").html(e).show(),Spaces.view.modal.scroll(0)):$("#files_selector_error").hide()}function c(){var e,i,t=$(".files_selector_files"),l="",a=!0;if($("#gallery_exit").toggleClass("gallery__select",_>0),_>0){l+='<div class="stnd_padd">Выбрано '+_+" из "+p.maxFiles+":<br />";for(e in f)i=f[e],l+=(a?"":", ")+'<img src="'+ICONS_BASEURL+Spaces.getFileIcon(i.fileext)+'" alt="" class="m" /> <span class="m t-strong_item t-link_item_hover">'+i.filename+"."+i.fileext+"</span></a>",a&&(a=!1);l+="</div>"}t.html(l)}function d(e){var i,t,l,a,s,n,r="";for(m={},r+='<div class="busi_switcher"><table width="100%"><tr>',r+=p.list==Spaces.FILES_LIST.DIRS?'<td><span class="active_item">папки</span></td><td><a href="#" class="list_type_selector" data-lt="'+Spaces.FILES_LIST.FILES+'"">все файлы</a></td>':'<td><a href="#" class="list_type_selector" data-lt="'+Spaces.FILES_LIST.DIRS+'"">папки</a></td><td><span class="active_item">все файлы</span></td>',r+="</tr></table></div>",v.length>0&&(r+='<div class="backlink"><a class="arrow_link file_selector_backline" href="#">← <span>Назад</span></a></div>'),i=e.dirs,t=0;t<i.length;++t)l="folder_user.gif",4==i[t].icon?l="folder_locked.gif":5==i[t].icon?l=k[i[t].type]:y[i[t].access_settings.mode]&&(l=y[i[t].access_settings.mode]),r+='<a href="#" data-dir_id="'+i[t].nid+'" class="select_dir no_ajax t-block_item t-padd_right light_border_bottom t-bg3 t-link_no_underline_block"><span class="t-block_item stnd_padd t-bg_arrow_next"> <img src="/i/'+l+'" alt="" class="icon icon_align" /> <span class="m t-strong_item t-link_item_hover">'+i[t].name+'</span> <small class="m">('+i[t].count+")</small></span></a>";for(a=e.files,s=0;s<a.length;++s)n=a[s],m[n.nid]=n,r+='<div data-file_id="'+n.nid+'" class="select_file_item list_item oh t-link_no_underline_block">',p.maxFiles>1&&(r+='<div class="left font0" style="margin-right:5px; position:relative;"><input type="checkbox" name="select_file" value="1"'+(f[n.nid]?' checked="checked"':"")+" /></div>"),n.preview.previewURL&&(r+='<div class="left font0" style="margin-right:5px; position:relative;"><img src="'+n.preview.previewURL+'" alt="" /></div>'),r+='<div class="oh"><span class="t-strong_item"><img src="'+ICONS_BASEURL+Spaces.getFileIcon(n.fileext)+'" alt="" class="m" /> <span class="m t-strong_item t-link_item_hover">'+n.filename+'</span></a> <span style="color:gray;" class="m">.'+n.fileext+"</span> "+(n.adult?'<img src="'+ICONS_BASEURL+'adult_ico.png" alt="" class="m" /> ':"")+'</span><span class="file_size right">'+n.weight+"</span><br /></div>"+(n.description||"")+"</div>";i.length||a.length||(r+='<div class="list_item">Папка пуста.</div>'),u.html(r),u.append(Spaces.templates.pagination(e.pagination,!0)),v.length>0&&u.append('<div class="backlink"><a class="arrow_link file_selector_backline" href="#">← <span>Назад</span></a></div>')}var p,f,_,m,v,g,u,S={dir:0,list:Spaces.FILES_LIST.DIRS,page:0,type:Spaces.TYPES.FILE,onFileSelect:null,onRender:null,file_uploader:!0,attaches:!0,maxFiles:1},h=!1,k={1:"film.gif",2:"file_mp3.gif",3:"PhotoIcon.gif"},y={2:"folder.gif",1:"folder_locked.gif",8:"folder_password.gif"},w=/^(gif|jpg|jpeg|png|bmp|avi|mpg|mp4|mpeg|asf|wmv|3gp|3gpp|flv|mov|wevm)$/i;window.FilesSelector={open:e}});
?>