shortcutCreator.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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><br>
  125. <button class="ui primary button" onclick="createURLShortcut();">
  126. Next
  127. </button>
  128. </button>
  129. <button class="ui button" onclick="backToStepOne();">
  130. Back
  131. </button>
  132. </div>
  133. <div id="stepThree" class="ui segment hidden">
  134. <br>
  135. <div style="width:100%;" align="center">
  136. <h2 class="ui icon header">
  137. <i class="green checkmark icon"></i>
  138. <div class="content">
  139. Shortcut Created
  140. <div class="sub header">Your shortcut has been created. You can now close this windows.</div>
  141. </div>
  142. </h2>
  143. </div>
  144. <br>
  145. <button class="ui positive button right floated" onclick="ao_module_close();">
  146. OK
  147. </button>
  148. <br><br>
  149. </div>
  150. <div id="stepThreeCrashed" class="ui segment hidden">
  151. <br>
  152. <div style="width:100%;" align="center">
  153. <h2 class="ui icon header">
  154. <i class="red remove icon"></i>
  155. <div class="content">
  156. Shortcut Creation Failed
  157. <div class="sub header" id="errmsg">Unable to create shortcut. Please try again later.</div>
  158. </div>
  159. </h2>
  160. </div>
  161. <br>
  162. <button class="ui negative button right floated" onclick="ao_module_close();">
  163. Exit
  164. </button>
  165. <br><br>
  166. </div>
  167. </div>
  168. <script>
  169. initModuleList();
  170. function initModuleList(){
  171. $.get("../../system/modules/list",function(data){
  172. if (data.error !== undefined){
  173. alert(data.error);
  174. }else{
  175. for (var i = 0 ;i < data.length; i++){
  176. var thisModule = data[i];
  177. if (thisModule.StartDir != ""){
  178. var moduleInfoEncoded = encodeURIComponent(JSON.stringify(thisModule));
  179. $("#moduleList").append(`<option value="${moduleInfoEncoded}">${thisModule.Name}</option>`);
  180. }
  181. }
  182. $('.ui.dropdown').dropdown();
  183. }
  184. });
  185. }
  186. function updateModuleInfo(moduleInfo){
  187. moduleInfo = JSON.parse(decodeURIComponent(moduleInfo));
  188. $("#moduleInfo").html(`
  189. <img class="ui avatar image" src="../../${moduleInfo.IconPath}">
  190. <span>${moduleInfo.StartDir} (version: ${moduleInfo.Version})</span>`);
  191. }
  192. function createModuleShortcut(){
  193. var moduleInfo = JSON.parse(decodeURIComponent($("#moduleList").val()));
  194. //Use the startup path for embeded > fw > default
  195. var moduleIcon = moduleInfo.IconPath;
  196. var moduleIconDir = moduleIcon.split("/");
  197. moduleIconDir.pop();
  198. moduleIconDir.join("/");
  199. if (imageExists("../../" + moduleIconDir + "desktop_icon.png")){
  200. moduleIcon = moduleIconDir + "desktop_icon.png";
  201. }
  202. generateShortcutFile("module",moduleInfo.Name, moduleInfo.Name, moduleIcon);
  203. $(".stageTwo").slideUp();
  204. $("#stepTwoState").addClass("completed");
  205. $("#stepThree").slideDown();
  206. }
  207. function backToStepOne(){
  208. $("#stepTwoState").removeClass("completed");
  209. $(".stageTwo").slideUp();
  210. $("#stepOne").slideDown();
  211. }
  212. function generateShortcutFile(shortcutType, shortcutText, shortCutPath, shortcutIcon){
  213. //Generate the shortcut file object
  214. $.ajax({
  215. url: "../../system/desktop/createShortcut",
  216. data: {"stype": shortcutType, "stext": shortcutText, "spath": shortCutPath, "sicon":shortcutIcon },
  217. method: "POST",
  218. success: function(data){
  219. if (data.error !== undefined){
  220. $("#errmsg").text(data.error);
  221. $("#stepThreeCrashed").slideDown();
  222. $("#stepThree").hide();
  223. }else{
  224. console.log(data);
  225. //Refresh desktop
  226. parent.refresh();
  227. }
  228. }
  229. })
  230. }
  231. function imageExists(image_url){
  232. var http = new XMLHttpRequest();
  233. http.open('HEAD', image_url, false);
  234. http.send();
  235. return http.status != 404;
  236. }
  237. function createURLShortcut(){
  238. var url = $("#urlShortcut").val();
  239. var shortcutname = $("#urlshortcutname").val();
  240. if (url == ""){
  241. return;
  242. }
  243. var urlchunk = url.split("/");
  244. var iconpath = urlchunk[0] + "//" + urlchunk[2] + "/favicon.ico";
  245. generateShortcutFile("url",shortcutname, url, iconpath);
  246. $(".stageTwo").slideUp();
  247. $("#stepTwoState").addClass("completed");
  248. $("#stepThree").slideDown();
  249. }
  250. function moveToStepTwo(){
  251. var selection = $("#selectType").val();
  252. if (selection == "0"){
  253. $("#stepTwoModule").slideDown();
  254. }else if (selection == "1"){
  255. $("#stepTwoFolder").slideDown();
  256. }else if (selection == "2"){
  257. $("#stepTwoURL").slideDown();
  258. }else{
  259. return;
  260. }
  261. $("#stepOneState").addClass("completed");
  262. $("#stepOne").slideUp();
  263. }
  264. function selectTargetFolder(){
  265. ao_module_openFileSelector(fileSelected, "user:/Desktop", "folder",true);
  266. }
  267. function fileSelected(filedata){
  268. console.log(filedata);
  269. for (var i=0; i < filedata.length; i++){
  270. var filename = filedata[i].filename;
  271. var filepath = filedata[i].filepath;
  272. $("#folderpath").val(filepath);
  273. //Filter / and : from the filename
  274. filename = filename.split(":").join("")
  275. filename = filename.split("/").join("")
  276. $("#shortcutname").val(filename);
  277. }
  278. }
  279. function createFolderShortcut(){
  280. var folderpath = $("#folderpath").val();
  281. var shortcutname = $("#shortcutname").val();
  282. if (folderpath == ""){
  283. return;
  284. }
  285. if (shortcutname == ""){
  286. shortcutname = folderpath.split("/").pop();
  287. if (shortcutname == ""){
  288. shortcutname = folderpath.split("/")[0];
  289. }
  290. }
  291. generateShortcutFile("folder",shortcutname, folderpath,"img/system/folder-shortcut.png");
  292. $(".stageTwo").slideUp();
  293. $("#stepTwoState").addClass("completed");
  294. $("#stepThree").slideDown();
  295. }
  296. function updateDesc(){
  297. var selection = $("#selectType").val();
  298. var src = "";
  299. var typeName = "";
  300. var typeDesc = "";
  301. if (selection == "0"){
  302. src = "img/a-module.png";
  303. typeName = "WebApp Modules";
  304. 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.";
  305. }else if (selection == "1"){
  306. src = "img/Directory.png";
  307. typeName = "Directory";
  308. typeDesc = "A folder shortcut that redirect you to another folder when launched.";
  309. }else if (selection == "2"){
  310. src = "img/Weburl.png";
  311. typeName = "Web URL";
  312. typeDesc = "A website or web resources that can be opened via double click.";
  313. }
  314. $("#typeIcon").attr('src', src);
  315. $("#typeName").text(typeName);
  316. $("#typeExplainText").text(typeDesc);
  317. $("#typeExplain").hide().slideDown();
  318. }
  319. </script>
  320. </body>
  321. </html>