admin.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * Admin-area specific javascript functions.
  4. *
  5. * @since 1.8
  6. */
  7. ?>
  8. //<script>
  9. elgg.provide('elgg.admin');
  10. elgg.admin.init = function () {
  11. // system messages do not fade in admin area, instead slide up when clicked
  12. $('.elgg-system-messages li').stop(true);
  13. $('.elgg-system-messages li').die('click');
  14. $('.elgg-system-messages li').live('click', function() {
  15. $(this).stop().slideUp('medium');
  16. });
  17. // draggable plugin reordering
  18. $('#elgg-plugin-list > ul').sortable({
  19. items: 'li:has(> .elgg-state-draggable)',
  20. handle: '.elgg-head',
  21. forcePlaceholderSize: true,
  22. placeholder: 'elgg-widget-placeholder',
  23. opacity: 0.8,
  24. revert: 500,
  25. stop: elgg.admin.movePlugin
  26. });
  27. // in-line editing for custom profile fields.
  28. // @note this requires jquery.jeditable plugin
  29. $(".elgg-state-editable").editable(elgg.admin.editProfileField, {
  30. type: 'text',
  31. onblur: 'submit',
  32. width: '300px',
  33. height: 'none',
  34. style: 'display:inline;'
  35. });
  36. // draggable profile field reordering.
  37. $('#elgg-profile-fields').sortable({
  38. items: 'li',
  39. handle: 'span.elgg-state-draggable',
  40. stop: elgg.admin.moveProfileField
  41. });
  42. // admin notices delete ajax
  43. $('a.elgg-admin-notice').click(elgg.admin.deleteNotice);
  44. // disable checkboxes (readonly does not work for them)
  45. $('input:checkbox.elgg-state-disabled, label.elgg-state-disabled > input:checkbox')
  46. .live('click', function() {return false;});
  47. // disable simple cache compress settings if simple cache is off
  48. $('[name=simplecache_enabled]').click(elgg.admin.simplecacheToggle);
  49. };
  50. /**
  51. * Save the plugin order after a move event.
  52. *
  53. * @param {Object} e Event object.
  54. * @param {Object} ui jQueryUI object
  55. * @return void
  56. */
  57. elgg.admin.movePlugin = function(e, ui) {
  58. // get guid from id like elgg-object-<guid>
  59. var pluginGuid = ui.item.attr('id');
  60. pluginGuid = pluginGuid.replace('elgg-object-', '');
  61. elgg.action('admin/plugins/set_priority', {
  62. data: {
  63. plugin_guid: pluginGuid,
  64. // we start at priority 1
  65. priority: ui.item.index() + 1
  66. },
  67. success: function() {
  68. // update plugins with priority dependences
  69. var priorityDep = new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));
  70. ui.item.siblings().andSelf().each(function() {
  71. if (priorityDep.test($(this).find('.elgg-dependency-requires').text())) {
  72. elgg.admin.updatePluginView($(this));
  73. }
  74. });
  75. }
  76. });
  77. };
  78. /**
  79. * Update the plugin view.
  80. *
  81. * @param {Object} pluginView Plugin view element to update
  82. * @return void
  83. */
  84. elgg.admin.updatePluginView = function(pluginView) {
  85. // get guid from id like elgg-object-<guid>
  86. var pluginGuid = pluginView.attr('id');
  87. pluginGuid = pluginGuid.replace('elgg-object-', '');
  88. elgg.get({
  89. url: elgg.config.wwwroot + "ajax/view/object/plugin/full",
  90. dataType: "html",
  91. cache: false,
  92. data: {
  93. guid: pluginGuid,
  94. display_reordering: true
  95. },
  96. success: function(htmlData) {
  97. if (htmlData.length > 0) {
  98. pluginView.html(htmlData);
  99. }
  100. }
  101. });
  102. }
  103. /**
  104. * In-line editing for custom profile fields
  105. *
  106. * @param string value The new value
  107. * @param {Object} settings The settings used for editable
  108. * @return void
  109. */
  110. elgg.admin.editProfileField = function(value, settings) {
  111. var id = $(this).attr('id');
  112. id = id.replace('elgg-profile-field-', '');
  113. var data = {
  114. id: id,
  115. label: value
  116. };
  117. elgg.action('profile/fields/edit', data);
  118. return value;
  119. };
  120. /**
  121. * Save the plugin profile order after a move event.
  122. *
  123. * @param {Object} e Event object.
  124. * @param {Object} ui jQueryUI object
  125. * @return void
  126. */
  127. elgg.admin.moveProfileField = function(e, ui) {
  128. var orderArr = $('#elgg-profile-fields').sortable('toArray');
  129. var orderStr = orderArr.join(',');
  130. elgg.action('profile/fields/reorder', {
  131. fieldorder: orderStr
  132. });
  133. };
  134. /**
  135. * Fires the ajax action to delete the admin notice then hides the notice.
  136. *
  137. * @return void
  138. */
  139. elgg.admin.deleteNotice = function(e) {
  140. e.preventDefault();
  141. var $container = $(this).closest('p');
  142. elgg.action($(this).attr('href'), {
  143. success: function(json) {
  144. $container.slideUp('medium');
  145. }
  146. });
  147. };
  148. /**
  149. * Toggles the display of the compression settings for simplecache
  150. *
  151. * @return void
  152. */
  153. elgg.admin.simplecacheToggle = function() {
  154. // when the checkbox is disabled, do not toggle the compression checkboxes
  155. if (!$(this).hasClass('elgg-state-disabled')) {
  156. var names = ['simplecache_minify_js', 'simplecache_minify_css'];
  157. for (var i = 0; i < names.length; i++) {
  158. var $input = $('input[type!=hidden][name="' + names[i] + '"]');
  159. if ($input.length) {
  160. $input.parent().toggleClass('elgg-state-disabled');
  161. }
  162. }
  163. }
  164. };
  165. elgg.register_hook_handler('init', 'system', elgg.admin.init, 1000);