рефакторинг кода внутреннего браузера
This commit is contained in:
@@ -27,6 +27,10 @@ var delCascadConfirm = "Вы уверены что хотите удалить?"
|
||||
var saveMessageOk = "Данные сохранены";
|
||||
var DOC_REV_DEL_FROM = "Ревизия от ";
|
||||
var DOC_REV_DEL_SUCCESS = " удалена!";
|
||||
var MAIN_MP_PLEASE_SELECT = "Пожалуйста, выберите файл!";
|
||||
var MAIN_MP_CREATE_FOLDER = "Создать папку";
|
||||
var MAIN_ADD_FOLDER = "Имя папки";
|
||||
var MAIN_NO_ADD_FOLDER = "Папка не добавлена!";
|
||||
|
||||
//===== Date & Time Pickers =====//
|
||||
$.datepicker.regional['ru'] = {
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta name="Expires" content="Mon, 06 Jan 1990 00:00:01 GMT">
|
||||
<meta http-equiv="Expires" content="Mon, 06 Jan 1990 00:00:01 GMT">
|
||||
|
||||
<!-- CSS Files -->
|
||||
<link href="{$tpl_dir}/css/reset.css" rel="stylesheet" type="text/css" media="screen" />
|
||||
<link href="{$tpl_dir}/css/main.css" rel="stylesheet" type="text/css" media="screen" />
|
||||
<link href="{$tpl_dir}/css/data_table.css" rel="stylesheet" type="text/css" media="screen" />
|
||||
@@ -19,7 +18,6 @@
|
||||
<link href="{$tpl_dir}/css/color_{$smarty.const.DEFAULT_THEME_FOLDER_COLOR}.css" rel="stylesheet" type="text/css" media="screen" />
|
||||
<link href="{$tpl_dir}/css/browser.css" rel="stylesheet" type="text/css" media="screen" />
|
||||
|
||||
<!-- JS files -->
|
||||
{include file="../scripts.tpl"}
|
||||
|
||||
<script type="text/javascript" src="{$ABS_PATH}lib/scripts/uploader/browserplus.js"></script>
|
||||
@@ -27,23 +25,45 @@
|
||||
<script type="text/javascript" src="{$ABS_PATH}lib/scripts/uploader/jquery.plupload.queue.js"></script>
|
||||
<script type="text/javascript" src="{$ABS_PATH}lib/scripts/uploader/i18n/{$smarty.session.admin_language}.js"></script>
|
||||
|
||||
<script src="{$tpl_dir}/js/main.js" type="text/javascript"></script>
|
||||
<script src="{$tpl_dir}/js/main.js" type="text/javascript"></script>
|
||||
|
||||
<!-- JS Scripts -->
|
||||
<script type="text/javascript">
|
||||
let ave_path = "{$ABS_PATH}";
|
||||
let ave_theme = "{$smarty.const.DEFAULT_THEME_FOLDER}";
|
||||
let ave_admintpl = "{$tpl_dir}";
|
||||
let th_folder = "{$smarty.const.THUMBNAIL_DIR}";
|
||||
// Глобальные переменные, не зависящие от URL-параметров
|
||||
let ave_path = '{$ABS_PATH|escape|default:''}';
|
||||
let ave_theme = '{$smarty.const.DEFAULT_THEME_FOLDER|escape|default:''}';
|
||||
let ave_admintpl = '{$tpl_dir|escape|default:''}';
|
||||
let th_folder = '{$smarty.const.THUMBNAIL_DIR|escape|default:''}';
|
||||
let sess = '{$sess|escape|default:''}';
|
||||
|
||||
// Константы Smarty, которые будут инициализированы в $(document).ready
|
||||
let IS_MULTILINK;
|
||||
let REQUEST_ID;
|
||||
let TARGET;
|
||||
let TARGET_ID;
|
||||
let MEDIA_PATH;
|
||||
let REQUEST_TARGET;
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
let sess = '{$sess}';
|
||||
|
||||
$(document).ready(function(){ldelim}
|
||||
// Извлекаем константы из скрытых полей (ЧИТАЕМ ИЗ HTML)
|
||||
const REQUEST_ID_VALUE = $('#hidden_request_id').val();
|
||||
const TARGET_VALUE = $('#hidden_target').val();
|
||||
const TARGET_ID_VALUE = $('#hidden_target_id').val();
|
||||
const MEDIA_PATH_VALUE = $('#hidden_mediapath').val();
|
||||
const REQUEST_TARGET_VALUE = $('#hidden_request_target').val();
|
||||
|
||||
// Инициализируем глобальные константы для browser_logic.js
|
||||
IS_MULTILINK = REQUEST_ID_VALUE.substring(0, 6) === 'links_';
|
||||
REQUEST_ID = REQUEST_ID_VALUE;
|
||||
TARGET = TARGET_VALUE;
|
||||
TARGET_ID = TARGET_ID_VALUE;
|
||||
MEDIA_PATH = MEDIA_PATH_VALUE;
|
||||
REQUEST_TARGET = REQUEST_TARGET_VALUE;
|
||||
|
||||
$('.openDialog').prop(
|
||||
{ldelim}
|
||||
href: 'index.php?do=browser&type={$smarty.request.type|escape}&target={$smarty.request.target|escape}&action=upload&directory=' + $('#DirName').val()
|
||||
{rdelim}
|
||||
{
|
||||
href: 'index.php?do=browser&type=' + REQUEST_TARGET + '&target=' + TARGET + '&action=upload&directory=' + $('#DirName').val()
|
||||
}
|
||||
);
|
||||
|
||||
{literal}
|
||||
@@ -64,16 +84,25 @@
|
||||
);
|
||||
{/literal}
|
||||
|
||||
{rdelim});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<script src="{$tpl_dir}/js/browser_logic.js" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<input type="hidden" id="hidden_request_id" value="{if isset($smarty.request.id)}{$smarty.request.id|escape:'html'}{/if}">
|
||||
<input type="hidden" id="hidden_target" value="{if isset($target)}{$target|escape:'html'}{/if}">
|
||||
<input type="hidden" id="hidden_target_id" value="{if isset($target_id)}{$target_id|escape:'html'}{/if}">
|
||||
<input type="hidden" id="hidden_mediapath" value="{if isset($mediapath)}{$mediapath|escape:'html'}{/if}">
|
||||
<input type="hidden" id="hidden_request_target" value="{if isset($smarty.request.target)}{$smarty.request.target|escape:'html'}{/if}">
|
||||
|
||||
<body>
|
||||
<!-- Wrapper -->
|
||||
<div class="wrapper">
|
||||
<!-- Content -->
|
||||
|
||||
|
||||
<div class="content" id="contentPage" style="padding: 0px;">
|
||||
|
||||
<div class="first"></div>
|
||||
@@ -127,114 +156,6 @@
|
||||
<div class="fix"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function getUrlParam(paramName)
|
||||
{ldelim}
|
||||
let reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i') ;
|
||||
let match = window.location.search.match(reParam) ;
|
||||
|
||||
return (match && match.length > 1) ? match[1] : '' ;
|
||||
{rdelim}
|
||||
|
||||
function getImgPreview (url)
|
||||
{ldelim}
|
||||
let parts = url.split('/');
|
||||
let fileName = parts.pop();
|
||||
let fileExt = fileName.split('.').pop();
|
||||
|
||||
let thumb = th_folder + '/' + fileName.substr(0, fileName.lastIndexOf(".")) + '-t128x128.' + fileExt;
|
||||
|
||||
parts.push(thumb);
|
||||
|
||||
return parts.join('/');
|
||||
{rdelim}
|
||||
|
||||
function submitTheForm() {ldelim}
|
||||
if (document.bForm.bFileName.value == '' && ('{$target}' != 'dir' && '{$target}' != 'directory' && '{$target}' != 'cascad')) {ldelim}
|
||||
alert('{#MAIN_MP_PLEASE_SELECT#}');
|
||||
{rdelim}
|
||||
else {ldelim}
|
||||
|
||||
{if $target=='link'}
|
||||
var funcNum = getUrlParam('CKEditorFuncNum');
|
||||
var fileUrl = '{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
|
||||
|
||||
{elseif $target=='link_image'}
|
||||
window.opener.document.getElementById('txtLnkUrl').value = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
|
||||
{elseif $target=='txtUrl'}
|
||||
var funcNum = getUrlParam('CKEditorFuncNum');
|
||||
var fileUrl = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value
|
||||
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
|
||||
|
||||
{elseif $target=='navi'}
|
||||
window.opener.document.getElementById('{$smarty.request.id|escape}').value = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
|
||||
{elseif $target=='img_feld' || $target_img=='img_feld'}
|
||||
let imgSource = '/' + '{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.document.getElementById('img_feld__{$target_id}').value = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.document.getElementById('_img_feld__{$target_id}').src = getImgPreview(imgSource);
|
||||
window.opener.$('.preview__{$target_id}').attr("href", getImgPreview(imgSource));
|
||||
{elseif $target!='' && $target_id!='' && $target_id!=null}
|
||||
|
||||
{if $target=='image'}
|
||||
let imgSource = '/' + '{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.$('#preview__{$target_id}').attr('src', getImgPreview(imgSource));
|
||||
window.opener.$('.preview__{$target_id}').attr('href', '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
|
||||
window.opener.$('#{$target}__{$target_id}').val('/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
|
||||
{/if}
|
||||
|
||||
{if $target=='dir'}
|
||||
var bdn = document.bForm.bDirName.value.split('/').reverse();
|
||||
window.opener.document.getElementById('{$target}__{$target_id}').value = bdn[1];
|
||||
{/if}
|
||||
|
||||
{if $target=='directory'}
|
||||
window.opener.$.fn.myPlugin('/{$mediapath}' + document.bForm.bDirName.value, {$target_id});
|
||||
{/if}
|
||||
|
||||
{if $target=='cascad'}
|
||||
{assign var=data value="_"|explode:$target_id}
|
||||
window.opener.$.fn.myPlugin('/{$mediapath}' + document.bForm.bDirName.value, {$data[0]}, {$data[1]});
|
||||
{/if}
|
||||
|
||||
{elseif $target!='all'}
|
||||
{if isset($smarty.request.fillout) and $smarty.request.fillout == 'dl'}
|
||||
window.opener.document.getElementById('{$smarty.request.target|escape}').value = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
{else}
|
||||
//window.opener.updatePreview();
|
||||
{/if}
|
||||
{/if}
|
||||
setTimeout("self.close();", 100);
|
||||
{rdelim}
|
||||
{rdelim}
|
||||
|
||||
function NewFolder() {ldelim}
|
||||
var title = '{#MAIN_MP_CREATE_FOLDER#}';
|
||||
var text = '{#MAIN_ADD_FOLDER#}';
|
||||
jPrompt(text, '', title, function(b){ldelim}
|
||||
if (b){ldelim}
|
||||
$.alerts._overlay('hide');
|
||||
$.alerts._overlay('show');
|
||||
parent.frames['zf'].location.href='index.php?do=browser&type={$smarty.request.type|escape}&target={$smarty.request.target|escape}&action=list&dir=' + document.bForm.bDirName.value + '&newdir=' + b;
|
||||
$.alerts._overlay('hide');
|
||||
{rdelim}
|
||||
else
|
||||
{ldelim}
|
||||
$.alerts._overlay('hide');
|
||||
$.jGrowl('{#MAIN_NO_ADD_FOLDER#}');
|
||||
{rdelim}
|
||||
{rdelim}
|
||||
);
|
||||
{rdelim}
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="{$ABS_PATH}admin/lang/{$smarty.session.admin_language}/scripts.js"></script>
|
||||
|
||||
<!-- Footer -->
|
||||
<div id="footer">
|
||||
<div class="wrapper">
|
||||
<span class="floatleft">{#oficial_site#}: {$smarty.const.APP_INFO}</span>
|
||||
@@ -242,6 +163,8 @@
|
||||
<span class="floatright">{$smarty.const.APP_NAME} v{$smarty.const.APP_VERSION}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="{$ABS_PATH}admin/lang/{$smarty.session.admin_language}/scripts.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
118
admin/templates/js/browser_logic.js
Normal file
118
admin/templates/js/browser_logic.js
Normal file
@@ -0,0 +1,118 @@
|
||||
// browser_logic.js
|
||||
// Этот файл использует глобальные константы, определенные в шаблоне
|
||||
// (IS_MULTILINK, REQUEST_ID, TARGET, TARGET_ID, MEDIA_PATH, REQUEST_TARGET, th_folder)
|
||||
|
||||
window.getUrlParam = function(paramName) {
|
||||
let reParam = new RegExp('(?:[\\?&]|&)' + paramName + '=([^&]+)', 'i');
|
||||
let match = window.location.search.match(reParam);
|
||||
return (match && match.length > 1) ? match[1] : '';
|
||||
}
|
||||
|
||||
window.getImgPreview = function(url) {
|
||||
let parts = url.split('/');
|
||||
let fileName = parts.pop();
|
||||
let fileExt = fileName.split('.').pop();
|
||||
|
||||
// th_folder определен в шаблоне
|
||||
let thumb = th_folder + '/' + fileName.substr(0, fileName.lastIndexOf(".")) + '-t128x128.' + fileExt;
|
||||
|
||||
parts.push(thumb);
|
||||
return parts.join('/');
|
||||
}
|
||||
|
||||
window.submitTheForm = function() {
|
||||
var bDirName = document.bForm.bDirName.value;
|
||||
if (bDirName && !bDirName.endsWith('/')) {
|
||||
document.bForm.bDirName.value = bDirName + '/';
|
||||
}
|
||||
|
||||
if (document.bForm.bFileName.value == '' && (TARGET != 'dir' && TARGET != 'directory' && TARGET != 'cascad')) {
|
||||
alert(MAIN_MP_PLEASE_SELECT);
|
||||
} else {
|
||||
|
||||
if (IS_MULTILINK) {
|
||||
let fullPath = MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
// Убедимся, что путь начинается со слэша, если MEDIA_PATH его не содержит
|
||||
if (!fullPath.startsWith('/')) {
|
||||
fullPath = '/' + fullPath;
|
||||
}
|
||||
window.opener.document.getElementById(REQUEST_ID).value = fullPath;
|
||||
}
|
||||
|
||||
else {
|
||||
if (TARGET == 'link') {
|
||||
var funcNum = window.getUrlParam('CKEditorFuncNum');
|
||||
var fileUrl = MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
|
||||
|
||||
} else if (TARGET == 'link_image') {
|
||||
window.opener.document.getElementById('txtLnkUrl').value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
|
||||
} else if (TARGET == 'txtUrl') {
|
||||
var funcNum = window.getUrlParam('CKEditorFuncNum');
|
||||
var fileUrl = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value
|
||||
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
|
||||
|
||||
} else if (TARGET == 'navi') {
|
||||
window.opener.document.getElementById(REQUEST_ID).value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
|
||||
} else if (TARGET == 'img_feld') {
|
||||
let imgSource = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.document.getElementById('img_feld__' + TARGET_ID).value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.document.getElementById('_img_feld__' + TARGET_ID).src = window.getImgPreview(imgSource);
|
||||
window.opener.$('.preview__' + TARGET_ID).attr("href", window.getImgPreview(imgSource));
|
||||
|
||||
} else if (TARGET != '' && TARGET_ID != '' && TARGET_ID != null) {
|
||||
|
||||
if (TARGET == 'image') {
|
||||
let imgSource = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
window.opener.$('#preview__' + TARGET_ID).attr('src', window.getImgPreview(imgSource));
|
||||
window.opener.$('.preview__' + TARGET_ID).attr('href', '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value);
|
||||
window.opener.$('#' + TARGET + '__' + TARGET_ID).val('/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value);
|
||||
}
|
||||
|
||||
if (TARGET == 'dir') {
|
||||
var bdn = document.bForm.bDirName.value.split('/').reverse();
|
||||
window.opener.document.getElementById(TARGET + '__' + TARGET_ID).value = bdn[1];
|
||||
}
|
||||
|
||||
if (TARGET == 'directory') {
|
||||
window.opener.$.fn.myPlugin('/' + MEDIA_PATH + document.bForm.bDirName.value, TARGET_ID);
|
||||
}
|
||||
|
||||
if (TARGET == 'cascad') {
|
||||
var data_parts = TARGET_ID.split('_');
|
||||
var data_id_0 = data_parts[0];
|
||||
var data_id_1 = data_parts[1];
|
||||
window.opener.$.fn.myPlugin('/' + MEDIA_PATH + document.bForm.bDirName.value, data_id_0, data_id_1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if (TARGET != 'all') {
|
||||
if (REQUEST_TARGET != '') {
|
||||
window.opener.document.getElementById(REQUEST_TARGET).value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout("self.close();", 100);
|
||||
}
|
||||
}
|
||||
|
||||
window.NewFolder = function() {
|
||||
var title = MAIN_MP_CREATE_FOLDER;
|
||||
var text = MAIN_ADD_FOLDER;
|
||||
jPrompt(text, '', title, function(b) {
|
||||
if (b) {
|
||||
$.alerts._overlay('hide');
|
||||
$.alerts._overlay('show');
|
||||
// используем REQUEST_TARGET (значение, полученное из TARGET)
|
||||
window.parent.frames['zf'].location.href = 'index.php?do=browser&type=' + REQUEST_TARGET + '&target=' + TARGET + '&action=list&dir=' + document.bForm.bDirName.value + '&newdir=' + b;
|
||||
$.alerts._overlay('hide');
|
||||
} else {
|
||||
$.alerts._overlay('hide');
|
||||
$.jGrowl(MAIN_NO_ADD_FOLDER);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -88,14 +88,23 @@ function openLinkWindow(target, doc, document_alias) {
|
||||
window.open('index.php?doc=' + doc + '&target=' + target + '&document_alias=' + document_alias + '&do=docs&action=showsimple&cp=' + sess + '&pop=1', 'pop', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',scrollbars=' + scrollbar + ',resizable=1');
|
||||
}
|
||||
|
||||
function openFileWindow(target, id, document_alias) {
|
||||
if (typeof width == 'undefined' || width == '') var width = screen.width * 0.6;
|
||||
if (typeof height == 'undefined' || height == '') var height = screen.height * 0.6;
|
||||
if (typeof doc == 'undefined') var doc = 'Title';
|
||||
if (typeof scrollbar == 'undefined') var scrollbar = 1;
|
||||
var left = (screen.width - width) / 2;
|
||||
var top = (screen.height - height) / 2;
|
||||
window.open('index.php?do=browser&id=' + id + '&type=file&target=navi&cp=' + sess, 'pop', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',scrollbars=' + scrollbar + ',resizable=1');
|
||||
function openFileWindow(id, type, target) {
|
||||
if (typeof width == 'undefined' || width == '') var width = screen.width * 0.6;
|
||||
if (typeof height == 'undefined' || height == '') var height = screen.height * 0.6;
|
||||
if (typeof doc == 'undefined') var doc = 'Title';
|
||||
if (typeof scrollbar == 'undefined') var scrollbar = 1;
|
||||
var left = (screen.width - width) / 2;
|
||||
var top = (screen.height - height) / 2;
|
||||
|
||||
// Передаем id и target в URL
|
||||
var url = 'index.php?do=browser&id=' + id + '&type=' + type + '&target=' + target + '&cp=' + sess;
|
||||
|
||||
// Добавляем флаг для Мультиссылки, если ID начинается с 'links_'
|
||||
if (typeof id === 'string' && id.startsWith('links_')) {
|
||||
url += '&is_multilink=1';
|
||||
}
|
||||
|
||||
window.open(url, 'pop', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',scrollbars=' + scrollbar + ',resizable=1');
|
||||
}
|
||||
|
||||
// Функция-плагин для включения tipsy сразу для всех классов внутри элемента
|
||||
|
||||
Reference in New Issue
Block a user