2013-02-20 18:33:05 -07:00
|
|
|
|
var MediaLibraryPage = {
|
|
|
|
|
|
2014-10-29 15:01:02 -07:00
|
|
|
|
onPageInit: function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
2014-11-10 20:41:19 -07:00
|
|
|
|
$('#selectCollectionType', page).on('change', function () {
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
|
|
|
|
var index = this.selectedIndex;
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
|
|
|
|
|
var name = this.options[index].innerHTML
|
|
|
|
|
.replace('*', '')
|
|
|
|
|
.replace('&', '&');
|
|
|
|
|
|
|
|
|
|
$('#txtValue', page).val(name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
onPageShow: function () {
|
|
|
|
|
|
2013-12-25 20:44:26 -07:00
|
|
|
|
var page = this;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
MediaLibraryPage.lastVirtualFolderName = "";
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
MediaLibraryPage.reloadLibrary(page);
|
2013-12-25 20:44:26 -07:00
|
|
|
|
},
|
2014-07-10 21:27:46 -07:00
|
|
|
|
|
2013-04-16 21:21:24 -07:00
|
|
|
|
reloadLibrary: function (page) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
ApiClient.getVirtualFolders().done(function (result) {
|
|
|
|
|
MediaLibraryPage.reloadVirtualFolders(page, result);
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
$('#divMediaLibrary', page).show();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
shouldRefreshLibraryAfterChanges: function () {
|
2013-12-01 13:17:40 -07:00
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
return $($.mobile.activePage).is('#mediaLibraryPage');
|
|
|
|
|
},
|
|
|
|
|
|
2013-04-16 21:21:24 -07:00
|
|
|
|
reloadVirtualFolders: function (page, virtualFolders) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
if (virtualFolders) {
|
|
|
|
|
MediaLibraryPage.virtualFolders = virtualFolders;
|
|
|
|
|
} else {
|
|
|
|
|
virtualFolders = MediaLibraryPage.virtualFolders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2014-01-30 14:23:54 -07:00
|
|
|
|
var addPathMappingInfo = $(page).is('#mediaLibraryPage');
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
for (var i = 0, length = virtualFolders.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var virtualFolder = virtualFolders[i];
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
var isCollapsed = MediaLibraryPage.lastVirtualFolderName != virtualFolder.Name;
|
|
|
|
|
|
2014-01-30 14:23:54 -07:00
|
|
|
|
|
|
|
|
|
html += MediaLibraryPage.getVirtualFolderHtml(virtualFolder, isCollapsed, i, addPathMappingInfo);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#divVirtualFolders', page).html(html).trigger('create');
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
},
|
|
|
|
|
|
2013-12-01 13:17:40 -07:00
|
|
|
|
changeCollectionType: function () {
|
|
|
|
|
|
2013-12-26 19:23:57 -07:00
|
|
|
|
Dashboard.alert({
|
2014-07-16 20:17:14 -07:00
|
|
|
|
message: Globalize.translate('HeaderChangeFolderTypeHelp'),
|
|
|
|
|
title: Globalize.translate('HeaderChangeFolderType')
|
2013-12-26 19:23:57 -07:00
|
|
|
|
});
|
2013-12-01 13:17:40 -07:00
|
|
|
|
},
|
|
|
|
|
|
2014-01-30 14:23:54 -07:00
|
|
|
|
getVirtualFolderHtml: function (virtualFolder, isCollapsed, index, addPathMappingInfo) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
isCollapsed = isCollapsed ? "true" : "false";
|
2013-12-24 11:37:29 -07:00
|
|
|
|
var html = '<div class="collapsibleVirtualFolder" data-mini="true" data-role="collapsible" data-collapsed="' + isCollapsed + '">';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
html += '<h3>' + virtualFolder.Name + '</h3>';
|
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
var typeName = MediaLibraryPage.getCollectionTypeOptions().filter(function (t) {
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
|
|
|
|
return t.value == virtualFolder.CollectionType;
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
typeName = typeName ? typeName.name : Globalize.translate('FolderTypeMixed');
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
html += '<p style="padding-left:.5em;">';
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
2014-11-10 20:41:19 -07:00
|
|
|
|
html += Globalize.translate('LabelFolderTypeValue').replace('{0}', '<b>' + typeName + '</b>');
|
|
|
|
|
html += '</p><ul class="mediaFolderLocations" data-inset="true" data-role="listview" data-split-icon="minus">';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
html += '<li data-role="list-divider" class="mediaLocationsHeader">' + Globalize.translate('HeaderMediaLocations');
|
2014-11-10 20:41:19 -07:00
|
|
|
|
html += '<button type="button" data-icon="plus" data-mini="true" data-iconpos="notext" data-inline="true" onclick="MediaLibraryPage.addMediaLocation(' + index + ');">' + Globalize.translate('ButtonAdd') + '</button>';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
html += '</li>';
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = virtualFolder.Locations.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var location = virtualFolder.Locations[i];
|
|
|
|
|
html += '<li>';
|
2014-02-20 22:04:11 -07:00
|
|
|
|
html += '<a style="font-size:14px;" class="lnkMediaLocation" href="#">' + location + '</a>';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
html += '<a href="#" data-index="' + i + '" data-folderindex="' + index + '" onclick="MediaLibraryPage.deleteMediaLocation(this);"></a>';
|
|
|
|
|
html += '</li>';
|
|
|
|
|
}
|
|
|
|
|
html += '</ul>';
|
|
|
|
|
|
2014-01-30 14:23:54 -07:00
|
|
|
|
if (addPathMappingInfo) {
|
2014-11-04 05:41:12 -07:00
|
|
|
|
html += '<div class="fieldDescription" style="margin:.5em 0 1.5em;">' + Globalize.translate('LabelPathSubstitutionHelp') + '</div>';
|
2014-01-30 14:23:54 -07:00
|
|
|
|
}
|
2014-01-29 22:20:18 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
html += '<p>';
|
2014-11-10 20:41:19 -07:00
|
|
|
|
html += '<button type="button" data-inline="true" data-icon="minus" data-folderindex="' + index + '" onclick="MediaLibraryPage.deleteVirtualFolder(this);" data-mini="true">' + Globalize.translate('ButtonRemove') + '</button>';
|
|
|
|
|
html += '<button type="button" data-inline="true" data-icon="edit" data-folderindex="' + index + '" onclick="MediaLibraryPage.renameVirtualFolder(this);" data-mini="true">' + Globalize.translate('ButtonRename') + '</button>';
|
|
|
|
|
html += '<button type="button" data-inline="true" data-icon="edit" data-folderindex="' + index + '" onclick="MediaLibraryPage.changeCollectionType(this);" data-mini="true">' + Globalize.translate('ButtonChangeType') + '</button>';
|
2013-02-20 18:33:05 -07:00
|
|
|
|
html += '</p>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
addVirtualFolder: function () {
|
|
|
|
|
|
2013-09-04 12:16:41 -07:00
|
|
|
|
$('.collectionTypeFieldDescription').show();
|
|
|
|
|
|
2014-10-29 15:01:02 -07:00
|
|
|
|
MediaLibraryPage.getTextValue(Globalize.translate('HeaderAddMediaFolder'), Globalize.translate('LabelName'), "", true, function (name, type) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
MediaLibraryPage.lastVirtualFolderName = name;
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
|
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
ApiClient.addVirtualFolder(name, type, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
addMediaLocation: function (virtualFolderIndex) {
|
|
|
|
|
|
|
|
|
|
MediaLibraryPage.selectDirectory(function (path) {
|
|
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
|
|
|
|
|
|
var virtualFolder = MediaLibraryPage.virtualFolders[virtualFolderIndex];
|
|
|
|
|
|
|
|
|
|
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
|
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
|
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
ApiClient.addMediaPath(virtualFolder.Name, path, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
selectDirectory: function (callback) {
|
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
var picker = new DirectoryBrowser($.mobile.activePage);
|
|
|
|
|
|
|
|
|
|
picker.show({ callback: callback });
|
|
|
|
|
|
|
|
|
|
MediaLibraryPage.directoryPicker = picker;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-07-12 12:56:40 -07:00
|
|
|
|
getTextValue: function (header, label, initialValue, showCollectionType, callback) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
var popup = $('#popupEnterText', page);
|
|
|
|
|
|
|
|
|
|
$('h3', popup).html(header);
|
2013-07-12 12:56:40 -07:00
|
|
|
|
$('#lblValue', popup).html(label);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
$('#txtValue', popup).val(initialValue);
|
|
|
|
|
|
2013-07-12 12:56:40 -07:00
|
|
|
|
if (showCollectionType) {
|
|
|
|
|
$('#fldCollectionType', popup).show();
|
2013-10-18 12:47:57 -07:00
|
|
|
|
$('#selectCollectionType', popup).attr('required', 'required').selectmenu('refresh');
|
2013-07-12 12:56:40 -07:00
|
|
|
|
} else {
|
|
|
|
|
$('#fldCollectionType', popup).hide();
|
2013-10-18 12:47:57 -07:00
|
|
|
|
$('#selectCollectionType', popup).removeAttr('required').selectmenu('refresh');
|
2013-07-12 12:56:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 12:47:57 -07:00
|
|
|
|
$('#selectCollectionType', popup).html(MediaLibraryPage.getCollectionTypeOptionsHtml()).val('').selectmenu('refresh');
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
2014-10-29 15:01:02 -07:00
|
|
|
|
popup.on("popupafterclose", function () {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
$(this).off("popupafterclose").off("click");
|
|
|
|
|
$('#textEntryForm', this).off("submit");
|
2013-03-28 20:50:46 -07:00
|
|
|
|
}).popup("open");
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
$('#textEntryForm', popup).on('submit', function () {
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
|
|
|
|
if (showCollectionType) {
|
2013-10-18 12:47:57 -07:00
|
|
|
|
|
|
|
|
|
var collectionType = $('#selectCollectionType', popup).val();
|
2013-12-01 13:17:40 -07:00
|
|
|
|
|
2013-10-18 12:47:57 -07:00
|
|
|
|
// The server expects an empty value for mixed
|
|
|
|
|
if (collectionType == 'mixed') {
|
|
|
|
|
collectionType = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback($('#txtValue', popup).val(), collectionType);
|
2013-07-12 12:56:40 -07:00
|
|
|
|
} else {
|
|
|
|
|
callback($('#txtValue', popup).val());
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2013-07-12 12:56:40 -07:00
|
|
|
|
getCollectionTypeOptionsHtml: function () {
|
|
|
|
|
|
2013-12-01 13:17:40 -07:00
|
|
|
|
return MediaLibraryPage.getCollectionTypeOptions().filter(function (i) {
|
2013-10-26 15:01:21 -07:00
|
|
|
|
|
|
|
|
|
return i.isSelectable !== false;
|
|
|
|
|
|
|
|
|
|
}).map(function (i) {
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
|
|
|
|
return '<option value="' + i.value + '">' + i.name + '</option>';
|
|
|
|
|
|
|
|
|
|
}).join("");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getCollectionTypeOptions: function () {
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
2013-10-18 12:47:57 -07:00
|
|
|
|
{ name: "", value: "" },
|
2014-08-24 08:48:06 -07:00
|
|
|
|
{ name: Globalize.translate('FolderTypeMovies'), value: "movies" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeMusic'), value: "music" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeTvShows'), value: "tvshows" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeBooks') + '*', value: "books" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeGames') + '*', value: "games" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeHomeVideos'), value: "homevideos" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeMusicVideos'), value: "musicvideos" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypePhotos'), value: "photos" },
|
|
|
|
|
{ name: Globalize.translate('FolderTypeMixed'), value: "mixed" }
|
2013-07-12 12:56:40 -07:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
renameVirtualFolder: function (button) {
|
|
|
|
|
|
|
|
|
|
var folderIndex = button.getAttribute('data-folderindex');
|
|
|
|
|
var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex];
|
|
|
|
|
|
|
|
|
|
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-09-04 12:16:41 -07:00
|
|
|
|
$('.collectionTypeFieldDescription').hide();
|
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
MediaLibraryPage.getTextValue(Globalize.translate('HeaderRenameMediaFolder'), Globalize.translate('LabelNewName'), virtualFolder.Name, false, function (newName) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
if (virtualFolder.Name != newName) {
|
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
|
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteVirtualFolder: function (button) {
|
|
|
|
|
|
|
|
|
|
var folderIndex = button.getAttribute('data-folderindex');
|
|
|
|
|
var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex];
|
|
|
|
|
|
|
|
|
|
var parent = $(button).parents('.collapsibleVirtualFolder');
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
var locations = $('.lnkMediaLocation', parent).map(function () {
|
|
|
|
|
return this.innerHTML;
|
|
|
|
|
}).get();
|
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
var msg = Globalize.translate('MessageAreYouSureYouWishToRemoveMediaFolder');
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
if (locations.length) {
|
2014-11-10 20:41:19 -07:00
|
|
|
|
msg += "<br/><br/>" + Globalize.translate("MessageTheFollowingLocationWillBeRemovedFromLibrary") + "<br/><br/>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
msg += locations.join("<br/>");
|
|
|
|
|
}
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
Dashboard.confirm(msg, Globalize.translate('HeaderRemoveMediaFolder'), function (confirmResult) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
if (confirmResult) {
|
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
|
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteMediaLocation: function (button) {
|
|
|
|
|
|
|
|
|
|
var folderIndex = button.getAttribute('data-folderindex');
|
|
|
|
|
var index = parseInt(button.getAttribute('data-index'));
|
|
|
|
|
|
|
|
|
|
var virtualFolder = MediaLibraryPage.virtualFolders[folderIndex];
|
|
|
|
|
|
|
|
|
|
MediaLibraryPage.lastVirtualFolderName = virtualFolder.Name;
|
|
|
|
|
|
|
|
|
|
var location = virtualFolder.Locations[index];
|
|
|
|
|
|
2014-08-24 08:48:06 -07:00
|
|
|
|
Dashboard.confirm(Globalize.translate('MessageConfirmRemoveMediaLocation'), Globalize.translate('HeaderRemoveMediaLocation'), function (confirmResult) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
if (confirmResult) {
|
|
|
|
|
|
2013-09-05 10:05:39 -07:00
|
|
|
|
var refreshAfterChange = MediaLibraryPage.shouldRefreshLibraryAfterChanges();
|
|
|
|
|
|
2014-02-20 22:04:11 -07:00
|
|
|
|
ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).done(MediaLibraryPage.processOperationResult);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
processOperationResult: function (result) {
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
$('#popupEnterText', page).popup("close");
|
2013-07-12 12:56:40 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
if (MediaLibraryPage.directoryPicker) {
|
|
|
|
|
MediaLibraryPage.directoryPicker.close();
|
|
|
|
|
MediaLibraryPage.directoryPicker = null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 21:21:24 -07:00
|
|
|
|
MediaLibraryPage.reloadLibrary(page);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-29 15:01:02 -07:00
|
|
|
|
$(document).on('pageinit', ".mediaLibraryPage", MediaLibraryPage.onPageInit).on('pageshow', ".mediaLibraryPage", MediaLibraryPage.onPageShow);
|
2014-03-16 12:39:58 -07:00
|
|
|
|
|
2014-07-10 21:27:46 -07:00
|
|
|
|
var WizardLibraryPage = {
|
|
|
|
|
|
|
|
|
|
next: function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
var apiClient = ApiClient;
|
|
|
|
|
|
|
|
|
|
apiClient.ajax({
|
2014-07-10 21:27:46 -07:00
|
|
|
|
type: "POST",
|
2014-11-14 19:31:03 -07:00
|
|
|
|
url: apiClient.getUrl('System/Configuration/MetadataPlugins/Autoset')
|
2014-07-10 21:27:46 -07:00
|
|
|
|
|
|
|
|
|
}).done(function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
Dashboard.navigate('wizardsettings.html');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-16 12:39:58 -07:00
|
|
|
|
(function ($, document, window) {
|
|
|
|
|
|
|
|
|
|
function pollTasks(page) {
|
|
|
|
|
|
|
|
|
|
ApiClient.getScheduledTasks().done(function (tasks) {
|
|
|
|
|
|
|
|
|
|
updateTasks(page, tasks);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateTasks(page, tasks) {
|
|
|
|
|
|
|
|
|
|
$('.refreshLibraryPanel', page).removeClass('hide');
|
|
|
|
|
|
|
|
|
|
var task = tasks.filter(function (t) {
|
|
|
|
|
|
|
|
|
|
return t.Name == 'Scan media library';
|
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
$('.btnRefresh', page).buttonEnabled(task.State == 'Idle').attr('data-taskid', task.Id);
|
|
|
|
|
|
|
|
|
|
var progress = (task.CurrentProgressPercentage || 0).toFixed(1);
|
2014-03-16 15:08:23 -07:00
|
|
|
|
var progressElem = $('.refreshProgress', page).val(progress);
|
|
|
|
|
|
|
|
|
|
if (task.State == 'Running') {
|
|
|
|
|
progressElem.show();
|
|
|
|
|
} else {
|
|
|
|
|
progressElem.hide();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 12:39:58 -07:00
|
|
|
|
var lastResult = task.LastExecutionResult ? task.LastExecutionResult.Status : '';
|
|
|
|
|
|
|
|
|
|
if (lastResult == "Failed") {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
$('.lastRefreshResult', page).html('<span style="color:#FF0000;">' + Globalize.translate('LabelFailed') + '</span>');
|
2014-03-16 12:39:58 -07:00
|
|
|
|
}
|
|
|
|
|
else if (lastResult == "Cancelled") {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
$('.lastRefreshResult', page).html('<span style="color:#0026FF;">' + Globalize.translate('LabelCancelled') + '</span>');
|
2014-03-16 12:39:58 -07:00
|
|
|
|
}
|
|
|
|
|
else if (lastResult == "Aborted") {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
$('.lastRefreshResult', page).html('<span style="color:#FF0000;">' + Globalize.translate('LabelAbortedByServerShutdown') + '</span>');
|
2014-03-16 12:39:58 -07:00
|
|
|
|
} else {
|
|
|
|
|
$('.lastRefreshResult', page).html(lastResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onWebSocketMessage(e, msg) {
|
|
|
|
|
|
|
|
|
|
if (msg.MessageType == "ScheduledTasksInfo") {
|
|
|
|
|
|
|
|
|
|
var tasks = msg.Data;
|
|
|
|
|
|
|
|
|
|
var page = $.mobile.activePage;
|
|
|
|
|
|
|
|
|
|
updateTasks(page, tasks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pageinit', "#mediaLibraryPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.btnRefresh', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var button = this;
|
|
|
|
|
var id = button.getAttribute('data-taskid');
|
|
|
|
|
|
|
|
|
|
ApiClient.startScheduledTask(id).done(function () {
|
|
|
|
|
|
|
|
|
|
pollTasks(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#mediaLibraryPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.refreshLibraryPanel', page).addClass('hide');
|
|
|
|
|
|
|
|
|
|
pollTasks(page);
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
var apiClient = ApiClient;
|
|
|
|
|
|
|
|
|
|
if (apiClient.isWebSocketOpen()) {
|
|
|
|
|
apiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1000,1000");
|
2014-03-16 12:39:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
$(apiClient).on("websocketmessage", onWebSocketMessage).on('websocketopen', function () {
|
2014-03-16 12:39:58 -07:00
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
if (apiClient.isWebSocketOpen()) {
|
|
|
|
|
apiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1000,1000");
|
2014-03-16 12:39:58 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pagehide', "#mediaLibraryPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
var apiClient = ApiClient;
|
|
|
|
|
|
|
|
|
|
if (apiClient.isWebSocketOpen()) {
|
|
|
|
|
apiClient.sendWebSocketMessage("ScheduledTasksInfoStop");
|
2014-03-16 12:39:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
$(apiClient).off("websocketmessage", onWebSocketMessage);
|
2014-03-16 12:39:58 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, document, window);
|