index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>System Setting</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/semantic/semantic.min.js"></script>
  10. <script type="text/javascript" src="../../script/ao_module.js"></script>
  11. <script type="text/javascript" src="../../script/applocale.js"></script>
  12. <style>
  13. html{
  14. overflow:hidden;
  15. height:100%;
  16. }
  17. body{
  18. background-color:#fcfcfc;
  19. overflow:hidden !important;
  20. height:100%;
  21. }
  22. #mainSideMenuDimmer{
  23. width:100%;
  24. height:100%;
  25. position:fixed;
  26. top:0px;
  27. left:0px;
  28. background-color: rgba(26,26,26,0.3);
  29. z-index:99;
  30. }
  31. #mainSideMenu{
  32. z-index:100;
  33. }
  34. #settingContentLoader{
  35. overflow-x: hidden;
  36. overflow-y:auto;
  37. height: calc(100% - 60px);
  38. }
  39. #mainFunctionTabMenu{
  40. background-color: #f8f8f8;
  41. margin-top: 0;
  42. padding-top: 1em;
  43. border-radius: 0 0 0 0 !important;
  44. }
  45. #msgbox{
  46. position: fixed;
  47. bottom: 0.2em;
  48. right: 2em;
  49. display:none;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div id="mainSideMenu" class="ui left fixed vertical menu">
  55. <div class="item">
  56. <img class="ui image" src="img/banner.png">
  57. </div>
  58. </div>
  59. <div id="mainSideMenuDimmer" onclick="hideToolBar();"></div>
  60. <div id="mainFunctionTabMenu" class="ui top attached tabular menu" style="overflow-x:auto;overflow-y:hidden;">
  61. <a id="toolbarBtn" class="item" onclick="showToolBar();">
  62. <i class="content icon"></i>
  63. </a>
  64. <div class="right menu">
  65. <!--
  66. <div class="item">
  67. <div class="ui transparent icon input">
  68. <input id="searchInput" type="text" placeholder="Search Settings..." onkeydown="if (event.which == 13){ search(); }">
  69. <i class="search link icon" onclick="search();"></i>
  70. </div>
  71. </div>
  72. -->
  73. </div>
  74. </div>
  75. <div id="settingContentLoader" class="ui bottom attached segment">
  76. </div>
  77. <div id="msgbox" class="ui compact small message">
  78. Hello World
  79. </div>
  80. </div>
  81. <script>
  82. var currentSettingModuleList = [];
  83. var loadViaSystemSetting = true; //Check for this parameter to see if launching in Setting Interface
  84. var loadToPage = undefined; //Load setting page directly to the given tab, passed in via window hash
  85. var pageStateRestored = false; //Flag to track if page state has been restored from hash
  86. function restorePageFromHash(){
  87. if (pageStateRestored){
  88. return;
  89. }
  90. if (window.location.hash.length > 0){
  91. var hashObject = window.location.hash.substr(1);
  92. hashObject = JSON.parse(decodeURIComponent(hashObject));
  93. if (typeof(hashObject.group) != 'undefined' && typeof(hashObject.name) != 'undefined'){
  94. loadToPage = hashObject;
  95. }
  96. if (!loadToPage || loadToPage.group == "" || loadToPage.name == ""){
  97. //Invalid hash object
  98. initSettingGroup("Info");
  99. return;
  100. }
  101. initSettingGroup(loadToPage.group, function(settingList){
  102. let reversedList = JSON.parse(JSON.stringify(settingList)).reverse();
  103. for (var i = 0; i < settingList.length; i++){
  104. var settingTab = settingList[i];
  105. console.log(settingTab.Name, loadToPage.name, settingTab.Name == loadToPage.name, i);
  106. if (settingTab.Name == loadToPage.name){
  107. //This is the tab we are looking for
  108. initSettingModules(settingList.length - i-1);
  109. }
  110. }
  111. });
  112. }else{
  113. //No hash, load default Info page
  114. initSettingGroup("Info");
  115. }
  116. pageStateRestored = true;
  117. }
  118. applocale.init("../locale/system_settings.json", function(){
  119. applocale.translate();
  120. //Initiation Functions
  121. initMainSideMenu(function(){
  122. //Menu is now loaded
  123. hideToolBar();
  124. if (!pageStateRestored){
  125. restorePageFromHash();
  126. return;
  127. }
  128. initSettingGroup("Info");
  129. });
  130. });
  131. function initMainSideMenu(callback){
  132. $.get("../../system/setting/list",function(data){
  133. for (var i =0; i < data.length; i++){
  134. var settingGroupName = data[i].Name;
  135. var groupUUID = data[i].Group;
  136. var iconPath = "../../" + data[i].IconPath;
  137. var toolTip = data[i].Desc;
  138. settingGroupName = applocale.getString("menu/group/" + settingGroupName, settingGroupName);
  139. $("#mainSideMenu").append(`<a class="item" group="${groupUUID}" title="${toolTip}" style="padding:4px;" onclick="menuClicked(this);"><img class="ui middle aligned mini image" src="${iconPath}" style="padding: 2px;"></img> ${settingGroupName}</a>`);
  140. }
  141. applocale.translate();
  142. //Notify that menu is loaded
  143. if (callback){
  144. callback();
  145. }
  146. });
  147. }
  148. function initSettingGroup(group, callback=undefined){
  149. $.get("../../system/setting/list?listGroup=" + group,function(data){
  150. if (data.error !== undefined){
  151. console.log(data.error);
  152. }else{
  153. currentSettingModuleList = data;
  154. initSettingModuleTabs(group);
  155. initSettingModules(0);
  156. if (callback != undefined){
  157. callback(data);
  158. }
  159. }
  160. });
  161. }
  162. function menuClicked(object){
  163. var group=$(object).attr("group");
  164. initSettingGroup(group, function(settingList){
  165. //After loading group, update hash with first tab
  166. if (settingList.length > 0){
  167. updateWindowHash(settingList[0].Group, settingList[0].Name);
  168. }
  169. });
  170. hideToolBar();
  171. }
  172. //Initiate the setting modules tabs
  173. function initSettingModuleTabs(groupName){
  174. $(".settingTab").remove();
  175. var moduleListInReverse = currentSettingModuleList.reverse();
  176. for (var i =0; i < moduleListInReverse.length; i ++){
  177. var thisModuleInfo = moduleListInReverse[i];
  178. var stringifyModuleInfo = encodeURIComponent(JSON.stringify(thisModuleInfo));
  179. let localeGroupKey = "tab/" + groupName.toLowerCase() + "/" + thisModuleInfo.Name;
  180. let displayTabName = applocale.getString(localeGroupKey, thisModuleInfo.Name)
  181. console.log(thisModuleInfo.Desc);
  182. $("#toolbarBtn").after(`<a class="item settingTab" moduleInfo="${stringifyModuleInfo}" title="${thisModuleInfo.Desc}" onclick="loadSettingModuleFromTab(this);">${displayTabName}</a>`);
  183. }
  184. applocale.translate();
  185. }
  186. function initSettingModules(index){
  187. if (index < 0){
  188. index = 0;
  189. }
  190. var targetObject = $(".settingTab")[index];
  191. $(".settingTab.active").removeClass("active");
  192. if (targetObject !== undefined){
  193. //Select this object
  194. $(targetObject).addClass("active");
  195. //Load this object into the tab
  196. var settingModuleInfo = JSON.parse(decodeURIComponent($(targetObject).attr("moduleInfo")));
  197. var settingStartDir = settingModuleInfo.StartDir;
  198. $("#settingContentLoader").html("");
  199. $("#settingContentLoader").load("../../" + settingStartDir, function(){
  200. injectIMEToLoadedConetentFrame();
  201. });
  202. }
  203. }
  204. function loadSettingModuleFromTab(object){
  205. targetObject = $(object);
  206. $(".settingTab.active").removeClass("active");
  207. if (targetObject !== undefined){
  208. //Select this object
  209. $(targetObject).addClass("active");
  210. //Load this object into the tab
  211. var settingModuleInfo = JSON.parse(decodeURIComponent($(targetObject).attr("moduleInfo")));
  212. var settingStartDir = settingModuleInfo.StartDir;
  213. //Update window hash with current tab
  214. updateWindowHash(settingModuleInfo.Group, settingModuleInfo.Name);
  215. $("#settingContentLoader").html("");
  216. $("#settingContentLoader").load("../../" + settingStartDir, function(){
  217. injectIMEToLoadedConetentFrame();
  218. });
  219. }
  220. }
  221. function updateWindowHash(groupName, moduleName){
  222. //Update window hash to preserve tab state on refresh
  223. //Skip if in ao_window mode
  224. if (ao_module_windowID !== false){
  225. //Running in floatWindow mode, do not update hash
  226. return;
  227. }
  228. var hashObject = {
  229. group: groupName,
  230. name: moduleName
  231. };
  232. window.location.hash = encodeURIComponent(JSON.stringify(hashObject));
  233. }
  234. function injectIMEToLoadedConetentFrame(){
  235. //Inject IME listener into the loaded content window
  236. var inputFields = document.getElementById("settingContentLoader").querySelectorAll("input,textarea");
  237. for (var i = 0; i < inputFields.length; i++){
  238. if ($(inputFields[i]).attr("type") != undefined){
  239. var thisType = $(inputFields[i]).attr("type");
  240. if (thisType == "text" || thisType =="search" || thisType =="url"){
  241. //Supported types of input
  242. if (ao_module_virtualDesktop){
  243. ao_module_bindCustomIMEEvents(inputFields[i]);
  244. }
  245. console.log(inputFields[i]);
  246. }else{
  247. //Not supported type of inputs
  248. }
  249. }else{
  250. //text area
  251. if (ao_module_virtualDesktop){
  252. ao_module_bindCustomIMEEvents(inputFields[i]);
  253. }
  254. }
  255. }
  256. }
  257. function hideToolBar(){
  258. $("#mainSideMenuDimmer").fadeOut('fast');
  259. $("#mainSideMenu").animate({left: -1 * $("#mainSideMenu").width()},300);
  260. }
  261. function showToolBar(){
  262. $("#mainSideMenuDimmer").fadeIn('fast');
  263. $("#mainSideMenu").animate({left: "0px"},300);
  264. }
  265. function search(){
  266. var keyword = $("#searchInput").val();
  267. alert(keyword);
  268. }
  269. function msgbox(message, succ=true, delay=3000){
  270. $("#msgbox").html(`<i class="ui ${succ?"green circle check":"red circle times"} icon"></i> ${message}`);
  271. $("#msgbox").stop().finish().fadeIn("fast").delay(delay).fadeOut("fast");
  272. }
  273. </script>
  274. </body>
  275. </html>