ui.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. This file is part of CPEE.
  3. CPEE is free software: you can redistribute it and/or modify it under the terms
  4. of the GNU General Public License as published by the Free Software Foundation,
  5. either version 3 of the License, or (at your option) any later version.
  6. CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
  7. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  8. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. CPEE (file COPYING in the main directory). If not, see
  11. <http://www.gnu.org/licenses/>.
  12. */
  13. function set_redis(key, value) {
  14. $.ajax({
  15. type: "POST",
  16. url: "/redis/set/" + key,
  17. data: JSON.stringify({ value: value }),
  18. dataType: "json",
  19. contentType: "json",
  20. success: function(data)
  21. {
  22. (data.GET);
  23. }
  24. });
  25. }
  26. function get_redis(key) {
  27. $.ajax({
  28. type: "GET",
  29. url: "redis/get/" + key,
  30. data: "format=json",
  31. dataType: "text",
  32. success: function(data)
  33. {
  34. $("#result").text(data.GET);
  35. }
  36. });
  37. }
  38. function split_string(string) {
  39. var string = str.split(" ",2);
  40. return string;
  41. };
  42. function ui_click_tab(moi) {
  43. $(moi).trigger('click');
  44. }
  45. function ui_close_tab(moi){
  46. var active = $(moi).parent().attr('data-tab');
  47. var tabbed = $(moi).parent().parent().parent();
  48. var is_inactive = $(moi).parent().hasClass('inactive');
  49. $('*[data-tab=' + active + ']').remove();
  50. $('*[data-belongs-to-tab=' + active + ']').remove();
  51. if (!is_inactive)
  52. ui_click_tab($('ui-tabbar ui-tab.default'));
  53. }
  54. function ui_add_close(moi) {
  55. $(moi).append($('<ui-close>✖</ui-close>'));
  56. }
  57. function ui_empty_tab_contents(id) {
  58. $('ui-content ui-area[data-belongs-to-tab=' + id + ']').empty();
  59. }
  60. function ui_add_tab(tabbed,title,id,closeable,additionalclasses) {
  61. additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
  62. if ($('ui-tabbar ui-tab[data-tab=' + id + ']').length > 0) {
  63. ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']'));
  64. return false;
  65. } else {
  66. var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "'>" + title + "</ui-tab>");
  67. var insarea = $("<ui-area data-belongs-to-tab='" + id + "' class='inactive' id="+ id +"></ui-area>");
  68. $(tabbed).find('ui-behind').before(instab);
  69. $(tabbed).find('ui-content').append(insarea);
  70. ui_add_close($('ui-tabbar ui-tab[data-tab=' + id + ']'));
  71. return true;
  72. }
  73. }
  74. function create_new_tab(title, id,terms) {
  75. if (terms != "empty"){
  76. var terms = atob(terms);
  77. var theDiv = document.getElementById(id);
  78. var newElement = document.createElement('div');
  79. var textElement = document.createElement('div');
  80. var array_terms = JSON.parse(terms);
  81. var len = Object.keys(array_terms).length;
  82. console.log(len);
  83. textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO document </a><br>";
  84. for (var key in array_terms) {
  85. console.log(key);
  86. textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','"+array_terms[key]+"')>"+key+" </a><br>";
  87. }
  88. newElement.setAttribute('id', "iso_"+id);
  89. console.log(terms);
  90. console.log(textElement)
  91. newElement.innerHTML = "<iframe width=100% height=1000px src= '{{ url_for('static', filename='isos/') }}"+ id + ".PDF)'> </iframe>";
  92. theDiv.appendChild(textElement);
  93. theDiv.appendChild(newElement);
  94. }
  95. else{
  96. var theDiv = document.getElementById(id);
  97. var newElement = document.createElement('div');
  98. var textElement = document.createElement('div');
  99. textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO File. </a><br>";
  100. newElement.setAttribute('id', "iso_"+id);
  101. newElement.innerHTML = "<iframe width=100% height=1000px src= '+{{ url_for('static', filename='isos/') }}"+ id + ".PDF)'> </iframe>";
  102. theDiv.appendChild(textElement);
  103. theDiv.appendChild(newElement);
  104. }
  105. return true;
  106. }
  107. function change_isos_tab(id, term){
  108. var theDiv = document.getElementById("iso_"+id);
  109. if (term == "start"){
  110. term = 1;
  111. }
  112. theDiv.innerHTML = "<iframe width=100% height=1000px src= '{{ url_for('static', filename='isos/') }}+" + id + ".PDF#page="+ term+ "')'> </iframe>";
  113. console.log(id,term);
  114. return true;
  115. }
  116. function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses, terms) {
  117. var state = ui_add_tab(tabbed,title,id,closeable,additionalclasses);
  118. console.log("test");
  119. if (state) { create_new_tab(title, id, terms); }
  120. if (state) { ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']')); }
  121. return state;
  122. }
  123. function ui_clone_tab(tabbar,original,title,id,closeable,additionalclasses) {
  124. additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
  125. var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "' id='tab_" + id + "'>" + title + "</ui-tab>");
  126. var insarea = original.clone();
  127. insarea.attr("data-belongs-to-tab",id);
  128. insarea.attr("class","inactive");
  129. $(tabbar).find('ui-behind').before(instab);
  130. $(tabbar).parent().append(insarea);
  131. ui_add_close($('ui-tabbed ui-tab[data-tab=' + id + ']'));
  132. }
  133. (function($) { //{{{
  134. $.fn.dragcolumn = function() {
  135. var drag = $(this);
  136. var prev = drag.prev();
  137. var next = drag.next();
  138. this.on("mousedown", function(e) {
  139. drag.addClass('draggable');
  140. $(document).one("mouseup", function(e) {
  141. drag.removeClass('draggable');
  142. e.preventDefault();
  143. });
  144. e.preventDefault();
  145. });
  146. $(document).on("mousemove", function(e) {
  147. if (!drag.hasClass('draggable'))
  148. return;
  149. var total = prev.outerWidth() + next.outerWidth();
  150. var pos = e.pageX - prev.offset().left;
  151. if (pos > total) {
  152. pos = total;
  153. }
  154. var leftPercentage = pos / total;
  155. var rightPercentage = 1 - leftPercentage;
  156. prev.css('flex', leftPercentage.toString());
  157. next.css('flex', rightPercentage.toString());
  158. e.preventDefault();
  159. });
  160. }
  161. $.fn.dragresize = function() {
  162. var drag = $(this);
  163. var prev = drag.prev();
  164. var initpos = 0;
  165. var initheight = $("ui-content",prev).height();
  166. this.on("mousedown", function(e) {
  167. drag.addClass('draggable');
  168. initpos = e.pageY;
  169. $(document).one("mouseup", function(e) {
  170. drag.removeClass('draggable');
  171. e.preventDefault();
  172. });
  173. e.preventDefault();
  174. });
  175. $(document).on("mousemove", function(e) {
  176. if (!drag.hasClass('draggable'))
  177. return;
  178. var pos = initheight - (initpos - e.pageY);
  179. if (pos < 0)
  180. return;
  181. $("ui-content",prev).css('height', pos.toString());
  182. e.preventDefault();
  183. });
  184. }
  185. })(jQuery); //}}}
  186. function ui_activate_tab(moi) { // {{{
  187. var active = $(moi).attr('data-tab');
  188. var tabbed = $(moi).parent().parent();
  189. var tabs = [];
  190. $("ui-tabbar > ui-tab",tabbed).each(function(){
  191. if (!$(this).attr('class').match(/switch/)) {
  192. tabs.push($(this).attr('data-tab'));
  193. }
  194. });
  195. $(".inactive",tabbed).removeClass("inactive");
  196. $.each(tabs,function(a,b){
  197. if (b != active) {
  198. $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
  199. $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
  200. }
  201. });
  202. } // }}}
  203. function ui_toggle_vis_tab(moi) {// {{{
  204. if ($(moi)[0].nodeName == 'UI-TABBED') {
  205. var tabbed = $(moi);
  206. }
  207. if ($(moi)[0].nodeName == 'UI-TAB') {
  208. var tabbed = $(moi).parent().parent();
  209. }
  210. if (tabbed) {
  211. tabbed.toggleClass('off');
  212. }
  213. }// }}}
  214. $(document).ready(function() {
  215. if (!($.browser.name == "Firefox" && $.browser.version >= 20) && !($.browser.name == "Chrome" && $.browser.version >= 30)) {
  216. $('body').children().remove();
  217. $('body').append('Sorry, only Firefox >= 20.0 and Chrom(e|ium) >= 17 for now.');
  218. }
  219. $('ui-rest ui-content ui-resizehandle').dragcolumn();
  220. $('*[is=x-ui] > ui-resizehandle').dragresize();
  221. $(document).on('click','ui-tabbar ui-tab.switch',function(){ui_toggle_vis_tab(this);});
  222. $(document).on('click','ui-tabbar ui-tab:not(.switch)',function(){ui_activate_tab(this);});
  223. ui_add_close($('ui-tabbar ui-tab.closeable'));
  224. $(document).on('click','ui-tabbar ui-tab.closeable ui-close',function(){ui_close_tab(this);});
  225. });