mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-26 03:30:48 +03:00
Доработка превью медиа - вкладка с выводом превью
This commit is contained in:
parent
b669141779
commit
67ca968528
|
@ -86,6 +86,7 @@ class ActionAjax extends Action {
|
|||
$this->AddEventPreg('/^media$/i','/^remove-file$/','/^$/','EventMediaRemoveFile');
|
||||
$this->AddEventPreg('/^media$/i','/^create-preview-file$/','/^$/','EventMediaCreatePreviewFile');
|
||||
$this->AddEventPreg('/^media$/i','/^remove-preview-file$/','/^$/','EventMediaRemovePreviewFile');
|
||||
$this->AddEventPreg('/^media$/i','/^load-preview-items$/','/^$/','EventMediaLoadPreviewItems');
|
||||
$this->AddEventPreg('/^media$/i','/^save-data-file$/','/^$/','EventMediaSaveDataFile');
|
||||
|
||||
$this->AddEventPreg('/^property$/i','/^tags$/','/^autocompleter$/','/^$/','EventPropertyTagsAutocompleter');
|
||||
|
@ -662,6 +663,50 @@ class ActionAjax extends Action {
|
|||
}
|
||||
|
||||
$this->Viewer_AssignAjax('sTemplate',$sTemplate);
|
||||
|
||||
/**
|
||||
* Дополнительно загружам превью
|
||||
*/
|
||||
$aFilter=array(
|
||||
'target_type'=>$sType,
|
||||
'is_preview'=>1,
|
||||
);
|
||||
if ($sId) {
|
||||
$aFilter['target_id']=$sId;
|
||||
} else {
|
||||
$aFilter['target_tmp']=$sTmp;
|
||||
}
|
||||
$aTargetItems=$this->Media_GetTargetItemsByFilter($aFilter);
|
||||
$oViewer->Assign('aTargetItems',$aTargetItems);
|
||||
$this->Viewer_AssignAjax('sTemplatePreview',$oViewer->Fetch('modals/modal.upload_image.preview.tpl'));
|
||||
}
|
||||
|
||||
protected function EventMediaLoadPreviewItems() {
|
||||
/**
|
||||
* Пользователь авторизован?
|
||||
*/
|
||||
if (!$this->oUserCurrent) {
|
||||
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
|
||||
return;
|
||||
}
|
||||
|
||||
$sType=getRequestStr('target_type');
|
||||
$sId=getRequestStr('target_id');
|
||||
$sTmp=getRequestStr('target_tmp');
|
||||
|
||||
$aFilter=array(
|
||||
'target_type'=>$sType,
|
||||
'is_preview'=>1,
|
||||
);
|
||||
if ($sId) {
|
||||
$aFilter['target_id']=$sId;
|
||||
} else {
|
||||
$aFilter['target_tmp']=$sTmp;
|
||||
}
|
||||
$aTargetItems=$this->Media_GetTargetItemsByFilter($aFilter);
|
||||
$oViewer=$this->Viewer_GetLocalViewer();
|
||||
$oViewer->Assign('aTargetItems',$aTargetItems);
|
||||
$this->Viewer_AssignAjax('sTemplatePreview',$oViewer->Fetch('modals/modal.upload_image.preview.tpl'));
|
||||
}
|
||||
|
||||
protected function EventMediaSubmitInsert() {
|
||||
|
|
|
@ -730,10 +730,18 @@ class ModuleMedia extends ModuleORM {
|
|||
*/
|
||||
public function GetImagePathBySize($sPath,$sSize) {
|
||||
$aPathInfo=pathinfo($sPath);
|
||||
if (preg_match('#^(\d+)([a-z]{2,10})?$#i',$sSize,$aMatch)) {
|
||||
$sSize=$aMatch[1].'x'.$aMatch[1];
|
||||
if (isset($aMatch[2])) {
|
||||
$sSize.=strtolower($aMatch[2]);
|
||||
if (is_array($sSize)) {
|
||||
$aSize=$sSize;
|
||||
$sSize = $aSize['w'].'x'.$aSize['h'];
|
||||
if ($aSize['crop']) {
|
||||
$sSize.='crop';
|
||||
}
|
||||
} else {
|
||||
if (preg_match('#^(\d+)([a-z]{2,10})?$#i',$sSize,$aMatch)) {
|
||||
$sSize=$aMatch[1].'x'.$aMatch[1];
|
||||
if (isset($aMatch[2])) {
|
||||
$sSize.=strtolower($aMatch[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $aPathInfo['dirname'].'/'.$aPathInfo['filename'].'_'.$sSize.'.'.$aPathInfo['extension'];
|
||||
|
|
|
@ -62,4 +62,16 @@ class ModuleMedia_EntityTarget extends EntityORM {
|
|||
$aData[$sKey]=$mValue;
|
||||
$this->setData($aData);
|
||||
}
|
||||
|
||||
public function getPreviewImageItemsWebPath() {
|
||||
$aPreviewItems=array();
|
||||
$sPathbase=$this->getDataOne('image_preview');
|
||||
$aSizes=$this->getDataOne('image_preview_sizes');
|
||||
if ($sPathbase and $aSizes) {
|
||||
foreach($aSizes as $aSize) {
|
||||
$aPreviewItems[]=$this->Media_GetImageWebPath($sPathbase,$aSize);
|
||||
}
|
||||
}
|
||||
return $aPreviewItems;
|
||||
}
|
||||
}
|
|
@ -72,6 +72,7 @@ ls.media = (function ($) {
|
|||
remove_file: aRouter['ajax'] + "media/remove-file/",
|
||||
create_preview_file: aRouter['ajax'] + "media/create-preview-file/",
|
||||
remove_preview_file: aRouter['ajax'] + "media/remove-preview-file/",
|
||||
load_preview_items: aRouter['ajax'] + "media/load-preview-items/",
|
||||
load_gallery: aRouter['ajax'] + "media/load-gallery/",
|
||||
generate_target_tmp: aRouter['ajax'] + "media/generate-target-tmp/",
|
||||
submit_insert: aRouter['ajax'] + "media/submit-insert/",
|
||||
|
@ -461,6 +462,7 @@ ls.media = (function ($) {
|
|||
* Обновляем отображение информации
|
||||
*/
|
||||
this.showDetail(item);
|
||||
this.loadPreviewItems();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
@ -492,6 +494,7 @@ ls.media = (function ($) {
|
|||
* Обновляем отображение информации
|
||||
*/
|
||||
this.showDetail(item);
|
||||
this.loadPreviewItems();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
@ -505,9 +508,21 @@ ls.media = (function ($) {
|
|||
ls.ajax.load(this.options.routers.load_gallery, { target_type: this.options.target_type, target_id: this.options.target_id, target_tmp: this.options.target_tmp }, function(result) {
|
||||
this.elements.gallery.fileList.removeClass( ls.options.classes.states.loading ).html(result.sTemplate);
|
||||
this[result.sTemplate ? 'markAsNotEmpty' : 'markAsEmpty']();
|
||||
|
||||
this.renderPreviewItems(result.sTemplatePreview);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
this.loadPreviewItems = function() {
|
||||
ls.ajax.load(this.options.routers.load_preview_items, { target_type: this.options.target_type, target_id: this.options.target_id, target_tmp: this.options.target_tmp }, function(result) {
|
||||
this.renderPreviewItems(result.sTemplatePreview);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
this.renderPreviewItems = function(sTemplatePreview) {
|
||||
$('#tab-media-preview').find('.modal-content').html(sTemplatePreview);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{if $aTargetItems}
|
||||
|
||||
{foreach $aTargetItems as $oTarget}
|
||||
{$aPreview=$oTarget->getPreviewImageItemsWebPath()}
|
||||
{foreach $aPreview as $sPreviewFile}
|
||||
<img src="{$sPreviewFile}" alt="">
|
||||
{/foreach}
|
||||
<a href="#" onclick="ls.media.removePreviewFile({$oTarget->getMediaId()}); return false;">Удалить превью</a>
|
||||
{/foreach}
|
||||
|
||||
{else}
|
||||
Превью можно <a href="#" onclick="jQuery('.js-tab-show-gallery').first().click(); return false;">выбрать из галереи</a>.
|
||||
{/if}
|
|
@ -39,6 +39,9 @@
|
|||
<li data-type="tab" data-tab-target="tab-media-insert" data-media-mode="insert" class="active js-tab-show-gallery"><a href="#">Вставить</a></li>
|
||||
<li data-type="tab" data-tab-target="tab-media-create-photoset" data-media-mode="create-photoset" class="js-tab-show-gallery"><a href="#">Создать фотосет</a></li>
|
||||
<li data-type="tab" data-tab-target="tab-media-link"><a href="#">Вставить по ссылке</a></li>
|
||||
{if $aTargetParams.allow_preview}
|
||||
<li data-type="tab" data-tab-target="tab-media-preview"><a href="#">Превью</a></li>
|
||||
{/if}
|
||||
</ul>
|
||||
|
||||
{* Side navigation content *}
|
||||
|
@ -105,6 +108,15 @@
|
|||
<button type="button" class="button" data-type="modal-close">{$aLang.uploadimg_cancel}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{**
|
||||
* Фотосет
|
||||
*}
|
||||
<div id="tab-media-preview" data-type="tab-pane" class="tab-pane modal-upload-image-pane">
|
||||
<div class="modal-content">
|
||||
ffff
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
|
|
Loading…
Reference in a new issue