| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <!DOCTYPE html>
- <html>
- <head>
- <title locale="title/title">Select an Application</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
- <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
- <script type="text/javascript" src="../../script/jquery.min.js"></script>
- <script type="text/javascript" src="../../script/ao_module.js"></script>
- <script type="text/javascript" src="../../script/applocale.js"></script>
- <link rel="stylesheet" href="dialog.css">
- <script type="text/javascript" src="js/dialog.js"></script>
- <style>
- .openerPrompt{
- color: var(--dlg_text);
- margin-bottom: 18px;
- word-break: break-all;
- }
- /* Padded rather than spaced in the markup so that the CJK locales,
- which wrap the name in brackets, do not gain a stray space */
- .openerPrompt .filename{
- font-weight: 600;
- padding: 0px 3px;
- }
- </style>
- </head>
- <body class="whiteTheme">
- <div class="dialog">
- <div class="dialogBody">
- <div class="openerPrompt">
- <span locale="message/select">Choose an application to open</span><span class="filename" id="targetFilename"></span><span locale="message/selectSuffix"></span>
- </div>
- <div class="dlgSectionLabel" locale="section/suggested">Suggested Applications</div>
- <div class="dlgList" id="suggestedList"></div>
- <div class="dlgDivider"></div>
- <div class="dlgListRow" id="showAllRow" onclick="toggleAllModules();">
- <div class="rowIcon"><i id="showAllIcon" class="caret right icon"></i></div>
- <div class="rowText"><div class="rowTitle" id="showAllLabel" locale="button/showAll">Other applications...</div></div>
- </div>
- <div class="dlgList" id="otherList" style="display:none;"></div>
- </div>
- <div class="dialogFooter">
- <button class="dlgBtn ghost" onclick="openDefaultOpenerSettings();" title="Default application settings">
- <i class="cog icon"></i> <span locale="button/settings">Default app settings</span>
- </button>
- <div class="spacer"></div>
- <button class="dlgBtn" onclick="ao_module_close();" locale="button/cancel">Cancel</button>
- <button id="confirmBtn" class="dlgBtn primary disabled" onclick="confirmSelection();" locale="button/confirm">Open</button>
- </div>
- </div>
- <script>
- /*
- defaultOpener.html
- Picks the WebApp that opens a file type. The list used to be a
- bordered scroll box with a "Show All" button underneath; it is
- now a plain list split into the apps that declare support for
- this extension and, behind one row, everything else.
- Confirming both stores the association and opens the file, which
- is what the old Confirm button did - the wording just says so now.
- */
- var targetFile = null;
- var targetExt = "";
- var showingAll = false;
- var moduleInfo = [];
- applocale.init("../locale/defaultOpener.json", function(){
- applocale.translate();
- initOpenerSelector();
- });
- dlgInitTheme();
- ao_module_setFixedWindowSize();
- function initOpenerSelector(){
- var loadedFiles = ao_module_loadInputFiles();
- targetFile = loadedFiles;
- if (targetFile != undefined && targetFile.length > 1){
- //Only the first file of a selection decides the association
- targetFile = targetFile[0];
- }
- if (targetFile == undefined || targetFile.filename == undefined){
- $("#suggestedList").html('<div class="dlgEmpty"><i class="file outline icon"></i><div>' +
- applocale.getString("message/nofile", "No file given") + "</div></div>");
- return;
- }
- targetExt = "." + targetFile.filename.split(".").pop();
- $("#targetFilename").text(targetFile.filename);
- loadModuleList();
- }
- function loadModuleList(){
- $.get("../../system/modules/list", function(data){
- moduleInfo = data;
- var suggested = "";
- var others = "";
- for (var i = 0; i < data.length; i++){
- var thisModule = data[i];
- var supportedExt = thisModule.SupportedExt;
- var row = renderModuleRow(thisModule);
- if (supportedExt != null && supportedExt.indexOf(targetExt) >= 0){
- suggested += row;
- }else{
- others += row;
- }
- }
- if (suggested == ""){
- //Nothing claims this extension: the full list is the
- //only useful thing to show, so open it straight away
- $("#suggestedList").html('<div class="dlgEmpty"><i class="folder open outline icon"></i><div>' +
- applocale.getString("message/nosuggestion", "No application registered for this file type") + "</div></div>");
- $("#otherList").html(others).show();
- showingAll = true;
- $("#showAllLabel").text(applocale.getString("button/showLess", "Hide other applications"));
- $("#showAllIcon").attr("class", "caret down icon");
- }else{
- $("#suggestedList").html(suggested);
- $("#otherList").html(others);
- }
- });
- }
- function renderModuleRow(thisModule){
- var moduleIcon = thisModule.IconPath;
- if (moduleIcon == ""){
- moduleIcon = "img/system/favicon.png";
- }
- return '<div class="dlgListRow" module="' + dlgEscape(thisModule.Name) + '" ' +
- 'onclick="selectThis(this);" ondblclick="selectThisAndConfirm(this);">' +
- '<div class="rowIcon"><img src="../../' + dlgEscape(moduleIcon) + '"></div>' +
- '<div class="rowText"><div class="rowTitle">' + dlgEscape(thisModule.Name) + "</div></div>" +
- '<div class="rowTick"><i class="check circle icon"></i></div>' +
- "</div>";
- }
- function toggleAllModules(){
- if (showingAll){
- showingAll = false;
- $("#otherList").slideUp("fast");
- $("#showAllLabel").text(applocale.getString("button/showAll", "Other applications..."));
- $("#showAllIcon").attr("class", "caret right icon");
- }else{
- showingAll = true;
- $("#otherList").slideDown("fast");
- $("#showAllLabel").text(applocale.getString("button/showLess", "Hide other applications"));
- $("#showAllIcon").attr("class", "caret down icon");
- }
- }
- function selectThis(object){
- $(".dlgListRow.selected").removeClass("selected");
- $(object).addClass("selected");
- $("#confirmBtn").removeClass("disabled");
- }
- function selectThisAndConfirm(object){
- selectThis(object);
- confirmSelection();
- }
- function getSelectedObjectLaunchInfo(moduleName){
- for (var i = 0; i < moduleInfo.length; i++){
- if (moduleInfo[i]["Name"] == moduleName){
- return moduleInfo[i];
- }
- }
- return undefined;
- }
- function openDefaultOpenerSettings(){
- ao_module_newfw({
- url: "SystemAO/modules/defaultOpener.html",
- width: 720,
- height: 560,
- appicon: "SystemAO/modules/img/small_icon.png",
- title: "Default Openers"
- });
- }
- function confirmSelection(){
- var targetModuleName = $(".dlgListRow.selected").attr("module");
- if (targetModuleName == undefined){
- return;
- }
- var launchInfo = getSelectedObjectLaunchInfo(targetModuleName);
- var openFilelist = [{
- filename: targetFile.filename,
- filepath: targetFile.filepath
- }];
- $.ajax({
- url: "../../system/modules/getDefault",
- data: {opr: "set", ext: targetExt, module: targetModuleName},
- success: function(data){
- if (data != undefined && data.error !== undefined){
- dlgToast(data.error);
- return;
- }
- if (!ao_module_hasParentCallback()){
- //Launched on its own: open the file with the app just picked
- if (ao_module_virtualDesktop){
- parent.openFileWithModule(launchInfo, openFilelist);
- ao_module_close();
- }else{
- window.location.href = "../../" + targetModuleName + "#" + encodeURIComponent(JSON.stringify(openFilelist));
- }
- }else{
- //Opened from the properties window: let it refresh
- ao_module_parentCallback("");
- ao_module_close();
- }
- },
- error: function(){
- dlgToast(applocale.getString("message/failed", "Unable to save the default application"));
- }
- });
- }
- </script>
- </body>
- </html>
|