shortcutCreator.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="mobile-web-app-capable" content="yes">
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script src="../../script/jquery.min.js"></script>
  9. <script src="../../script/semantic/semantic.min.js"></script>
  10. <script src="../../script/ao_module.js"></script>
  11. <style>
  12. .hidden{
  13. display:none;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <br>
  19. <div class="ui container">
  20. <div class="ui ordered fluid steps">
  21. <div id="stepOneState" class="active step">
  22. <div class="content">
  23. <div class="title">Select Type</div>
  24. <div class="description">Choose a shortcut type</div>
  25. </div>
  26. </div>
  27. <div id="stepTwoState" class="step">
  28. <div class="content">
  29. <div class="title">Select Path</div>
  30. <div class="description">Fill shortcut target path</div>
  31. </div>
  32. </div>
  33. <div id="stepThreeState" class="step">
  34. <div class="content">
  35. <div class="title">Create</div>
  36. <div class="description">Generate shortcut</div>
  37. </div>
  38. </div>
  39. </div>
  40. <div id="stepOne" class="ui segment">
  41. <p>Select a type of shortcut you want to create:</p>
  42. <div class="ui selection fluid dropdown">
  43. <input id="selectType" type="hidden" onchange="updateDesc();">
  44. <i class="dropdown icon"></i>
  45. <div class="default text">Shortcut Type</div>
  46. <div class="menu">
  47. <div class="item" data-value="0">WebApp Module</div>
  48. <div class="item" data-value="1">Folder / Directory</div>
  49. <div class="item" data-value="2">Website URL</div>
  50. </div>
  51. </div>
  52. <div id="typeExplain" class="ui segment" style="display:none;">
  53. <div class="ui feed">
  54. <div class="event">
  55. <div class="label">
  56. <img id="typeIcon" src="">
  57. </div>
  58. <div class="content">
  59. <div id="typeName" class="summary">
  60. </div>
  61. <div id="typeExplainText" class="extra text">
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <br>
  68. <button class="ui primary button" onclick="moveToStepTwo();">
  69. Next
  70. </button>
  71. </button>
  72. <button class="ui button">
  73. Cancel
  74. </button>
  75. </div>
  76. <div id="stepTwoModule" class="ui segment stageTwo hidden">
  77. <p>Select a module to create the shortcut</p>
  78. <select id="moduleList" class="ui search fluid dropdown" onchange="updateModuleInfo(this.value);">
  79. <option value="">Select WebApp Module</option>
  80. </select>
  81. <small id="moduleInfo"></small>
  82. <br><br>
  83. <button class="ui primary button" onclick="createModuleShortcut();">
  84. Next
  85. </button>
  86. </button>
  87. <button class="ui button" onclick="backToStepOne();">
  88. Back
  89. </button>
  90. </div>
  91. <div id="stepTwoFolder" class="ui segment stageTwo hidden">
  92. <p>Open or Enter a valid path for folder shortcut</p>
  93. <div class="ui corner fluid labeled input">
  94. <input id="shortcutname" type="text" placeholder="Folder Shortcut Name" value="Folder Shortcut">
  95. </div>
  96. <br>
  97. <div class="ui action fluid input">
  98. <input id="folderpath" type="text" value="" placeholder="e.g. user:/Desktop">
  99. <button class="ui teal right labeled icon button" onclick="selectTargetFolder();">
  100. <i class="folder open icon"></i>
  101. Open
  102. </button>
  103. </div>
  104. <br><br>
  105. <button class="ui primary button" onclick="createFolderShortcut();">
  106. Next
  107. </button>
  108. </button>
  109. <button class="ui button" onclick="backToStepOne();">
  110. Back
  111. </button>
  112. </div>
  113. <div id="stepTwoURL" class="ui segment stageTwo hidden">
  114. <p>Enter the shortcut name in the input below</p>
  115. <div class="ui corner fluid labeled input">
  116. <input id="urlshortcutname" type="text" placeholder="Website Name" value="My Website">
  117. </div>
  118. <br>
  119. <p>Enter the target URL in the input below (including http:// or https://)</p>
  120. <div class="ui icon fluid input">
  121. <input id="urlShortcut" type="text" placeholder="Website URL">
  122. <i class="globe icon"></i>
  123. </div>
  124. <br>
  125. <p>Enter the shortcut icon for desktop / floatWindow icon</p>
  126. <div class="ui icon fluid input">
  127. <input id="urlShortcutImage" type="text" placeholder="Shortcut Logo" value="">
  128. <i class="image icon"></i>
  129. </div>
  130. <br>
  131. <br><br>
  132. <button class="ui primary button" onclick="createURLShortcut();">
  133. Next
  134. </button>
  135. </button>
  136. <button class="ui button" onclick="backToStepOne();">
  137. Back
  138. </button>
  139. </div>
  140. <div id="stepThree" class="ui segment hidden">
  141. <br>
  142. <div style="width:100%;" align="center">
  143. <h2 class="ui icon header">
  144. <i class="green checkmark icon"></i>
  145. <div class="content">
  146. Shortcut Created
  147. <div class="sub header">Your shortcut has been created. You can now close this windows.</div>
  148. </div>
  149. </h2>
  150. </div>
  151. <br>
  152. <button class="ui positive button right floated" onclick="ao_module_close();">
  153. OK
  154. </button>
  155. <br><br>
  156. </div>
  157. <div id="stepThreeCrashed" class="ui segment hidden">
  158. <br>
  159. <div style="width:100%;" align="center">
  160. <h2 class="ui icon header">
  161. <i class="red remove icon"></i>
  162. <div class="content">
  163. Shortcut Creation Failed
  164. <div class="sub header" id="errmsg">Unable to create shortcut. Please try again later.</div>
  165. </div>
  166. </h2>
  167. </div>
  168. <br>
  169. <button class="ui negative button right floated" onclick="ao_module_close();">
  170. Exit
  171. </button>
  172. <br><br>
  173. </div>
  174. </div>
  175. <script>
  176. initModuleList();
  177. function initModuleList(){
  178. $.get("../../system/modules/list",function(data){
  179. if (data.error !== undefined){
  180. alert(data.error);
  181. }else{
  182. for (var i = 0 ;i < data.length; i++){
  183. var thisModule = data[i];
  184. if (thisModule.StartDir != ""){
  185. var moduleInfoEncoded = encodeURIComponent(JSON.stringify(thisModule));
  186. $("#moduleList").append(`<option value="${moduleInfoEncoded}">${thisModule.Name}</option>`);
  187. }
  188. }
  189. $('.ui.dropdown').dropdown();
  190. }
  191. });
  192. }
  193. function updateModuleInfo(moduleInfo){
  194. moduleInfo = JSON.parse(decodeURIComponent(moduleInfo));
  195. $("#moduleInfo").html(`
  196. <img class="ui avatar image" src="../../${moduleInfo.IconPath}">
  197. <span>${moduleInfo.StartDir} (version: ${moduleInfo.Version})</span>`);
  198. }
  199. function createModuleShortcut(){
  200. var moduleInfo = JSON.parse(decodeURIComponent($("#moduleList").val()));
  201. //Use the startup path for embeded > fw > default
  202. var moduleIcon = moduleInfo.IconPath;
  203. var moduleIconDir = moduleIcon.split("/");
  204. moduleIconDir.pop();
  205. moduleIconDir.join("/");
  206. if (imageExists("../../" + moduleIconDir + "desktop_icon.png")){
  207. moduleIcon = moduleIconDir + "desktop_icon.png";
  208. }
  209. generateShortcutFile("module",moduleInfo.Name, moduleInfo.Name, moduleIcon);
  210. $(".stageTwo").slideUp();
  211. $("#stepTwoState").addClass("completed");
  212. $("#stepThree").slideDown();
  213. }
  214. function backToStepOne(){
  215. $("#stepTwoState").removeClass("completed");
  216. $(".stageTwo").slideUp();
  217. $("#stepOne").slideDown();
  218. }
  219. function generateShortcutFile(shortcutType, shortcutText, shortCutPath, shortcutIcon){
  220. //Generate the shortcut file object
  221. $.ajax({
  222. url: "../../system/desktop/createShortcut",
  223. data: {"stype": shortcutType, "stext": shortcutText, "spath": shortCutPath, "sicon":shortcutIcon },
  224. method: "POST",
  225. success: function(data){
  226. if (data.error !== undefined){
  227. $("#errmsg").text(data.error);
  228. $("#stepThreeCrashed").slideDown();
  229. $("#stepThree").hide();
  230. }else{
  231. console.log(data);
  232. //Refresh desktop
  233. parent.refresh();
  234. }
  235. }
  236. })
  237. }
  238. function imageExists(image_url){
  239. var http = new XMLHttpRequest();
  240. http.open('HEAD', image_url, false);
  241. http.send();
  242. return http.status != 404;
  243. }
  244. function createURLShortcut(){
  245. var url = $("#urlShortcut").val();
  246. var shortcutname = $("#urlshortcutname").val();
  247. if (url == ""){
  248. return;
  249. }
  250. var urlchunk = url.split("/");
  251. var iconpath = urlchunk[0] + "//" + urlchunk[2] + "/favicon.ico";
  252. if ($("#urlShortcutImage").val() != ""){
  253. iconpath = $("#urlShortcutImage").val().trim();
  254. }
  255. generateShortcutFile("url",shortcutname, url, iconpath);
  256. $(".stageTwo").slideUp();
  257. $("#stepTwoState").addClass("completed");
  258. $("#stepThree").slideDown();
  259. }
  260. function moveToStepTwo(){
  261. var selection = $("#selectType").val();
  262. if (selection == "0"){
  263. $("#stepTwoModule").slideDown();
  264. }else if (selection == "1"){
  265. $("#stepTwoFolder").slideDown();
  266. }else if (selection == "2"){
  267. $("#stepTwoURL").slideDown();
  268. }else{
  269. return;
  270. }
  271. $("#stepOneState").addClass("completed");
  272. $("#stepOne").slideUp();
  273. }
  274. function selectTargetFolder(){
  275. ao_module_openFileSelector(fileSelected, "user:/Desktop", "folder",true);
  276. }
  277. function fileSelected(filedata){
  278. console.log(filedata);
  279. for (var i=0; i < filedata.length; i++){
  280. var filename = filedata[i].filename;
  281. var filepath = filedata[i].filepath;
  282. $("#folderpath").val(filepath);
  283. //Filter / and : from the filename
  284. filename = filename.split(":").join("")
  285. filename = filename.split("/").join("")
  286. $("#shortcutname").val(filename);
  287. }
  288. }
  289. function createFolderShortcut(){
  290. var folderpath = $("#folderpath").val();
  291. var shortcutname = $("#shortcutname").val();
  292. if (folderpath == ""){
  293. return;
  294. }
  295. if (shortcutname == ""){
  296. shortcutname = folderpath.split("/").pop();
  297. if (shortcutname == ""){
  298. shortcutname = folderpath.split("/")[0];
  299. }
  300. }
  301. generateShortcutFile("folder",shortcutname, folderpath,"img/system/folder-shortcut.png");
  302. $(".stageTwo").slideUp();
  303. $("#stepTwoState").addClass("completed");
  304. $("#stepThree").slideDown();
  305. }
  306. function updateDesc(){
  307. var selection = $("#selectType").val();
  308. var src = "";
  309. var typeName = "";
  310. var typeDesc = "";
  311. if (selection == "0"){
  312. src = "img/a-module.png";
  313. typeName = "WebApp Modules";
  314. typeDesc = "The webapp / modules loaded onto the ArOZ Online System. You can start the module by double clicking the shortcut or drag files onto it on Desktop.";
  315. }else if (selection == "1"){
  316. src = "img/Directory.png";
  317. typeName = "Directory";
  318. typeDesc = "A folder shortcut that redirect you to another folder when launched.";
  319. }else if (selection == "2"){
  320. src = "img/Weburl.png";
  321. typeName = "Web URL";
  322. typeDesc = "A website or web resources that can be opened via double click.";
  323. }
  324. $("#typeIcon").attr('src', src);
  325. $("#typeName").text(typeName);
  326. $("#typeExplainText").text(typeDesc);
  327. $("#typeExplain").hide().slideDown();
  328. }
  329. </script>
  330. </body>
  331. </html>