defaultOpener.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title locale="title/title">Select an Application</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/ao_module.js"></script>
  10. <script type="text/javascript" src="../../script/applocale.js"></script>
  11. <link rel="stylesheet" href="dialog.css">
  12. <script type="text/javascript" src="js/dialog.js"></script>
  13. <style>
  14. .openerPrompt{
  15. color: var(--dlg_text);
  16. margin-bottom: 18px;
  17. word-break: break-all;
  18. }
  19. /* Padded rather than spaced in the markup so that the CJK locales,
  20. which wrap the name in brackets, do not gain a stray space */
  21. .openerPrompt .filename{
  22. font-weight: 600;
  23. padding: 0px 3px;
  24. }
  25. </style>
  26. </head>
  27. <body class="whiteTheme">
  28. <div class="dialog">
  29. <div class="dialogBody">
  30. <div class="openerPrompt">
  31. <span locale="message/select">Choose an application to open</span><span class="filename" id="targetFilename"></span><span locale="message/selectSuffix"></span>
  32. </div>
  33. <div class="dlgSectionLabel" locale="section/suggested">Suggested Applications</div>
  34. <div class="dlgList" id="suggestedList"></div>
  35. <div class="dlgDivider"></div>
  36. <div class="dlgListRow" id="showAllRow" onclick="toggleAllModules();">
  37. <div class="rowIcon"><i id="showAllIcon" class="caret right icon"></i></div>
  38. <div class="rowText"><div class="rowTitle" id="showAllLabel" locale="button/showAll">Other applications...</div></div>
  39. </div>
  40. <div class="dlgList" id="otherList" style="display:none;"></div>
  41. </div>
  42. <div class="dialogFooter">
  43. <button class="dlgBtn ghost" onclick="openDefaultOpenerSettings();" title="Default application settings">
  44. <i class="cog icon"></i> <span locale="button/settings">Default app settings</span>
  45. </button>
  46. <div class="spacer"></div>
  47. <button class="dlgBtn" onclick="ao_module_close();" locale="button/cancel">Cancel</button>
  48. <button id="confirmBtn" class="dlgBtn primary disabled" onclick="confirmSelection();" locale="button/confirm">Open</button>
  49. </div>
  50. </div>
  51. <script>
  52. /*
  53. defaultOpener.html
  54. Picks the WebApp that opens a file type. The list used to be a
  55. bordered scroll box with a "Show All" button underneath; it is
  56. now a plain list split into the apps that declare support for
  57. this extension and, behind one row, everything else.
  58. Confirming both stores the association and opens the file, which
  59. is what the old Confirm button did - the wording just says so now.
  60. */
  61. var targetFile = null;
  62. var targetExt = "";
  63. var showingAll = false;
  64. var moduleInfo = [];
  65. applocale.init("../locale/defaultOpener.json", function(){
  66. applocale.translate();
  67. initOpenerSelector();
  68. });
  69. dlgInitTheme();
  70. ao_module_setFixedWindowSize();
  71. function initOpenerSelector(){
  72. var loadedFiles = ao_module_loadInputFiles();
  73. targetFile = loadedFiles;
  74. if (targetFile != undefined && targetFile.length > 1){
  75. //Only the first file of a selection decides the association
  76. targetFile = targetFile[0];
  77. }
  78. if (targetFile == undefined || targetFile.filename == undefined){
  79. $("#suggestedList").html('<div class="dlgEmpty"><i class="file outline icon"></i><div>' +
  80. applocale.getString("message/nofile", "No file given") + "</div></div>");
  81. return;
  82. }
  83. targetExt = "." + targetFile.filename.split(".").pop();
  84. $("#targetFilename").text(targetFile.filename);
  85. loadModuleList();
  86. }
  87. function loadModuleList(){
  88. $.get("../../system/modules/list", function(data){
  89. moduleInfo = data;
  90. var suggested = "";
  91. var others = "";
  92. for (var i = 0; i < data.length; i++){
  93. var thisModule = data[i];
  94. var supportedExt = thisModule.SupportedExt;
  95. var row = renderModuleRow(thisModule);
  96. if (supportedExt != null && supportedExt.indexOf(targetExt) >= 0){
  97. suggested += row;
  98. }else{
  99. others += row;
  100. }
  101. }
  102. if (suggested == ""){
  103. //Nothing claims this extension: the full list is the
  104. //only useful thing to show, so open it straight away
  105. $("#suggestedList").html('<div class="dlgEmpty"><i class="folder open outline icon"></i><div>' +
  106. applocale.getString("message/nosuggestion", "No application registered for this file type") + "</div></div>");
  107. $("#otherList").html(others).show();
  108. showingAll = true;
  109. $("#showAllLabel").text(applocale.getString("button/showLess", "Hide other applications"));
  110. $("#showAllIcon").attr("class", "caret down icon");
  111. }else{
  112. $("#suggestedList").html(suggested);
  113. $("#otherList").html(others);
  114. }
  115. });
  116. }
  117. function renderModuleRow(thisModule){
  118. var moduleIcon = thisModule.IconPath;
  119. if (moduleIcon == ""){
  120. moduleIcon = "img/system/favicon.png";
  121. }
  122. return '<div class="dlgListRow" module="' + dlgEscape(thisModule.Name) + '" ' +
  123. 'onclick="selectThis(this);" ondblclick="selectThisAndConfirm(this);">' +
  124. '<div class="rowIcon"><img src="../../' + dlgEscape(moduleIcon) + '"></div>' +
  125. '<div class="rowText"><div class="rowTitle">' + dlgEscape(thisModule.Name) + "</div></div>" +
  126. '<div class="rowTick"><i class="check circle icon"></i></div>' +
  127. "</div>";
  128. }
  129. function toggleAllModules(){
  130. if (showingAll){
  131. showingAll = false;
  132. $("#otherList").slideUp("fast");
  133. $("#showAllLabel").text(applocale.getString("button/showAll", "Other applications..."));
  134. $("#showAllIcon").attr("class", "caret right icon");
  135. }else{
  136. showingAll = true;
  137. $("#otherList").slideDown("fast");
  138. $("#showAllLabel").text(applocale.getString("button/showLess", "Hide other applications"));
  139. $("#showAllIcon").attr("class", "caret down icon");
  140. }
  141. }
  142. function selectThis(object){
  143. $(".dlgListRow.selected").removeClass("selected");
  144. $(object).addClass("selected");
  145. $("#confirmBtn").removeClass("disabled");
  146. }
  147. function selectThisAndConfirm(object){
  148. selectThis(object);
  149. confirmSelection();
  150. }
  151. function getSelectedObjectLaunchInfo(moduleName){
  152. for (var i = 0; i < moduleInfo.length; i++){
  153. if (moduleInfo[i]["Name"] == moduleName){
  154. return moduleInfo[i];
  155. }
  156. }
  157. return undefined;
  158. }
  159. function openDefaultOpenerSettings(){
  160. ao_module_newfw({
  161. url: "SystemAO/modules/defaultOpener.html",
  162. width: 720,
  163. height: 560,
  164. appicon: "SystemAO/modules/img/small_icon.png",
  165. title: "Default Openers"
  166. });
  167. }
  168. function confirmSelection(){
  169. var targetModuleName = $(".dlgListRow.selected").attr("module");
  170. if (targetModuleName == undefined){
  171. return;
  172. }
  173. var launchInfo = getSelectedObjectLaunchInfo(targetModuleName);
  174. var openFilelist = [{
  175. filename: targetFile.filename,
  176. filepath: targetFile.filepath
  177. }];
  178. $.ajax({
  179. url: "../../system/modules/getDefault",
  180. data: {opr: "set", ext: targetExt, module: targetModuleName},
  181. success: function(data){
  182. if (data != undefined && data.error !== undefined){
  183. dlgToast(data.error);
  184. return;
  185. }
  186. if (!ao_module_hasParentCallback()){
  187. //Launched on its own: open the file with the app just picked
  188. if (ao_module_virtualDesktop){
  189. parent.openFileWithModule(launchInfo, openFilelist);
  190. ao_module_close();
  191. }else{
  192. window.location.href = "../../" + targetModuleName + "#" + encodeURIComponent(JSON.stringify(openFilelist));
  193. }
  194. }else{
  195. //Opened from the properties window: let it refresh
  196. ao_module_parentCallback("");
  197. ao_module_close();
  198. }
  199. },
  200. error: function(){
  201. dlgToast(applocale.getString("message/failed", "Unable to save the default application"));
  202. }
  203. });
  204. }
  205. </script>
  206. </body>
  207. </html>