2013-07-06 10:20:53 -07:00
|
|
|
|
(function (window, document, $) {
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
function refreshDirectoryBrowser(page, path, fileOptions) {
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2013-09-06 13:25:03 -07:00
|
|
|
|
if (path) {
|
|
|
|
|
$('.networkHeadline').hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.networkHeadline').show();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
var promise;
|
|
|
|
|
|
2014-01-01 11:26:31 -07:00
|
|
|
|
var parentPathPromise = null;
|
|
|
|
|
|
2013-09-06 13:25:03 -07:00
|
|
|
|
if (path === "Network") {
|
|
|
|
|
promise = ApiClient.getNetworkDevices();
|
|
|
|
|
}
|
|
|
|
|
else if (path) {
|
2013-10-21 07:21:32 -07:00
|
|
|
|
promise = ApiClient.getDirectoryContents(path, fileOptions);
|
2014-01-01 11:26:31 -07:00
|
|
|
|
parentPathPromise = ApiClient.getParentPath(path);
|
2013-07-06 10:20:53 -07:00
|
|
|
|
} else {
|
|
|
|
|
promise = ApiClient.getDrives();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-01 11:26:31 -07:00
|
|
|
|
if (!parentPathPromise) {
|
|
|
|
|
parentPathPromise = $.Deferred();
|
|
|
|
|
parentPathPromise.resolveWith(null, []);
|
|
|
|
|
parentPathPromise = parentPathPromise.promise();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.when(promise, parentPathPromise).done(function (response1, response2) {
|
|
|
|
|
|
|
|
|
|
var folders = response1[0];
|
|
|
|
|
var parentPath = response2 && response2.length ? response2[0] || '' : '';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
|
|
|
|
$('#txtDirectoryPickerPath', page).val(path || "");
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
if (path) {
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
html += '<li><a class="lnkPath lnkDirectory" data-path="' + parentPath + '" href="#">..</a></li>';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = folders.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var folder = folders[i];
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
var cssClass = folder.Type == "File" ? "lnkPath lnkFile" : "lnkPath lnkDirectory";
|
|
|
|
|
|
2014-01-01 11:26:31 -07:00
|
|
|
|
html += '<li><a class="' + cssClass + '" data-type="' + folder.Type + '" data-path="' + folder.Path + '" href="#">' + folder.Name + '</a></li>';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 13:25:03 -07:00
|
|
|
|
if (!path) {
|
2014-06-24 14:45:21 -07:00
|
|
|
|
html += '<li><a class="lnkPath lnkDirectory" data-path="Network" href="#">' + Globalize.translate('ButtonNetwork') + '</a></li>';
|
2013-09-06 13:25:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
$('#ulDirectoryPickerList', page).html(html).listview('refresh');
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
|
|
|
|
|
$('#txtDirectoryPickerPath', page).val("");
|
|
|
|
|
$('#ulDirectoryPickerList', page).html('').listview('refresh');
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
|
|
|
|
window.DirectoryBrowser = function (page) {
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.show = function (options) {
|
|
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
var fileOptions = {
|
2013-10-21 07:22:21 -07:00
|
|
|
|
includeDirectories: true
|
2013-10-21 07:21:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (options.includeDirectories != null) {
|
|
|
|
|
fileOptions.includeDirectories = options.includeDirectories;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.includeFiles != null) {
|
|
|
|
|
fileOptions.includeFiles = options.includeFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-23 21:50:45 -07:00
|
|
|
|
options.header = options.header || Globalize.translate('HeaderSelectPath');
|
2014-01-29 22:20:18 -07:00
|
|
|
|
options.instruction = options.instruction || "";
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2014-06-28 12:35:30 -07:00
|
|
|
|
var html = '<div data-role="popup" id="popupDirectoryPicker" class="popup" style="min-width:65%;">';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
2013-12-24 11:37:29 -07:00
|
|
|
|
html += '<div class="ui-bar-a" style="text-align: center; padding: 0 20px;">';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
html += '<h3>' + options.header + '</h3>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2013-12-24 11:37:29 -07:00
|
|
|
|
html += '<div data-role="content" class="ui-content">';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
html += '<form>';
|
|
|
|
|
|
2014-01-29 22:20:18 -07:00
|
|
|
|
var instruction = options.instruction ? options.instruction + '<br/><br/>' : '';
|
2014-06-24 14:45:21 -07:00
|
|
|
|
|
|
|
|
|
html += '<p class="directoryPickerHeadline">';
|
|
|
|
|
html += instruction;
|
|
|
|
|
html += Globalize.translate('MessageDirectoryPickerInstruction')
|
|
|
|
|
.replace('{0}', '<b>\\\\server</b>')
|
|
|
|
|
.replace('{1}', '<b>\\\\192.168.1.101</b>');
|
|
|
|
|
html += '</p>';
|
2014-01-29 22:20:18 -07:00
|
|
|
|
|
|
|
|
|
html += '<div style="margin:20px 0 0;">';
|
2014-06-24 14:45:21 -07:00
|
|
|
|
html += '<label for="txtDirectoryPickerPath" class="lblDirectoryPickerPath">' + Globalize.translate('LabelCurrentPath') + '</label>';
|
2014-07-07 18:41:03 -07:00
|
|
|
|
html += '<div style="width:82%;display:inline-block;"><input id="txtDirectoryPickerPath" name="txtDirectoryPickerPath" type="text" required="required" style="font-weight:bold;" /></div>';
|
2014-06-24 14:45:21 -07:00
|
|
|
|
html += '<button class="btnRefreshDirectories" type="button" data-icon="refresh" data-inline="true" data-mini="true" data-iconpos="notext">' + Globalize.translate('ButtonRefresh') + '</button>';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2014-07-07 18:41:03 -07:00
|
|
|
|
html += '<div style="height: 180px; overflow-y: auto;">';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
html += '<ul id="ulDirectoryPickerList" data-role="listview" data-inset="true" data-auto-enhanced="false"></ul>';
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
html += '</div>';
|
2013-10-21 07:21:32 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
|
|
|
|
html += '<p>';
|
2014-06-24 14:45:21 -07:00
|
|
|
|
html += '<button type="submit" data-theme="b" data-icon="check" data-mini="true">' + Globalize.translate('ButtonOk') + '</button>';
|
|
|
|
|
html += '<button type="button" data-icon="delete" onclick="$(this).parents(\'.popup\').popup(\'close\');" data-mini="true">' + Globalize.translate('ButtonCancel') + '</button>';
|
2013-07-06 10:20:53 -07:00
|
|
|
|
html += '</p>';
|
|
|
|
|
html += '</form>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
$(page).append(html);
|
|
|
|
|
|
|
|
|
|
var popup = $('#popupDirectoryPicker').popup().trigger('create').on("popupafteropen", function () {
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
$('#popupDirectoryPicker input:first', this).focus();
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
}).popup("open").on("popupafterclose", function () {
|
|
|
|
|
|
|
|
|
|
$('form', this).off("submit");
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
$(this).off("click").off("change").off("popupafterclose").remove();
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
}).on("click", ".lnkPath", function () {
|
2013-07-06 10:20:53 -07:00
|
|
|
|
|
|
|
|
|
var path = this.getAttribute('data-path');
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
if ($(this).hasClass('lnkFile')) {
|
|
|
|
|
$('#txtDirectoryPickerPath', page).val(path);
|
|
|
|
|
} else {
|
|
|
|
|
refreshDirectoryBrowser(page, path, fileOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 13:25:03 -07:00
|
|
|
|
|
2013-09-08 06:38:52 -07:00
|
|
|
|
}).on("click", ".btnRefreshDirectories", function () {
|
|
|
|
|
|
|
|
|
|
var path = $('#txtDirectoryPickerPath', page).val();
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
refreshDirectoryBrowser(page, path, fileOptions);
|
2013-09-08 06:38:52 -07:00
|
|
|
|
|
2013-07-06 10:20:53 -07:00
|
|
|
|
}).on("change", "#txtDirectoryPickerPath", function () {
|
|
|
|
|
|
2013-10-21 07:21:32 -07:00
|
|
|
|
refreshDirectoryBrowser(page, this.value, fileOptions);
|
2013-07-06 10:20:53 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var txtCurrentPath = $('#txtDirectoryPickerPath', popup);
|
|
|
|
|
|
|
|
|
|
if (options.path) {
|
|
|
|
|
txtCurrentPath.val(options.path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('form', popup).on('submit', function () {
|
|
|
|
|
|
|
|
|
|
if (options.callback) {
|
|
|
|
|
options.callback($('#txtDirectoryPickerPath', this).val());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
refreshDirectoryBrowser(page, txtCurrentPath.val());
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-06 13:25:03 -07:00
|
|
|
|
self.close = function () {
|
2013-07-06 10:20:53 -07:00
|
|
|
|
$('#popupDirectoryPicker', page).popup("close");
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})(window, document, jQuery);
|