common.ui.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /**
  2. * Toggle acl.
  3. *
  4. * @param string $acl
  5. * @param string $type
  6. * @access public
  7. * @return void
  8. */
  9. function toggleAcl(type)
  10. {
  11. const acl = $('input[name=acl]:checked').val();
  12. let libID = $('input[name=lib]').val();
  13. if($('input[name=lib]').length == 0 && $('input[name=module]').length > 0)
  14. {
  15. let moduleID = $('input[name=module]').val();
  16. if(moduleID.indexOf('_') >= 0) libID = moduleID.substr(0, moduleID.indexOf('_'));
  17. }
  18. if(acl == 'private')
  19. {
  20. if(libType != 'mine')
  21. {
  22. $('#whiteListBox').removeClass('hidden');
  23. $('#groupBox').removeClass('hidden');
  24. }
  25. }
  26. else
  27. {
  28. $('#whiteListBox').addClass('hidden');
  29. $('#groupBox').addClass('hidden');
  30. }
  31. $('#whiteListBox .notice').remove();
  32. if(type == 'lib')
  33. {
  34. if(libType == 'project' && typeof(doclibID) != 'undefined')
  35. {
  36. let link = $.createLink('doc', 'ajaxGetWhitelist', 'doclibID=' + doclibID + '&acl=' + acl);
  37. $.getJSON(link, function(users)
  38. {
  39. if(users != 'private' && users)
  40. {
  41. const $usersPicker = $('select[name^=users]').zui('picker');
  42. $usersPicker.render({items: users});
  43. $usersPicker.$.setValue('');
  44. }
  45. })
  46. }
  47. }
  48. else if(type == 'doc')
  49. {
  50. $('#whiteListBox, #readListBox').toggleClass('hidden', acl == 'open');
  51. $('#groupBox').toggleClass('hidden', acl == 'open');
  52. loadWhitelist(libID);
  53. }
  54. }
  55. /**
  56. * Load whitelist by libID.
  57. *
  58. * @param int $libID
  59. * @access public
  60. * @return void
  61. */
  62. window.loadWhitelist = function(libID)
  63. {
  64. let groupLink = $.createLink('doc', 'ajaxGetWhitelist', 'libID=' + libID + '&acl=&control=group');
  65. let userLink = $.createLink('doc', 'ajaxGetWhitelist', 'libID=' + libID + '&acl=&control=user');
  66. $.getJSON(groupLink, function(groups)
  67. {
  68. if(groups != 'private' && groups)
  69. {
  70. const $groupsPicker = $('select[name^=groups]').zui('picker');
  71. $groupsPicker.render({items: groups});
  72. $groupsPicker.$.setValue('');
  73. }
  74. });
  75. $.get(userLink, function(users)
  76. {
  77. if(users != 'private' && users)
  78. {
  79. users = JSON.parse(users);
  80. const $usersPicker = $('select[name^=users]').zui('picker');
  81. $usersPicker.render({items: users});
  82. $usersPicker.$.setValue('');
  83. }
  84. });
  85. }
  86. /**
  87. * locateNewLib
  88. *
  89. * @param string $type product|project|execution|custom|mine
  90. * @param int $objectID
  91. * @param int $libID
  92. * @access public
  93. * @return void
  94. */
  95. window.locateNewLib = function(type, objectID, libID)
  96. {
  97. let method = 'teamSpace';
  98. let params = 'objectID=' + objectID + '&libID=' + libID;
  99. let module = 'doc';
  100. if(type == 'product' || type == 'project')
  101. {
  102. method = type + 'Space';
  103. }
  104. else if(type == 'execution')
  105. {
  106. module = 'execution';
  107. method = 'doc';
  108. }
  109. else if(type == 'mine')
  110. {
  111. method = 'mySpace';
  112. params = 'type=mine&libID=' + libID;
  113. }
  114. loadPage($.createLink(module, method, params));
  115. }
  116. window.rendDocCell = function(result, {col, row})
  117. {
  118. const dtable = zui.DTable.query('#docTable');
  119. if(!dtable) return;
  120. if(col.name == 'title' && result[0])
  121. {
  122. const doc = row.data;
  123. const starIcon = doc.collector.indexOf(',' + dtable.options.currentAccount + ',') >= 0 ? 'star' : 'star-empty';
  124. const docType = dtable.options.iconList[doc.type];
  125. const docIcon = doc.type == 'text' ? 'wiki-file' : doc.type;
  126. let html = "<img src='static/svg/" + docIcon + ".svg' class='file-icon'/>";
  127. result.unshift({html});
  128. if(doc.status == 'draft')
  129. {
  130. html = "<span class='label special-pale rounded-full draft'>" + dtable.options.draftText + '</span>';
  131. result.push({html});
  132. }
  133. if(dtable.options.canCollect)
  134. {
  135. html = "<a href='" + $.createLink('doc', 'collect', 'objectID=' + doc.id + '&objectType=doc') + "' class='btn btn-link ajax-submit star'><img src='static/svg/" + starIcon + ".svg'/></a>";
  136. result.push({html});
  137. }
  138. if(result[1]['props']) result[1]['props']['class'] = 'text-ellipsis';
  139. return result;
  140. }
  141. if(col.name == 'module')
  142. {
  143. const moduleDivide = row.data.moduleName ? ' > ' : '';
  144. const moduleName = row.data.libName + moduleDivide + row.data.moduleName;
  145. const spaceMethod = typeof spaceMethodList != 'undefined' ? spaceMethodList[row.data.objectType] : '';
  146. let moduleHtml = '';
  147. if(spaceMethod && eval(`${spaceMethod}Priv`))
  148. {
  149. let spaceParams = `libID=${row.data.lib}&moduleID=${row.data.module}`;
  150. if(['product', 'project', 'execution', 'custom'].indexOf(row.data.objectType) !== -1) spaceParams = `objectID=${row.data.objectID}&${spaceParams}`;
  151. if(row.data.objectType == 'mine') spaceParams = `type=${row.data.objectType}&${spaceParams}`;
  152. moduleHtml = `<a data-app='${dtable.options.currentTab}' href="` + $.createLink('doc', spaceMethod, spaceParams) + '">' + moduleName + '</a>';
  153. }
  154. else
  155. {
  156. moduleHtml = `<span>${moduleName}</span>`;
  157. }
  158. result[0] = {html: moduleHtml};
  159. result[1] = {attrs: {title: moduleName}};
  160. return result;
  161. }
  162. if(col.name == 'actions' && result[0].length)
  163. {
  164. if(col.setting.list.edit && row.data.type != 'text')
  165. {
  166. result[0]['props']['items'][0]['data-toggle'] = 'modal';
  167. return result;
  168. }
  169. }
  170. return result;
  171. }
  172. window.loadObjectModules = function(e, docID)
  173. {
  174. let objectID = e.target.value;
  175. let objectType = e.target.name;
  176. if(objectType == 'space')
  177. {
  178. let targetSpace = objectID.split('.');
  179. objectType = targetSpace[0];
  180. objectID = targetSpace[1];
  181. }
  182. if(objectType == 'execution' && objectID == 0)
  183. {
  184. objectType = 'project';
  185. objectID = $('[name=project]').val();
  186. }
  187. if(!objectType || (objectType != 'mine' && !objectID)) return false;
  188. let docType = $('.radio-primary [name=type]:not(.hidden):checked').val();
  189. if(typeof docType == 'undefined') docType = 'doc';
  190. const link = $.createLink('doc', 'ajaxGetModules', 'objectType=' + objectType + '&objectID=' + objectID + '&type=' + docType + '&docID=' + docID);
  191. $.get(link, function(data)
  192. {
  193. data = JSON.parse(data);
  194. const $libPicker = $("[name='lib']").zui('picker');
  195. $libPicker.render({items: data.libs});
  196. $libPicker.$.setValue('');
  197. const $modulePicker = $("[name='parent']").zui('picker');
  198. $modulePicker.render({items: data.modules});
  199. $modulePicker.$.setValue('');
  200. });
  201. }
  202. window.loadLibModules = function(e, docID)
  203. {
  204. const libID = e.target.value;
  205. const libType = $(e.target.closest('div.form-group')).attr('data-lib-type');
  206. const objectID = $("input[name='" + libType + "']").val();
  207. if(typeof docType == 'undefined')
  208. {
  209. docType = $('.radio-primary [name=type]:not(.hidden):checked').val();
  210. if(typeof docType == 'undefined') docType = 'doc';
  211. }
  212. const link = $.createLink('doc', 'ajaxGetModules', 'objectType=' + libType + '&objectID=' + objectID + '&type=' + docType + '&docID=' + docID + '&libID=' + libID);
  213. $.get(link, function(data)
  214. {
  215. data = JSON.parse(data);
  216. if(docType == 'docTemplate')
  217. {
  218. data = data.filter(function(item)
  219. {
  220. return item.value != 0;
  221. });
  222. }
  223. const $modulePicker = $("[name='parent']").zui('picker');
  224. $modulePicker.render({items: data.modules});
  225. $modulePicker.$.setValue('');
  226. });
  227. }
  228. window.loadScopeTypes = function(e)
  229. {
  230. const libID = e.target.value;
  231. const link = $.createLink('doc', 'ajaxGetScopeTypes', 'libID=' + libID);
  232. $.get(link, function(data)
  233. {
  234. data = JSON.parse(data);
  235. const $modulePicker = $("[name='module']").zui('picker');
  236. $modulePicker.render({items: data});
  237. $modulePicker.$.setValue('');
  238. });
  239. }
  240. window.toggleWhiteList = function(e)
  241. {
  242. const acl = e.target.value;
  243. $('#whiteListBox').toggleClass('hidden', acl == 'open');
  244. $('#readListBox').toggleClass('hidden', acl == 'open');
  245. }
  246. $(document).on('mousedown', '.ajaxCollect', function (event)
  247. {
  248. if(event.button != 0) return;
  249. var obj = $(this);
  250. var url = obj.data('link');
  251. $.get(url, function(response)
  252. {
  253. if(response.status == 'yes')
  254. {
  255. obj.children('img').attr('src', 'static/svg/star.svg');
  256. obj.parent().prev().children('.file-name').children('i').remove('.icon');
  257. obj.parent().prev().children('.file-name').prepend('<i class="icon icon-star text-yellow"></i> ');
  258. }
  259. else
  260. {
  261. obj.children('img').attr('src', 'static/svg/star-empty.svg');
  262. obj.parent().prev().children('.file-name').children('i').remove(".icon");
  263. }
  264. }, 'json');
  265. return false;
  266. });
  267. window.updateOrder = function(event, orders)
  268. {
  269. const type = $(event.item).children('div').attr('data-type');
  270. let sortedIdList = {};
  271. for(let i in orders)
  272. {
  273. if(i != 'annex') sortedIdList['orders[' + orders[i] + ']'] = i;
  274. }
  275. sortedIdList['type'] = 'doc';
  276. if(type == 'module')
  277. {
  278. $.post($.createLink('doc', 'sortCatalog'), sortedIdList);
  279. }
  280. else if(type == 'docLib')
  281. {
  282. $.post($.createLink('doc', 'sortDoclib'), sortedIdList);
  283. }
  284. }
  285. window.canSortTo = function(e, from, to)
  286. {
  287. if(from['data-objectType'] != to['data-objectType']) return false;
  288. if(to['data-type'] == 'annex') return false;
  289. }
  290. window.checkObjectPriv = function(e)
  291. {
  292. $whiteListBox = $('#whiteListBox');
  293. if($whiteListBox.length == 0 || $whiteListBox.hasClass('hidden')) return;
  294. let $users = $('#whiteListBox [name^=users]');
  295. let users = $users.val();
  296. if(users.length == 0) return;
  297. let formData = new FormData();
  298. let $object = $('[name=' + libType + ']');
  299. let objectType = libType;
  300. let objectID = 0;
  301. if($object.length > 0) objectID = $object.val();
  302. if(libType == 'project')
  303. {
  304. let $execution = $('[name=execution]');
  305. if($execution.length > 0 && parseInt($execution.val()) > 0)
  306. {
  307. objectType = 'execution';
  308. objectID = $execution.val();
  309. }
  310. }
  311. if(objectID == 0) return;
  312. users.forEach(function(user){ formData.append('users[]', user); });
  313. $.post($.createLink('doc', 'ajaxCheckObjectPriv', 'libType=' + libType + '&objectID=' + objectID), formData, function(data)
  314. {
  315. $inputGroupBox = $users.closest('.input-group').parent();
  316. $inputGroupBox.find('.notice').remove();
  317. if(!data) return;
  318. $inputGroupBox.append("<div class='notice pt-1'>" + data + '</div>');
  319. });
  320. }
  321. window.checkLibPriv = function(id, formName)
  322. {
  323. $listBox = $(id);
  324. if($listBox.length == 0 || $listBox.hasClass('hidden')) return;
  325. let $users = $listBox.find(`[name^=${formName}]`);
  326. let users = $users.val();
  327. if(users.length == 0) return;
  328. let formData = new FormData();
  329. let libID = $('[name=lib]').val();
  330. users.forEach(function(user){ formData.append('users[]', user); });
  331. $.post($.createLink('doc', 'ajaxCheckLibPriv', 'libID=' + libID), formData, function(data)
  332. {
  333. $inputGroupBox = $users.closest('.input-group').parent();
  334. $inputGroupBox.find('.notice').remove();
  335. if(!data) return;
  336. $inputGroupBox.append("<div class='notice pt-1'>" + data + '</div>');
  337. });
  338. }