pod.js 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. function generateStringId(charNb = 32, allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
  2. var text = "";
  3. for( var i=0; i < charNb; i++ ) {
  4. text += allowedChars.charAt(Math.floor(Math.random() * allowedChars.length));
  5. }
  6. return text;
  7. }
  8. function toggleFullScreen(outerWidgetId, innerWidgetId) {
  9. if($(outerWidgetId).hasClass('full-size-overlay')) {
  10. // Toggle from fullscreen to "normal"
  11. $(outerWidgetId).removeClass('full-size-overlay');
  12. $(innerWidgetId).removeClass('full-size-overlay-inner');
  13. $('.pod-toggle-full-screen-button > i').removeClass('fa-compress')
  14. $('.pod-toggle-full-screen-button > i').addClass('fa-expand')
  15. } else {
  16. // Toggle from normal to fullscreen
  17. $(outerWidgetId).addClass('full-size-overlay');
  18. $(innerWidgetId).addClass('full-size-overlay-inner');
  19. $('.pod-toggle-full-screen-button > i').removeClass('fa-expand')
  20. $('.pod-toggle-full-screen-button > i').addClass('fa-compress')
  21. }
  22. }
  23. function initToolbarBootstrapBindings(richTextEditorId) {
  24. // $('a[title]').tooltip({container:'body'});
  25. $(richTextEditorId+' > .dropdown-menu input').click(function() {return false;})
  26. .change(function () {$(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');})
  27. .keydown('esc', function () {this.value='';$(this).change();});
  28. $('[data-role=magic-overlay]').each(function () {
  29. var overlay = $(this), target = $(overlay.data('target'));
  30. overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
  31. });
  32. if ("onwebkitspeechchange" in document.createElement("input")) {
  33. var editorOffset = $(richTextEditorId).offset();
  34. $('#voiceBtn').css('position','absolute').offset({top: editorOffset.top, left: editorOffset.left+$(richTextEditorId).innerWidth()-35});
  35. } else {
  36. $('#voiceBtn').hide();
  37. }
  38. };
  39. function showErrorAlert (reason, detail) {
  40. var msg='';
  41. if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
  42. else {
  43. console.log("error uploading file", reason, detail);
  44. }
  45. $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+
  46. '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
  47. };
  48. $(document).ready(function() {
  49. /* EDIT CONTENT FORM */
  50. $("#current-document-content-edit-form" ).css("display", "none");
  51. $("#current-document-content-edit-button" ).click(function() {
  52. $("#current-document-content" ).css("display", "none");
  53. $("#current-document-content-edit-form" ).css("display", "block");
  54. $("#current-document-toobar").css("display", "none");
  55. });
  56. $("#current-document-content-edit-cancel-button, #current-document-content-edit-cancel-button-top" ).click(function() {
  57. $("#current-document-content" ).css("display", "block");
  58. $("#current-document-content-edit-form" ).css("display", "none");
  59. $("#current-document-toobar").css("display", "block");
  60. });
  61. $('#current-document-content-edit-save-button, #current-document-content-edit-save-button-top').on('click', function(e){
  62. // We don't want this to act as a link so cancel the link action
  63. e.preventDefault();
  64. $('#current_node_textarea_wysiwyg').cleanHtml();
  65. $('#current_node_textarea').val($('#current_node_textarea_wysiwyg').html());
  66. $('#current-document-content-edit-form').submit();
  67. });
  68. $(function() {
  69. $('.datetime-picker-input-div').datetimepicker({
  70. language: 'fr-FR',
  71. pickSeconds: false
  72. });
  73. });
  74. // #################################
  75. // ##
  76. // ## The following JS code allow t
  77. // ##
  78. // ##
  79. // Javascript to enable link to tab
  80. var hash = document.location.hash;
  81. var prefix = "tab-";
  82. if (hash) {
  83. $('.nav-tabs a[href='+hash.replace(prefix,"")+']').tab('show');
  84. }
  85. // Change hash for page-reload
  86. $('.nav-tabs a').on('shown', function (e) {
  87. window.location.hash = e.target.hash.replace("#", "#" + prefix);
  88. });
  89. // #################################
  90. // ##
  91. // ## Show/hide behavior
  92. // ## for the main menu
  93. // ##
  94. // ##
  95. $('a.toggle-child-menu-items').on('click', function (e) {
  96. parent_id = $(this).parent().attr('id');
  97. child = $('#'+parent_id+'-children');
  98. togglebutton = $(this).children('i:first')
  99. if(child.css('display')=='none'){
  100. child.css("display", "block");
  101. togglebutton.removeClass('icon-g-folder-plus');
  102. togglebutton.attr('class', 'icon-g-folder-open');
  103. console.log("class is: "+togglebutton.attr('class'));
  104. } else {
  105. child.css("display", "none");
  106. togglebutton.removeClass('icon-g-folder-open');
  107. togglebutton.addClass('icon-g-folder-plus');
  108. console.log("class is: "+togglebutton.attr('class'));
  109. }
  110. });
  111. // #################################
  112. // ##
  113. // ## large / small view of the document
  114. // ## (toggle visibility of the left panel)
  115. // ##
  116. // ##
  117. $('a#view-size-toggle-button-small').on('click', function (e) {
  118. console.log("Toggle view mode");
  119. $('#view-size-toggle-button-small').css('display', 'none');
  120. $('#view-size-toggle-button-medium').css('display', 'block');
  121. $('#view-size-toggle-button-large').css('display', 'none');
  122. left_panel_id = '#application-left-panel'; // is span3 by default (to be hidden in fullscreen mode)
  123. main_panel_id = '#application-main-panel'; // is span9 by default (to be 12 in fullscreen mode)
  124. docu_panel_id = '#application-document-panel'; // is span5 by default (to be span8 in fullscreen mode)
  125. metadata_panel_id = '#application-metadata-panel';
  126. left_panel = $(left_panel_id);
  127. main_panel = $(main_panel_id);
  128. docu_panel = $(docu_panel_id);
  129. metadata_panel = $(metadata_panel_id);
  130. console.log("Toggle from small (default) to medium (no left tab)");
  131. left_panel.css('display', 'block');
  132. metadata_panel.css('display', 'block');
  133. main_panel.removeClass('span9');
  134. main_panel.removeClass('span12');
  135. main_panel.addClass('span9');
  136. docu_panel.removeClass('span5');
  137. docu_panel.removeClass('span8');
  138. docu_panel.removeClass('span12');
  139. docu_panel.addClass('span5');
  140. });
  141. $('a#view-size-toggle-button-medium').on('click', function (e) {
  142. console.log("Toggle view mode to: MEDIUM");
  143. $('#view-size-toggle-button-small').css('display', 'none');
  144. $('#view-size-toggle-button-medium').css('display', 'none');
  145. $('#view-size-toggle-button-large').css('display', 'block');
  146. left_panel_id = '#application-left-panel'; // is span3 by default (to be hidden in fullscreen mode)
  147. main_panel_id = '#application-main-panel'; // is span9 by default (to be 12 in fullscreen mode)
  148. docu_panel_id = '#application-document-panel'; // is span5 by default (to be span8 in fullscreen mode)
  149. metadata_panel_id = '#application-metadata-panel';
  150. left_panel = $(left_panel_id);
  151. main_panel = $(main_panel_id);
  152. docu_panel = $(docu_panel_id);
  153. metadata_panel = $(metadata_panel_id);
  154. left_panel.css('display', 'none');
  155. metadata_panel.css('display', 'block');
  156. main_panel.removeClass('span9');
  157. main_panel.addClass('span12');
  158. docu_panel.removeClass('span5');
  159. docu_panel.removeClass('span12');
  160. docu_panel.addClass('span8');
  161. });
  162. $('a#view-size-toggle-button-large').on('click', function (e) {
  163. console.log("Toggle view mode to: LARGE");
  164. $('#view-size-toggle-button-small').css('display', 'block');
  165. $('#view-size-toggle-button-medium').css('display', 'none');
  166. $('#view-size-toggle-button-large').css('display', 'none');
  167. left_panel_id = '#application-left-panel'; // is span3 by default (to be hidden in fullscreen mode)
  168. main_panel_id = '#application-main-panel'; // is span9 by default (to be 12 in fullscreen mode)
  169. docu_panel_id = '#application-document-panel'; // is span5 by default (to be span8 in fullscreen mode)
  170. metadata_panel_id = '#application-metadata-panel';
  171. left_panel = $(left_panel_id);
  172. main_panel = $(main_panel_id);
  173. docu_panel = $(docu_panel_id);
  174. metadata_panel = $(metadata_panel_id);
  175. left_panel.css('display', 'none');
  176. metadata_panel.css('display', 'none');
  177. main_panel.removeClass('span9');
  178. main_panel.addClass('span12');
  179. docu_panel.removeClass('span5');
  180. docu_panel.removeClass('span8');
  181. docu_panel.addClass('span12');
  182. });
  183. // ALLOW TO SHOW POPOVER WITH SPECIFIC DATA
  184. $('.item-with-data-popoverable').popover({ html: true});
  185. /** Make calculator available on all pages */
  186. $('#keyboard span').on('click', function (e) {
  187. current_value = $(this).text()
  188. if(current_value=='C') {
  189. $('#calculation').val('');
  190. $('#result').val('');
  191. } else if(current_value=='=') {
  192. string = $('#calculation').val().replace(/[^0-9+-/\*\%\(\)]/gi, ''); // replace('/[^0-9()*/-+]/g', "");
  193. console.log("Compute value of "+string)
  194. calculation = eval(string);
  195. console.log("Result is: "+calculation)
  196. $('#result').val(calculation)
  197. } else {
  198. field = $('#calculation')
  199. field.oldval = field.val();
  200. field.val(field.oldval+current_value)
  201. }
  202. });
  203. });