{include file='mediaListItems'}
</ul>
</div>
+
+<div class="paginationBottom jsPagination"></div>
{include file='mediaListItems'}
</ul>
</div>
+
+<div class="paginationBottom jsPagination"></div>
'Core', 'Dictionary', 'Dom/ChangeListener', 'Dom/Traverse',
'Dom/Util', 'EventHandler', 'Language', 'List',
'Permission', 'Ui/Dialog', 'Ui/Notification', 'WoltLabSuite/Core/Controller/Clipboard',
- 'WoltLabSuite/Core/Media/Editor', 'WoltLabSuite/Core/Media/Upload', 'WoltLabSuite/Core/Media/Manager/Search', 'StringUtil'
+ 'WoltLabSuite/Core/Media/Editor', 'WoltLabSuite/Core/Media/Upload', 'WoltLabSuite/Core/Media/Manager/Search', 'StringUtil',
+ 'WoltLabSuite/Core/Ui/Pagination'
],
function(
Core, Dictionary, DomChangeListener, DomTraverse,
DomUtil, EventHandler, Language, List,
Permission, UiDialog, UiNotification, Clipboard,
- MediaEditor, MediaUpload, MediaManagerSearch, StringUtil
+ MediaEditor, MediaUpload, MediaManagerSearch, StringUtil,
+ UiPagination
)
{
"use strict";
this._id = 'mediaManager' + _mediaManagerCounter++;
this._listItems = new Dictionary();
this._media = new Dictionary();
- this._mediaCache = null;
this._mediaManagerMediaList = null;
this._search = null;
this._upload = null;
this._forceClipboard = false;
this._hadInitiallyMarkedItems = false;
+ this._pagination = null;
if (Permission.get('admin.content.cms.canManageMedia')) {
this._mediaEditor = new MediaEditor(this);
}
}
+ this._initPagination(~~data.returnValues.pageCount);
+
this._hadInitiallyMarkedItems = data.returnValues.hasMarkedItems;
},
var deleteAction = new WCF.Action.Delete('wcf\\data\\media\\MediaAction', '.mediaFile');
deleteAction._didTriggerEffect = function(element) {
- this.removeMedia(elData(element[0], 'object-id'), true);
+ this.removeMedia(elData(element[0], 'object-id'));
}.bind(this);
}
}
},
+ /**
+ * Initializes the dialog pagination.
+ *
+ * @param {integer} pageCount
+ * @param {integer} pageNo
+ */
+ _initPagination: function(pageCount, pageNo) {
+ if (pageNo === undefined) pageNo = 1;
+
+ if (pageCount > 1) {
+ var newPagination = elCreate('div');
+ newPagination.className = 'paginationBottom jsPagination';
+ DomUtil.replaceElement(elBySel('.jsPagination', UiDialog.getDialog(this).content), newPagination);
+
+ this._pagination = new UiPagination(newPagination, {
+ activePage: pageNo,
+ callbackSwitch: this._search.search.bind(this._search),
+ maxPage: pageCount
+ });
+ }
+ else if (this._pagination) {
+ elHide(this._pagination.getElement());
+ }
+ },
+
/**
* Removes all media clipboard checkboxes.
*/
* Removes a media file.
*
* @param {int} mediaId id of the removed media file
- * @param {boolean|undefined} checkCache media file will also be removed from the local cache if true
*/
- removeMedia: function(mediaId, checkCache) {
+ removeMedia: function(mediaId) {
if (this._listItems.has(mediaId)) {
// remove list item
try {
this._listItems.delete(mediaId);
this._media.delete(mediaId);
}
-
- if (checkCache && this._mediaCache && this._mediaCache.has(mediaId)) {
- this._mediaCache.delete(mediaId);
- }
},
/**
* Changes the displayed media to the previously displayed media.
*/
resetMedia: function() {
- if (this._mediaCache !== null) {
- this._setMedia(this._mediaCache);
-
- this._mediaCache = null;
-
- this._search.resetSearch();
- if (this._mediaCategorySelect) {
- this._mediaCategorySelect.value = 0;
- }
- }
+ // calling WoltLabSuite/Core/Media/Manager/Search.search() reloads the first page of the dialog
+ this._search.search();
},
/**
*
* @param {object} media media data
* @param {string} template
+ * @param {object} additionalData
*/
- setMedia: function(media, template) {
- if (!this._mediaCache) {
- this._mediaCache = this._media;
- }
-
+ setMedia: function(media, template, additionalData) {
var hasMedia = false;
for (var mediaId in media) {
if (objOwns(media, mediaId)) {
}
}
+ this._initPagination(additionalData.pageCount, additionalData.pageNo);
+
this._setMedia(media);
},
* @param {object} data response data
*/
_ajaxSuccess: function(data) {
- this._mediaManager.setMedia(data.returnValues.media || { }, data.returnValues.template || '');
+ this._mediaManager.setMedia(data.returnValues.media || { }, data.returnValues.template || '', {
+ pageCount: data.returnValues.pageCount || 0,
+ pageNo: data.returnValues.pageNo || 0
+ });
+
+ elByClass('dialogContent', this._mediaManager.getDialog())[0].scrollTop = 0;
},
/**
if (this._searchMode) {
this._searchMode = false;
- this._mediaManager.resetMedia();
this.resetSearch();
+ this._mediaManager.resetMedia();
}
},
/**
* Sends an AJAX request to fetch search results.
+ *
+ * @param {integer} pageNo
*/
- search: function() {
+ search: function(pageNo) {
+ if (typeof pageNo !== "number") {
+ pageNo = 1;
+ }
+
var searchString = this._input.value;
if (searchString && this._input.value.length < this._mediaManager.getOption('minSearchLength')) {
this._showStringThresholdError();
categoryID: this._mediaManager.getCategoryId(),
imagesOnly: this._mediaManager.getOption('imagesOnly'),
mode: this._mediaManager.getMode(),
+ pageNo: pageNo,
searchString: searchString
}
});
imagesOnly: this._mediaManager.getOption('imagesOnly')
};
- if (this._categoryId) {
- parameters.categoryID = this._categoryId;
-
- this._categoryId = null;
+ var categoryId = this._mediaManager.getCategoryId();
+ if (categoryId) {
+ parameters.categoryID = categoryId;
}
return Core.extend(MediaUpload._super.prototype._getParameters.call(this), parameters);
* @see WoltLabSuite/Core/Upload#_uploadFiles
*/
_uploadFiles: function(files, blob) {
- // reset media (search) before uploading
- if (this._mediaManager) {
- this._categoryId = this._mediaManager.getCategoryId();
- this._mediaManager.resetMedia();
- }
-
return MediaUpload._super.prototype._uploadFiles.call(this, files, blob);
}
});
return listItem;
},
+ /**
+ * Returns the active page.
+ *
+ * @return {integer}
+ */
+ getActivePage: function() {
+ return this._options.activePage;
+ },
+
+ /**
+ * Returns the pagination Ui element.
+ *
+ * @return {HTMLElement}
+ */
+ getElement: function() {
+ return this._element;
+ },
+
+ /**
+ * Returns the maximum page.
+ *
+ * @return {integer}
+ */
+ getMaxPage: function() {
+ return this._options.maxPage;
+ },
+
/**
* Switches to given page number.
*
* @method MediaEditor getSingleObject()
*/
class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction, IUploadAction {
+ /**
+ * number of media files per media manager dialog page
+ */
+ const ITEMS_PER_MANAGER_DIALOG_PAGE = 50;
+
/**
* @inheritDoc
*/
if ($this->parameters['imagesOnly']) {
$mediaList->getConditionBuilder()->add('media.isImage = ?', [1]);
}
- $mediaList->sqlOrderBy = 'media.uploadTime DESC';
- $mediaList->sqlLimit = 50;
+ $mediaList->sqlOrderBy = 'media.uploadTime DESC, media.mediaID DESC';
+ $mediaList->sqlLimit = static::ITEMS_PER_MANAGER_DIALOG_PAGE;
$mediaList->readObjects();
$categoryList = (new CategoryNodeTree('com.woltlab.wcf.media.category'))->getIterator();
return [
'hasMarkedItems' => ClipboardHandler::getInstance()->hasMarkedItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.media')),
'media' => $this->getI18nMediaData($mediaList),
+ 'pageCount' => ceil($mediaList->countObjects() / static::ITEMS_PER_MANAGER_DIALOG_PAGE),
'template' => WCF::getTPL()->fetch('mediaManager', 'wcf', [
'categoryList' => $categoryList,
'mediaList' => $mediaList,
if ($this->parameters['mode'] != 'editor' && $this->parameters['mode'] != 'select') {
throw new UserInputException('mode');
}
+
+ $this->readInteger('pageNo', true);
+ if (!$this->parameters['pageNo']) $this->parameters['pageNo'] = 1;
}
/**
if ($this->parameters['categoryID']) {
$mediaList->getConditionBuilder()->add('media.categoryID = ?', [$this->parameters['categoryID']]);
}
- $mediaList->sqlOrderBy = 'media.uploadTime DESC';
- $mediaList->sqlLimit = 50;
+ $mediaList->sqlOrderBy = 'media.uploadTime DESC, media.mediaID DESC';
+ $mediaList->sqlLimit = static::ITEMS_PER_MANAGER_DIALOG_PAGE;
+ $mediaList->sqlOffset = ($this->parameters['pageNo'] - 1) * static::ITEMS_PER_MANAGER_DIALOG_PAGE;
$mediaList->readObjectIDs();
if (empty($mediaList->getObjectIDs())) {
+ // check if page is requested that might have existed but does not exist anymore due to deleted
+ // media files
+ if ($this->parameters['pageNo'] > 1 && $this->parameters['searchString'] === '' && !$this->parameters['categoryID']) {
+ // request media dialog page with highest page number
+ $parameters = $this->parameters;
+ $parameters['pageNo'] = ceil($mediaList->countObjects() / static::ITEMS_PER_MANAGER_DIALOG_PAGE);
+
+ return (new MediaAction($this->objects, 'getSearchResultList', $parameters))->executeAction()['returnValues'];
+ }
+
return [
'template' => WCF::getLanguage()->getDynamicVariable('wcf.media.search.noResults')
];
return [
'media' => $this->getI18nMediaData($viewableMediaList),
+ 'pageCount' => ceil($mediaList->countObjects() / static::ITEMS_PER_MANAGER_DIALOG_PAGE),
+ 'pageNo' => $this->parameters['pageNo'],
'template' => WCF::getTPL()->fetch('mediaListItems', 'wcf', [
'mediaList' => $viewableMediaList,
'mode' => $this->parameters['mode']