common.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /**
  2. * Load modules by objectID and objectType.
  3. *
  4. * @param string $objectType
  5. * @param int $objectID
  6. * @access public
  7. * @return void
  8. */
  9. function loadObjectModules(objectType, objectID, docType)
  10. {
  11. if(typeof docType == 'undefined') docType = 'doc';
  12. if(objectType == 'execution' && objectID == 0)
  13. {
  14. objectType = 'project';
  15. objectID = $('#project').val();
  16. }
  17. if(objectID == undefined) objectID = 0;
  18. var link = createLink('doc', 'ajaxGetModules', 'objectType=' + objectType + '&objectID=' + objectID + '&type=' + docType);
  19. var selected = $('#module').val();
  20. $('#moduleBox').load(link, function(){$('#moduleBox').find('select').val(selected).picker(); $('#moduleLabel').remove();});
  21. }
  22. /**
  23. * Load executions.
  24. *
  25. * @param int $projectID
  26. * @access public
  27. * @return void
  28. */
  29. function loadExecutions(projectID)
  30. {
  31. var link = createLink('project', 'ajaxGetExecutions', "projectID=" + projectID + "&executionID=0&mode=multiple,leaf,noprefix&type=sprint,stage");
  32. $('#executionBox').load(link, function()
  33. {
  34. var $extension = $('#executionBox').find('select');
  35. $extension.attr('onchange', "loadObjectModules('execution', this.value)").picker();
  36. if($extension.hasClass('disabled')) $('#executionBox').find('.picker').addClass('disabled');
  37. });
  38. loadObjectModules('project', projectID);
  39. }
  40. /**
  41. * Toggle acl.
  42. *
  43. * @param string $acl
  44. * @param string $type
  45. * @access public
  46. * @return void
  47. */
  48. function toggleAcl(acl, type)
  49. {
  50. var libID = $('#lib').val();
  51. if($('#lib').length == 0 && $('#module').length > 0)
  52. {
  53. var moduleID = $('#module').val();
  54. if(moduleID.indexOf('_') >= 0) libID = moduleID.substr(0, moduleID.indexOf('_'));
  55. }
  56. if(acl == 'private')
  57. {
  58. $('#whiteListBox').removeClass('hidden');
  59. $('#groupBox').removeClass('hidden');
  60. }
  61. else
  62. {
  63. $('#whiteListBox').addClass('hidden');
  64. $('#groupBox').addClass('hidden');
  65. }
  66. if(type == 'lib')
  67. {
  68. if(libType == 'book' && acl == 'private') $('#whiteListBox').addClass('hidden');
  69. if(libType == 'project' && typeof(doclibID) != 'undefined')
  70. {
  71. var link = createLink('doc', 'ajaxGetWhitelist', 'doclibID=' + doclibID + '&acl=' + acl);
  72. $.get(link, function(users)
  73. {
  74. $('#users').replaceWith(users);
  75. $('#users').next('.picker').remove();
  76. $('#users').picker();
  77. })
  78. }
  79. }
  80. else if(type == 'doc')
  81. {
  82. $('#whiteListBox').toggleClass('hidden', acl == 'open');
  83. $('#groupBox').toggleClass('hidden', acl == 'open');
  84. loadWhitelist(libID);
  85. }
  86. }
  87. /**
  88. * Load doc module by libID.
  89. *
  90. * @param int $libID
  91. * @access public
  92. * @return void
  93. */
  94. function loadDocModule(libID)
  95. {
  96. var link = createLink('doc', 'ajaxGetChild', 'libID=' + libID);
  97. $.post(link, function(data)
  98. {
  99. $('#moduleBox').html(data);
  100. $('#module').picker();
  101. });
  102. loadWhitelist(libID);
  103. }
  104. /**
  105. * Set cookie of browse type and reload.
  106. *
  107. * @param type $type
  108. * @access public
  109. * @return void
  110. */
  111. function setBrowseType(type)
  112. {
  113. $.cookie('browseType', type, {expires:config.cookieLife, path:config.webRoot});
  114. location.href = location.href;
  115. }
  116. $(document).ready(function()
  117. {
  118. /* Hide #module chosen dropdown on #lib dropdown show. */
  119. $('#lib').on('chosen:showing_dropdown', function()
  120. {
  121. $('#module').trigger('chosen:close');
  122. });
  123. $('.libs-group.sort').sortable(
  124. {
  125. trigger: '.lib',
  126. selector: '.lib',
  127. finish: function()
  128. {
  129. var orders = {};
  130. var orderNext = 1;
  131. $('.libs-group .lib').not('.files').not('.addbtn').each(function()
  132. {
  133. orders[$(this).data('id')] = orderNext ++;
  134. })
  135. $.post(createLink('doc', 'sort'), orders, function(data)
  136. {
  137. if(data.result == 'success')
  138. {
  139. return location.reload();
  140. }
  141. else
  142. {
  143. alert(data.message);
  144. return location.reload();
  145. }
  146. }, 'json');
  147. }
  148. });
  149. 'use strict';
  150. var NAME = 'zui.splitRow'; // model name.
  151. /* The SplitRow model class. */
  152. var SplitRow = function(element, options)
  153. {
  154. var that = this;
  155. that.name = NAME;
  156. var $element = that.$ = $(element);
  157. options = that.options = $.extend({}, SplitRow.DEFAULTS, this.$.data(), options);
  158. var id = options.id || $element.attr('id') || $.zui.uuid();
  159. var $cols = $element.children('.side-col,.main-col');
  160. var $firstCol = $cols.first();
  161. var $secondCol = $cols.eq(1);
  162. var $spliter = $firstCol.next('.col-spliter');
  163. if (!$spliter.length)
  164. {
  165. $spliter = $(options.spliter);
  166. if (!$spliter.parent().length)
  167. {
  168. $spliter.insertAfter($firstCol);
  169. }
  170. }
  171. var spliterWidth = $spliter.width();
  172. var minFirstColWidth = $firstCol.data('minWidth');
  173. var minSecondColWidth = $secondCol.data('minWidth');
  174. var setFirstColWidth = function(width)
  175. {
  176. var rowWidth = $element.width();
  177. var maxFirstWidth = rowWidth - minSecondColWidth - spliterWidth;
  178. width = Math.max(minFirstColWidth, Math.min(width, maxFirstWidth));
  179. $firstCol.width(width);
  180. $.zui.store.set('splitRowFirstSize:' + id, width);
  181. };
  182. var defaultWidth = $.zui.store.get('splitRowFirstSize:' + id);
  183. if(typeof(defaultWidth) == 'undefined')
  184. {
  185. defaultWidth = 0;
  186. $firstCol.find('.tabs ul.nav-tabs li').each(function(){defaultWidth += $(this).outerWidth()});
  187. defaultWidth += ($firstCol.find('.tabs ul.nav-tabs li').length - 1) * 10;
  188. defaultWidth += 30;
  189. }
  190. setFirstColWidth(defaultWidth);
  191. var documentEventName = '.' + id;
  192. var mouseDownX, isMouseDown, startFirstWidth;
  193. $spliter.on('mousedown', function(e)
  194. {
  195. startFirstWidth = $firstCol.width();
  196. mouseDownX = e.pageX;
  197. isMouseDown = true;
  198. $element.addClass('row-spliting');
  199. e.preventDefault();
  200. $(document).on('mousemove' + documentEventName, function(e)
  201. {
  202. if (isMouseDown)
  203. {
  204. var deltaX = e.pageX - mouseDownX;
  205. setFirstColWidth(startFirstWidth + deltaX);
  206. e.preventDefault();
  207. }
  208. else
  209. {
  210. $(document).off(documentEventName);
  211. $element.removeClass('row-spliting');
  212. }
  213. }).on('mouseup' + documentEventName + ' mouseleave' + documentEventName, function(e)
  214. {
  215. isMouseDown = false;
  216. $(document).off(documentEventName);
  217. $element.removeClass('row-spliting');
  218. });
  219. });
  220. var fixColClass = function($col)
  221. {
  222. if (options.smallSize) $col.toggleClass('col-sm-size', $col.width() < options.smallSize);
  223. if (options.middleSize) $col.toggleClass('col-md-size', $col.width() < options.middleSize);
  224. };
  225. var resizeCols = function()
  226. {
  227. var cellHeight = $(window).height() - $('#footer').outerHeight() - $('#header').outerHeight() - 42;
  228. $cols.children('.panel').height(cellHeight).css('maxHeight', cellHeight).find('.panel-body').css('position', 'absolute');
  229. var sideHeight = cellHeight - $cols.find('.nav-tabs').height() - $cols.find('.side-footer').height() - 35;
  230. $cols.find('.tab-content').height(sideHeight).css('maxHeight', sideHeight).css('overflow-y', 'auto');
  231. };
  232. $(window).on('resize', resizeCols);
  233. $firstCol.on('resize', function(e) {fixColClass($firstCol);});
  234. $secondCol.on('resize', function(e) {fixColClass($secondCol);});
  235. fixColClass($firstCol);
  236. fixColClass($secondCol);
  237. resizeCols();
  238. };
  239. /* default options. */
  240. SplitRow.DEFAULTS =
  241. {
  242. spliter: '<div class="col-spliter"></div>',
  243. smallSize: 700,
  244. middleSize: 850
  245. };
  246. /* Extense jquery element. */
  247. $.fn.splitRow = function(option)
  248. {
  249. return this.each(function()
  250. {
  251. var $this = $(this);
  252. var data = $this.data(NAME);
  253. var options = typeof option == 'object' && option;
  254. if(!data) $this.data(NAME, (data = new SplitRow(this, options)));
  255. });
  256. };
  257. SplitRow.NAME = NAME;
  258. $.fn.splitRow.Constructor = SplitRow;
  259. /* Auto call splitRow after document load complete. */
  260. $(function()
  261. {
  262. $('.split-row').splitRow();
  263. });
  264. var $pageSetting = $('#pageSetting');
  265. if($pageSetting.length)
  266. {
  267. $pageSetting.on('click', '.close-dropdown', function()
  268. {
  269. $pageSetting.parent().removeClass('open');
  270. }).on('click', function(e){e.stopPropagation()});
  271. }
  272. $(document).on('mousedown', '.ajaxCollect', function (event)
  273. {
  274. if(event.button != 0) return;
  275. var obj = $(this);
  276. var url = obj.data('url');
  277. $.get(url, function(response)
  278. {
  279. if(response.status == 'yes')
  280. {
  281. obj.children('img').attr('src', 'static/svg/star.svg');
  282. obj.parent().prev().children('.file-name').children('i').remove('.icon');
  283. obj.parent().prev().children('.file-name').prepend('<i class="icon icon-star text-yellow"></i> ');
  284. }
  285. else
  286. {
  287. obj.children('img').attr('src', 'static/svg/star-empty.svg');
  288. obj.parent().prev().children('.file-name').children('i').remove(".icon");
  289. }
  290. }, 'json');
  291. return false;
  292. });
  293. });
  294. /**
  295. * locateNewLib
  296. *
  297. * @param string $type product|project|execution|custom|mine
  298. * @param int $objectID
  299. * @param int $libID
  300. * @access public
  301. * @return void
  302. */
  303. function locateNewLib(type, objectID, libID)
  304. {
  305. var method = 'teamSpace';
  306. var params = 'objectID=' + objectID + '&libID=' + libID;
  307. var module = 'doc';
  308. if(type == 'product' || type == 'project')
  309. {
  310. method = type + 'Space';
  311. }
  312. else if(type == 'execution')
  313. {
  314. module = 'execution';
  315. method = 'doc';
  316. }
  317. else if(type == 'mine')
  318. {
  319. method = 'mySpace';
  320. params = 'type=mine&libID=' + libID;
  321. }
  322. location.href = createLink(module, method, params);
  323. }
  324. /**
  325. * Submit form.
  326. *
  327. * @param object $object
  328. * @access public
  329. * @return void
  330. */
  331. function submit(object)
  332. {
  333. $(object).attr('type', 'submit');
  334. $('#dataform').submit();
  335. setTimeout(function(){$(object).attr('type', 'button').removeAttr('disabled')}, 2000);
  336. }