PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/web/concrete/js/ccm_app/ui.js

http://github.com/concrete5/concrete5
JavaScript | 813 lines | 667 code | 116 blank | 30 comment | 119 complexity | 947223c5a328c18ddea37b91cc5f6d5e MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. var ccm_arrangeMode = false;
  2. var ccm_selectedDomID = false;
  3. var ccm_isBlockError = false;
  4. var ccm_activeMenu = false;
  5. var ccm_blockError = false;
  6. ccm_menuInit = function(obj) {
  7. if (CCM_EDIT_MODE && (!CCM_ARRANGE_MODE)) {
  8. switch(obj.type) {
  9. case "BLOCK":
  10. $("#b" + obj.bID + "-" + obj.aID).mouseover(function(e) {
  11. ccm_activate(obj, "#b" + obj.bID + "-" + obj.aID);
  12. });
  13. break;
  14. case "AREA":
  15. $("#a" + obj.aID + "controls").mouseover(function(e) {
  16. ccm_activate(obj, "#a" + obj.aID + "controls");
  17. });
  18. break;
  19. }
  20. }
  21. }
  22. ccm_showBlockMenu = function(obj, e) {
  23. ccm_hideMenus();
  24. e.stopPropagation();
  25. ccm_activeMenu = true;
  26. // now, check to see if this menu has been made
  27. var bobj = document.getElementById("ccm-block-menu" + obj.bID + "-" + obj.aID);
  28. if (!bobj) {
  29. // create the 1st instance of the menu
  30. el = document.createElement("DIV");
  31. el.id = "ccm-block-menu" + obj.bID + "-" + obj.aID;
  32. el.className = "ccm-menu ccm-ui";
  33. el.style.display = "block";
  34. el.style.visibility = "hidden";
  35. document.body.appendChild(el);
  36. bobj = $("#ccm-block-menu" + obj.bID + "-" + obj.aID);
  37. bobj.css("position", "absolute");
  38. //contents of menu
  39. var html = '<div class="popover"><div class="arrow"></div><div class="inner"><div class="content">';
  40. html += '<ul>';
  41. //html += '<li class="header"></li>';
  42. if (obj.canWrite && obj.hasEditDialog) {
  43. html += (obj.editInline) ? '<li><a class="ccm-menu-icon ccm-icon-edit-menu" onclick="ccm_hideMenus()" id="menuEdit' + obj.bID + '-' + obj.aID + '" href="' + CCM_DISPATCHER_FILENAME + '?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=edit#_edit' + obj.bID + '">' + ccmi18n.editBlock + '</a></li>'
  44. : '<li><a class="ccm-menu-icon ccm-icon-edit-menu" onclick="ccm_hideMenus()" dialog-title="' + ccmi18n.editBlock + ' ' + obj.btName + '" dialog-append-buttons="true" dialog-modal="false" dialog-on-close="ccm_blockWindowAfterClose()" dialog-width="' + obj.width + '" dialog-height="' + obj.height + '" id="menuEdit' + obj.bID + '-' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_block_popup.php?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=edit">' + ccmi18n.editBlock + '</a></li>';
  45. }
  46. if (obj.canWriteStack) {
  47. html += '<li><a class="ccm-menu-icon ccm-icon-edit-menu" id="menuEdit' + obj.bID + '-' + obj.aID + '" href="' + CCM_DISPATCHER_FILENAME + '/dashboard/blocks/stacks/-/view_details/' + obj.stID + '">' + ccmi18n.editStackContents + '</a></li>'
  48. html += '<li class="header"></li>';
  49. }
  50. if (obj.canCopyToScrapbook) {
  51. html += '<li><a class="ccm-menu-icon ccm-icon-clipboard-menu" id="menuAddToScrapbook' + obj.bID + '-' + obj.aID + '" href="#" onclick="javascript:ccm_addToScrapbook(' + obj.cID + ',' + obj.bID + ',\'' + encodeURIComponent(obj.arHandle) + '\');return false;">' + ccmi18n.copyBlockToScrapbook + '</a></li>';
  52. }
  53. if (obj.canArrange) {
  54. html += '<li><a class="ccm-menu-icon ccm-icon-move-menu" id="menuArrange' + obj.bID + '-' + obj.aID + '" href="javascript:ccm_arrangeInit()">' + ccmi18n.arrangeBlock + '</a></li>';
  55. }
  56. if (obj.canDelete) {
  57. html += '<li><a class="ccm-menu-icon ccm-icon-delete-menu" id="menuDelete' + obj.bID + '-' + obj.aID + '" href="#" onclick="javascript:ccm_deleteBlock(' + obj.cID + ',' + obj.bID + ',' + obj.aID + ', \'' + encodeURIComponent(obj.arHandle) + '\', \'' + obj.deleteMessage + '\');return false;">' + ccmi18n.deleteBlock + '</a></li>';
  58. }
  59. if (obj.canDesign || obj.canWrite) {
  60. html += '<li class="ccm-menu-separator"></li>';
  61. }
  62. if (obj.canDesign) {
  63. html += '<li><a class="ccm-menu-icon ccm-icon-design-menu" onclick="ccm_hideMenus()" dialog-modal="false" dialog-title="' + ccmi18n.changeBlockBaseStyle + '" dialog-width="475" dialog-height="500" dialog-append-buttons="true" id="menuChangeCSS' + obj.bID + '-' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_block_popup.php?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=block_css&modal=true&width=300&height=100" title="' + ccmi18n.changeBlockCSS + '">' + ccmi18n.changeBlockCSS + '</a></li>';
  64. }
  65. if (obj.canWrite) {
  66. html += '<li><a class="ccm-menu-icon ccm-icon-custom-template-menu" onclick="ccm_hideMenus()" dialog-append-buttons="true" dialog-modal="false" dialog-title="' + ccmi18n.changeBlockTemplate + '" dialog-width="300" dialog-height="275" id="menuChangeTemplate' + obj.bID + '-' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_block_popup.php?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=template&modal=true&width=300&height=275" title="' + ccmi18n.changeBlockTemplate + '">' + ccmi18n.changeBlockTemplate + '</a></li>';
  67. }
  68. if (obj.canModifyGroups || obj.canAliasBlockOut || obj.canSetupComposer) {
  69. html += '<li class="ccm-menu-separator"></li>';
  70. }
  71. if (obj.canModifyGroups) {
  72. html += '<li><a title="' + ccmi18n.setBlockPermissions + '" onclick="ccm_hideMenus()" class="ccm-menu-icon ccm-icon-permissions-menu" dialog-width="400" dialog-height="390" id="menuBlockGroups' + obj.bID + '-' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_block_popup.php?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=groups" dialog-append-buttons="true" dialog-title="' + ccmi18n.setBlockPermissions + '">' + ccmi18n.setBlockPermissions + '</a></li>';
  73. }
  74. if (obj.canAliasBlockOut) {
  75. html += '<li><a class="ccm-menu-icon ccm-icon-setup-child-pages-menu" dialog-append-buttons="true" onclick="ccm_hideMenus()" dialog-width="550" dialog-height="450" id="menuBlockAliasOut' + obj.bID + '-' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_block_popup.php?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=child_pages" dialog-title="' + ccmi18n.setBlockAlias + '">' + ccmi18n.setBlockAlias + '</a></li>';
  76. }
  77. if (obj.canSetupComposer) {
  78. html += '<li><a class="ccm-menu-icon ccm-icon-setup-composer-menu" dialog-append-buttons="true" onclick="ccm_hideMenus()" dialog-width="300" dialog-modal="false" dialog-height="130" id="menuBlockSetupComposer' + obj.bID + '-' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_block_popup.php?cID=' + obj.cID + '&bID=' + obj.bID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&btask=composer" dialog-title="' + ccmi18n.setBlockComposerSettings + '">' + ccmi18n.setBlockComposerSettings + '</a></li>';
  79. }
  80. html += '</ul>';
  81. html += '</div></div></div>';
  82. bobj.append(html);
  83. // add dialog elements where necessary
  84. if (obj.canWrite && (!obj.editInline)) {
  85. $('a#menuEdit' + obj.bID + '-' + obj.aID).dialog();
  86. $('a#menuChangeTemplate' + obj.bID + '-' + obj.aID).dialog();
  87. }
  88. if (obj.canDesign) {
  89. $('a#menuChangeCSS' + obj.bID + '-' + obj.aID).dialog();
  90. }
  91. if (obj.canAliasBlockOut) {
  92. $('a#menuBlockAliasOut' + obj.bID + '-' + obj.aID).dialog();
  93. }
  94. if (obj.canSetupComposer) {
  95. $('a#menuBlockSetupComposer' + obj.bID + '-' + obj.aID).dialog();
  96. }
  97. if (obj.canModifyGroups) {
  98. $("#menuBlockGroups" + obj.bID + '-' + obj.aID).dialog();
  99. }
  100. } else {
  101. bobj = $("#ccm-block-menu" + obj.bID + '-' + obj.aID);
  102. }
  103. ccm_fadeInMenu(bobj, e);
  104. }
  105. ccm_openAreaAddBlock = function(arHandle, addOnly, cID) {
  106. if (!addOnly) {
  107. addOnly = 0;
  108. }
  109. if (!cID) {
  110. cID = CCM_CID;
  111. }
  112. $.fn.dialog.open({
  113. title: ccmi18n.blockAreaMenu,
  114. href: CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + cID + '&atask=add&arHandle=' + arHandle + '&addOnly=' + addOnly,
  115. width: 550,
  116. modal: false,
  117. height: 380
  118. });
  119. }
  120. ccm_showAreaMenu = function(obj, e) {
  121. var addOnly = (obj.addOnly)?1:0;
  122. ccm_activeMenu = true;
  123. if (e.shiftKey) {
  124. ccm_openAreaAddBlock(obj.arHandle, addOnly);
  125. } else {
  126. e.stopPropagation();
  127. // now, check to see if this menu has been made
  128. var aobj = document.getElementById("ccm-area-menu" + obj.aID);
  129. if (!aobj) {
  130. // create the 1st instance of the menu
  131. el = document.createElement("DIV");
  132. el.id = "ccm-area-menu" + obj.aID;
  133. el.className = "ccm-menu ccm-ui";
  134. el.style.display = "block";
  135. el.style.visibility = "hidden";
  136. document.body.appendChild(el);
  137. aobj = $("#ccm-area-menu" + obj.aID);
  138. aobj.css("position", "absolute");
  139. //contents of menu
  140. var html = '<div class="popover"><div class="arrow"></div><div class="inner"><div class="content">';
  141. html += '<ul>';
  142. //html += '<li class="header"></li>';
  143. if (obj.canAddBlocks) {
  144. html += '<li><a onclick="ccm_hideMenus()" class="ccm-menu-icon ccm-icon-add-block-menu" dialog-title="' + ccmi18n.addBlockNew + '" dialog-modal="false" dialog-width="550" dialog-height="380" id="menuAddNewBlock' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + CCM_CID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&atask=add&addOnly=' + addOnly + '">'+ ccmi18n.addBlockNew + '</a></li>';
  145. html += '<li><a onclick="ccm_hideMenus()" class="ccm-menu-icon ccm-icon-add-stack-menu" dialog-title="' + ccmi18n.addBlockStack + '" dialog-modal="false" dialog-width="550" dialog-height="380" id="menuAddNewStack' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + CCM_CID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&atask=add_from_stack&addOnly=' + addOnly + '">' + ccmi18n.addBlockStack + '</a></li>';
  146. html += '<li><a onclick="ccm_hideMenus()" class="ccm-menu-icon ccm-icon-clipboard-menu" dialog-title="' + ccmi18n.addBlockPaste + '" dialog-modal="false" dialog-width="550" dialog-height="380" id="menuAddPaste' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + CCM_CID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&atask=paste&addOnly=' + addOnly + '">' + ccmi18n.addBlockPaste + '</a></li>';
  147. }
  148. if (obj.canAddBlocks && (obj.canDesign || obj.canLayout)) {
  149. html += '<li class="ccm-menu-separator"></li>';
  150. }
  151. if (obj.canLayout) {
  152. html += '<li><a onclick="ccm_hideMenus()" class="ccm-menu-icon ccm-icon-add-layout-menu" dialog-title="' + ccmi18n.addAreaLayout + '" dialog-modal="false" dialog-width="400" dialog-height="300" dialog-append-buttons="true" id="menuAreaLayout' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + CCM_CID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&atask=layout">' + ccmi18n.addAreaLayout + '</a></li>';
  153. }
  154. if (obj.canDesign) {
  155. html += '<li><a onclick="ccm_hideMenus()" class="ccm-menu-icon ccm-icon-design-menu" dialog-title="' + ccmi18n.changeAreaCSS + '" dialog-modal="false" dialog-append-buttons="true" dialog-width="475" dialog-height="500" id="menuAreaStyle' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + CCM_CID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&atask=design">' + ccmi18n.changeAreaCSS + '</a></li>';
  156. }
  157. if (obj.canWrite && obj.canModifyGroups) {
  158. html += '<li class="ccm-menu-separator"></li>';
  159. }
  160. if (obj.canModifyGroups) {
  161. html += '<li><a onclick="ccm_hideMenus()" title="' + ccmi18n.setAreaPermissions + '" dialog-append-buttons="true" dialog-modal="false" class="ccm-menu-icon ccm-icon-permissions-menu" dialog-width="580" dialog-height="420" id="menuAreaGroups' + obj.aID + '" href="' + CCM_TOOLS_PATH + '/edit_area_popup.php?cID=' + CCM_CID + '&arHandle=' + encodeURIComponent(obj.arHandle) + '&atask=groups" dialog-title="' + ccmi18n.setAreaPermissions + '">' + ccmi18n.setAreaPermissions + '</a></li>';
  162. }
  163. html += '</ul>';
  164. html += '</div></div></div>';
  165. aobj.append(html);
  166. // add dialog elements where necessary
  167. if (obj.canAddBlocks) {
  168. $('a#menuAddNewBlock' + obj.aID).dialog();
  169. $('a#menuAddNewStack' + obj.aID).dialog();
  170. $('a#menuAddPaste' + obj.aID).dialog();
  171. }
  172. if (obj.canWrite) {
  173. $('a#menuAreaStyle' + obj.aID).dialog();
  174. $('a#menuAreaLayout' + obj.aID).dialog();
  175. }
  176. if (obj.canModifyGroups) {
  177. $('a#menuAreaGroups' + obj.aID).dialog();
  178. }
  179. } else {
  180. aobj = $("#ccm-area-menu" + obj.aID);
  181. }
  182. ccm_fadeInMenu(aobj, e);
  183. }
  184. }
  185. ccm_hideHighlighter = function() {
  186. $("#ccm-highlighter").css('display', 'none');
  187. $('div.ccm-menu-hotspot-active').removeClass('ccm-menu-hotspot-active');
  188. }
  189. ccm_addError = function(err) {
  190. if (!ccm_isBlockError) {
  191. ccm_blockError = '';
  192. ccm_blockError += '<ul>';
  193. }
  194. ccm_isBlockError = true;
  195. ccm_blockError += "<li>" + err + "</li>";;
  196. }
  197. ccm_resetBlockErrors = function() {
  198. ccm_isBlockError = false;
  199. ccm_blockError = "";
  200. }
  201. ccm_addToScrapbook = function(cID, bID, arHandle) {
  202. ccm_mainNavDisableDirectExit();
  203. // got to grab the message too, eventually
  204. ccm_hideHighlighter();
  205. $.ajax({
  206. type: 'POST',
  207. url: CCM_TOOLS_PATH + '/pile_manager.php',
  208. data: 'cID=' + cID + '&bID=' + bID + '&arHandle=' + arHandle + '&btask=add&scrapbookName=userScrapbook',
  209. success: function(resp) {
  210. ccm_hideHighlighter();
  211. ccmAlert.hud(ccmi18n.copyBlockToScrapbookMsg, 2000, 'add', ccmi18n.copyBlockToScrapbook);
  212. }});
  213. }
  214. ccm_deleteBlock = function(cID, bID, aID, arHandle, msg) {
  215. if (confirm(msg)) {
  216. ccm_mainNavDisableDirectExit();
  217. // got to grab the message too, eventually
  218. ccm_hideHighlighter();
  219. $d = $("#b" + bID + '-' + aID);
  220. $d.hide();
  221. ccmAlert.hud(ccmi18n.deleteBlockMsg, 2000, 'delete_small', ccmi18n.deleteBlock);
  222. $.ajax({
  223. type: 'POST',
  224. url: CCM_DISPATCHER_FILENAME,
  225. data: 'cID=' + cID + '&ccm_token=' + CCM_SECURITY_TOKEN + '&isAjax=true&btask=remove&bID=' + bID + '&arHandle=' + arHandle
  226. })
  227. }
  228. }
  229. ccm_hideMenus = function() {
  230. /* 1st, hide all items w/the css menu class */
  231. ccm_activeMenu = false;
  232. $("div.ccm-menu").hide();
  233. $("div.ccm-menu").css('visibility', 'hidden');
  234. $("div.ccm-menu").show();
  235. }
  236. ccm_parseBlockResponse = function(r, currentBlockID, task) {
  237. try {
  238. r = r.replace(/(<([^>]+)>)/ig,""); // because some plugins add bogus HTML after our JSON requests and screw everything up
  239. resp = eval('(' + r + ')');
  240. if (resp.error == true) {
  241. var message = '<ul>'
  242. for (i = 0; i < resp.response.length; i++) {
  243. message += '<li>' + resp.response[i] + '<\/li>';
  244. }
  245. message += '<\/ul>';
  246. ccmAlert.notice(ccmi18n.error, message);
  247. } else {
  248. ccm_blockWindowClose();
  249. if (resp.cID) {
  250. cID = resp.cID;
  251. } else {
  252. cID = CCM_CID;
  253. }
  254. var action = CCM_TOOLS_PATH + '/edit_block_popup?cID=' + cID + '&bID=' + resp.bID + '&arHandle=' + encodeURIComponent(resp.arHandle) + '&btask=view_edit_mode';
  255. $.get(action,
  256. function(r) {
  257. if (task == 'add') {
  258. if ($("#a" + resp.aID + " div.ccm-area-styles-a"+ resp.aID).length > 0) {
  259. $("#a" + resp.aID + " div.ccm-area-styles-a"+ resp.aID).append(r);
  260. } else {
  261. $("#a" + resp.aID).append(r);
  262. }
  263. } else {
  264. $('#b' + currentBlockID + '-' + resp.aID).before(r).remove();
  265. }
  266. jQuery.fn.dialog.hideLoader();
  267. ccm_mainNavDisableDirectExit();
  268. if (task == 'add') {
  269. ccmAlert.hud(ccmi18n.addBlockMsg, 2000, 'add', ccmi18n.addBlock);
  270. jQuery.fn.dialog.closeAll();
  271. } else {
  272. ccmAlert.hud(ccmi18n.updateBlockMsg, 2000, 'success', ccmi18n.updateBlock);
  273. }
  274. if (typeof window.ccm_parseBlockResponsePost == 'function') {
  275. ccm_parseBlockResponsePost(resp);
  276. }
  277. }
  278. );
  279. }
  280. } catch(e) {
  281. ccmAlert.notice(ccmi18n.error, r);
  282. }
  283. }
  284. ccm_mainNavDisableDirectExit = function(disableShow) {
  285. // make sure that exit edit mode is enabled
  286. $("#ccm-exit-edit-mode-direct").hide();
  287. if (!disableShow) {
  288. $("#ccm-exit-edit-mode-comment").show();
  289. }
  290. }
  291. ccm_setupBlockForm = function(form, currentBlockID, task) {
  292. form.ajaxForm({
  293. type: 'POST',
  294. iframe: true,
  295. beforeSubmit: function() {
  296. ccm_hideHighlighter();
  297. $('input[name=ccm-block-form-method]').val('AJAX');
  298. jQuery.fn.dialog.showLoader();
  299. return ccm_blockFormSubmit();
  300. },
  301. success: function(r) {
  302. ccm_parseBlockResponse(r, currentBlockID, task);
  303. }
  304. });
  305. }
  306. ccm_activate = function(obj, domID) {
  307. if (ccm_arrangeMode || ccm_activeMenu) {
  308. return false;
  309. }
  310. if (ccm_selectedDomID) {
  311. $(ccm_selectedDomID).removeClass('ccm-menu-hotspot-active');
  312. }
  313. aobj = $(domID);
  314. aobj.addClass('ccm-menu-hotspot-active');
  315. ccm_selectedDomID = domID;
  316. offs = aobj.offset();
  317. $("#ccm-highlighter").hide();
  318. $("#ccm-highlighter").css("width", aobj.outerWidth());
  319. $("#ccm-highlighter").css("height", aobj.outerHeight());
  320. $("#ccm-highlighter").css("top", offs.top);
  321. $("#ccm-highlighter").css("left", offs.left);
  322. $("#ccm-highlighter").fadeIn(120, 'easeOutExpo');
  323. /*
  324. $("#ccmMenuHighlighter").mouseover(
  325. function() {clearTimeout(ccm_deactivateTimer)}
  326. );
  327. */
  328. $("#ccm-highlighter").mouseout(function(e) {
  329. if (!ccm_activeMenu) {
  330. if (!e.target) {
  331. ccm_hideHighlighter();
  332. } else if ($(e.toElement).parents('div.ccm-menu').length == 0) {
  333. ccm_hideHighlighter();
  334. }
  335. }
  336. });
  337. $("#ccm-highlighter").unbind('click');
  338. $("#ccm-highlighter").click(
  339. function(e) {
  340. switch(obj.type) {
  341. case "BLOCK":
  342. ccm_showBlockMenu(obj, e);
  343. break;
  344. case "AREA":
  345. ccm_showAreaMenu(obj,e);
  346. break;
  347. }
  348. }
  349. );
  350. }
  351. ccm_editInit = function() {
  352. document.write = function() {
  353. // stupid javascript in html blocks
  354. void(0);
  355. }
  356. $(document.body).append('<div style="position: absolute; display:none" id="ccm-highlighter">&nbsp;</div>');
  357. $(document).click(function() {ccm_hideMenus();});
  358. $("div.ccm-menu a").bind('click.hide-menu', function(e) {
  359. ccm_hideMenus();
  360. return false;
  361. });
  362. }
  363. ccm_triggerSelectUser = function(uID, uName, uEmail) {
  364. alert(uID);
  365. alert(uName);
  366. alert(uEmail);
  367. }
  368. ccm_setupUserSearch = function() {
  369. $(".chosen-select").chosen();
  370. $("#ccm-user-list-cb-all").click(function() {
  371. if ($(this).prop('checked') == true) {
  372. $('.ccm-list-record td.ccm-user-list-cb input[type=checkbox]').attr('checked', true);
  373. $("#ccm-user-list-multiple-operations").attr('disabled', false);
  374. } else {
  375. $('.ccm-list-record td.ccm-user-list-cb input[type=checkbox]').attr('checked', false);
  376. $("#ccm-user-list-multiple-operations").attr('disabled', true);
  377. }
  378. });
  379. $("td.ccm-user-list-cb input[type=checkbox]").click(function(e) {
  380. if ($("td.ccm-user-list-cb input[type=checkbox]:checked").length > 0) {
  381. $("#ccm-user-list-multiple-operations").attr('disabled', false);
  382. } else {
  383. $("#ccm-user-list-multiple-operations").attr('disabled', true);
  384. }
  385. });
  386. // if we're not in the dashboard, add to the multiple operations select menu
  387. $("#ccm-user-list-multiple-operations").change(function() {
  388. var action = $(this).val();
  389. switch(action) {
  390. case 'choose':
  391. var idstr = '';
  392. $("td.ccm-user-list-cb input[type=checkbox]:checked").each(function() {
  393. ccm_triggerSelectUser($(this).val(), $(this).attr('user-name'), $(this).attr('user-email'));
  394. });
  395. jQuery.fn.dialog.closeTop();
  396. break;
  397. case "properties":
  398. uIDstring = '';
  399. $("td.ccm-user-list-cb input[type=checkbox]:checked").each(function() {
  400. uIDstring=uIDstring+'&uID[]='+$(this).val();
  401. });
  402. jQuery.fn.dialog.open({
  403. width: 630,
  404. height: 450,
  405. modal: false,
  406. href: CCM_TOOLS_PATH + '/users/bulk_properties?' + uIDstring,
  407. title: ccmi18n.properties
  408. });
  409. break;
  410. }
  411. $(this).get(0).selectedIndex = 0;
  412. });
  413. }
  414. ccm_triggerSelectGroup = function(gID, gName) {
  415. alert(gID);
  416. alert(gName);
  417. }
  418. ccm_setupGroupSearchPaging = function() {
  419. $("div#ccm-group-paging").each(function() {
  420. $(this).closest('.ui-dialog-content').dialog('option', 'buttons', [{}]);
  421. $(this).closest('.ui-dialog').find('.ui-dialog-buttonpane .ccm-pane-dialog-pagination').remove();
  422. $(this).appendTo($(this).closest('.ui-dialog').find('.ui-dialog-buttonpane').addClass('ccm-ui'));
  423. });
  424. }
  425. ccm_setupGroupSearch = function() {
  426. $('div.ccm-group a').unbind();
  427. $('div.ccm-group a').each(function(i) {
  428. var gla = $(this);
  429. $(this).click(function() {
  430. ccm_triggerSelectGroup(gla.attr('group-id'), gla.attr('group-name'));
  431. $.fn.dialog.closeTop();
  432. return false;
  433. });
  434. });
  435. $("#ccm-group-search").ajaxForm({
  436. beforeSubmit: function() {
  437. $("#ccm-group-search-wrapper").html("");
  438. },
  439. success: function(resp) {
  440. $("#ccm-group-search-wrapper").html(resp);
  441. }
  442. });
  443. /* setup paging */
  444. ccm_setupGroupSearchPaging();
  445. $("div#ccm-group-paging a").click(function() {
  446. $("#ccm-group-search-wrapper").html("");
  447. $.ajax({
  448. type: "GET",
  449. url: $(this).attr('href'),
  450. success: function(resp) {
  451. //$("#ccm-dialog-throbber").css('visibility','hidden');
  452. $("#ccm-group-search-wrapper").html(resp);
  453. }
  454. });
  455. return false;
  456. });
  457. }
  458. ccm_saveArrangement = function(cID) {
  459. if (!cID) {
  460. cID = CCM_CID;
  461. }
  462. ccm_mainNavDisableDirectExit();
  463. var serial = '';
  464. $('div.ccm-area').each(function() {
  465. areaStr = '&area[' + $(this).attr('id').substring(1) + '][]=';
  466. bArray = $(this).sortable('toArray');
  467. for (i = 0; i < bArray.length; i++ ) {
  468. if (bArray[i] != '' && bArray[i].substring(0, 1) == 'b') {
  469. // make sure to only go from b to -, meaning b28-9 becomes "28"
  470. var bID = bArray[i].substring(1, bArray[i].indexOf('-'));
  471. var bObj = $('#' + bArray[i]);
  472. if (bObj.attr('custom-style')) {
  473. bID += '-' + bObj.attr('custom-style');
  474. }
  475. serial += areaStr + bID;
  476. }
  477. }
  478. });
  479. $.ajax({
  480. type: 'POST',
  481. url: CCM_DISPATCHER_FILENAME,
  482. data: 'cID=' + cID + '&ccm_token=' + CCM_SECURITY_TOKEN + '&btask=ajax_do_arrange' + serial,
  483. success: function(msg) {
  484. $("div.ccm-area").removeClass('ccm-move-mode');
  485. $('div.ccm-block-arrange').each(function() {
  486. $(this).addClass('ccm-block');
  487. $(this).removeClass('ccm-block-arrange');
  488. });
  489. ccm_arrangeMode = false;
  490. $(".ccm-main-nav-edit-option").fadeIn(300);
  491. ccmAlert.hud(ccmi18n.arrangeBlockMsg, 2000, 'up_down', ccmi18n.arrangeBlock);
  492. }});
  493. }
  494. ccm_arrangeInit = function() {
  495. //$(document.body).append('<img src="' + CCM_IMAGE_PATH + '/topbar_throbber.gif" width="16" height="16" id="ccm-topbar-loader" />');
  496. ccm_arrangeMode = true;
  497. ccm_hideHighlighter();
  498. $('div.ccm-block').each(function() {
  499. $(this).addClass('ccm-block-arrange');
  500. $(this).removeClass('ccm-block');
  501. });
  502. $(".ccm-main-nav-edit-option").fadeOut(300, function() {
  503. $(".ccm-main-nav-arrange-option").fadeIn(300);
  504. });
  505. $("div.ccm-area").each(function() {
  506. var cID = $(this).attr('cID');
  507. $(this).addClass('ccm-move-mode');
  508. $(this).sortable({
  509. items: 'div.ccm-block-arrange',
  510. connectWith: $("div.ccm-area"),
  511. accept: 'div.ccm-block-arrange',
  512. opacity: 0.5,
  513. stop: function() {
  514. ccm_saveArrangement(cID);
  515. }
  516. });
  517. });
  518. }
  519. if (typeof(ccm_selectSitemapNode) != 'function') {
  520. ccm_selectSitemapNode = function(cID, cName) {
  521. alert(cID);
  522. alert(cName);
  523. }
  524. }
  525. ccm_goToSitemapNode = function(cID, cName) {
  526. window.location.href= CCM_DISPATCHER_FILENAME + '?cID=' + cID;
  527. }
  528. ccm_fadeInMenu = function(bobj, e) {
  529. var mwidth = bobj.find('div.popover div.inner').width();
  530. var mheight = bobj.find('div.popover').height();
  531. bobj.hide();
  532. bobj.css('visibility', 'visible');
  533. var posX = e.pageX + 2;
  534. var posY = e.pageY + 2;
  535. if ($(window).height() < e.clientY + mheight) {
  536. posY = posY - mheight - 10;
  537. posX = posX - (mwidth / 2);
  538. bobj.find('div.popover').removeClass('below');
  539. bobj.find('div.popover').addClass('above');
  540. } else {
  541. posX = posX - (mwidth / 2);
  542. posY = posY + 10;
  543. bobj.find('div.popover').removeClass('above');
  544. bobj.find('div.popover').addClass('below');
  545. }
  546. bobj.css("top", posY + "px");
  547. bobj.css("left", posX + "px");
  548. bobj.fadeIn(60);
  549. }
  550. ccm_blockWindowClose = function() {
  551. jQuery.fn.dialog.closeTop();
  552. ccm_blockWindowAfterClose();
  553. }
  554. ccm_blockWindowAfterClose = function() {
  555. ccmValidateBlockForm = function() {return true;}
  556. }
  557. ccm_blockFormSubmit = function() {
  558. if (typeof window.ccmValidateBlockForm == 'function') {
  559. r = window.ccmValidateBlockForm();
  560. if (!r) {
  561. jQuery.fn.dialog.hideLoader();
  562. }
  563. if (ccm_isBlockError) {
  564. if(ccm_blockError) {
  565. ccmAlert.notice(ccmi18n.error, ccm_blockError + '</ul>');
  566. }
  567. ccm_resetBlockErrors();
  568. return false;
  569. }
  570. }
  571. return true;
  572. }
  573. ccm_paneToggleOptions = function(obj) {
  574. var pane = $(obj).parent().find('div.ccm-pane-options-content');
  575. if ($(obj).hasClass('ccm-icon-option-closed')) {
  576. $(obj).removeClass('ccm-icon-option-closed').addClass('ccm-icon-option-open');
  577. pane.slideDown('fast', 'easeOutExpo');
  578. } else {
  579. $(obj).removeClass('ccm-icon-option-open').addClass('ccm-icon-option-closed');
  580. pane.slideUp('fast', 'easeOutExpo');
  581. }
  582. }
  583. ccm_setupGridStriping = function(tbl) {
  584. $("#" + tbl + " tr").removeClass();
  585. var j = 0;
  586. $("#" + tbl + " tr").each(function() {
  587. if ($(this).css('display') != 'none') {
  588. if (j % 2 == 0) {
  589. $(this).addClass('ccm-row-alt');
  590. }
  591. j++;
  592. }
  593. });
  594. }
  595. ccm_dashboardRequestRemoteInformation = function() {
  596. $.get(CCM_TOOLS_PATH + '/dashboard/get_remote_information');
  597. }
  598. /**
  599. * JavaScript localization. Provide a key and then reference that key in PHP somewhere (where it will be translated)
  600. */
  601. ccm_t = function(key) {
  602. return $("input[name=ccm-string-" + key + "]").val();
  603. }
  604. /* Block Styles Customization Popup */
  605. var ccmCustomStyle = {
  606. tabs:function(aLink,tab){
  607. $('.ccm-styleEditPane').hide();
  608. $('#ccm-styleEditPane-'+tab).show();
  609. $(aLink.parentNode.parentNode).find('li').removeClass('ccm-nav-active');
  610. $(aLink.parentNode).addClass('ccm-nav-active');
  611. return false;
  612. },
  613. resetAll:function(){
  614. if (!confirm( ccmi18n.confirmCssReset)) {
  615. return false;
  616. }
  617. jQuery.fn.dialog.showLoader();
  618. $('#ccm-reset-style').val(1);
  619. $('#ccmCustomCssForm').get(0).submit();
  620. return true;
  621. },
  622. showPresetDeleteIcon: function() {
  623. if ($('select[name=cspID]').val() > 0) {
  624. $("#ccm-style-delete-preset").show();
  625. } else {
  626. $("#ccm-style-delete-preset").hide();
  627. }
  628. },
  629. deletePreset: function() {
  630. var cspID = $('select[name=cspID]').val();
  631. if (cspID > 0) {
  632. if( !confirm(ccmi18n.confirmCssPresetDelete) ) return false;
  633. var action = $('#ccm-custom-style-refresh-action').val() + '&deleteCspID=' + cspID + '&subtask=delete_custom_style_preset';
  634. jQuery.fn.dialog.showLoader();
  635. $.get(action, function(r) {
  636. $("#ccm-custom-style-wrapper").html(r);
  637. jQuery.fn.dialog.hideLoader();
  638. });
  639. }
  640. },
  641. initForm: function() {
  642. if ($("#cspFooterPreset").length > 0) {
  643. $("#ccmCustomCssFormTabs input, #ccmCustomCssFormTabs select, #ccmCustomCssFormTabs textarea").bind('change click', function() {
  644. $("#cspFooterPreset").show();
  645. $("#cspFooterNoPreset").remove();
  646. $("#ccmCustomCssFormTabs input, #ccmCustomCssFormTabs select").unbind('change click');
  647. });
  648. }
  649. $('input[name=cspPresetAction]').click(function() {
  650. if ($(this).val() == 'create_new_preset' && $(this).prop('checked')) {
  651. $('input[name=cspName]').attr('disabled', false).focus();
  652. } else {
  653. $('input[name=cspName]').val('').attr('disabled', true);
  654. }
  655. });
  656. ccmCustomStyle.showPresetDeleteIcon();
  657. ccmCustomStyle.lastPresetID=parseInt($('select[name=cspID]').val());
  658. $('select[name=cspID]').change(function(){
  659. var cspID = parseInt($(this).val());
  660. var selectedCsrID = parseInt($('input[name=selectedCsrID]').val());
  661. if(ccmCustomStyle.lastPresetID==cspID) return false;
  662. ccmCustomStyle.lastPresetID=cspID;
  663. jQuery.fn.dialog.showLoader();
  664. if (cspID > 0) {
  665. var action = $('#ccm-custom-style-refresh-action').val() + '&cspID=' + cspID;
  666. } else {
  667. var action = $('#ccm-custom-style-refresh-action').val() + '&csrID=' + selectedCsrID;
  668. }
  669. $.get(action, function(r) {
  670. $("#ccm-custom-style-wrapper").html(r);
  671. jQuery.fn.dialog.hideLoader();
  672. });
  673. });
  674. $('#ccmCustomCssForm').submit(function() {
  675. if ($('input[name=cspCreateNew]').prop('checked') == true) {
  676. if ($('input[name=cspName]').val() == '') {
  677. $('input[name=cspName]').focus();
  678. alert(ccmi18n.errorCustomStylePresetNoName);
  679. return false;
  680. }
  681. }
  682. jQuery.fn.dialog.showLoader();
  683. return true;
  684. });
  685. //IE bug fix 0 can't focus on txt fields if new block just added
  686. if(!parseInt(ccmCustomStyle.lastPresetID))
  687. setTimeout('$("#ccmCustomCssFormTabs input").attr("disabled", false).get(0).focus()',500);
  688. },
  689. validIdCheck:function(el,prevID){
  690. var selEl = $('#'+el.value);
  691. if( selEl && selEl.get(0) && selEl.get(0).id!=prevID ){
  692. $('#ccm-styles-invalid-id').css('display','block');
  693. }else{
  694. $('#ccm-styles-invalid-id').css('display','none');
  695. }
  696. }
  697. };