Elgg  Version 2.3
admin.js
Go to the documentation of this file.
1 
6 define(function(require) {
7  var $ = require('jquery');
8  var ui = require('jquery-ui');
9  var elgg = require('elgg');
10  var spinner = require('elgg/spinner');
11  var Ajax = require('elgg/Ajax');
12 
13  var ajax = new Ajax();
14 
15  function init () {
16  // system messages do not fade in admin area, instead slide up when clicked
17  $('.elgg-system-messages li').stop(true);
18  $(document).off('click', '.elgg-system-messages li');
19  $(document).on('click', '.elgg-system-messages li', function(e) {
20  if (!$(e.target).is('a')) {
21  $(this).stop().slideUp('medium');
22  }
23  });
24 
25  initPluginReordering();
26 
27  // in-line editing for custom profile fields.
28  // @note this requires jquery.jeditable plugin
29  $(".elgg-state-editable").editable(editProfileField, {
30  type: 'text',
31  onblur: 'submit',
32  width: '300px',
33  height: 'none',
34  style: 'display:inline;'
35  });
36 
37  // draggable profile field reordering.
38  $('#elgg-profile-fields').sortable({
39  items: 'li',
40  handle: 'span.elgg-state-draggable',
41  stop: moveProfileField
42  });
43 
44  // admin notices delete ajax
45  $('a.elgg-admin-notice').click(deleteNotice);
46 
47  // disable checkboxes (readonly does not work for them)
48  $(document).on('click', 'input:checkbox.elgg-state-disabled, label.elgg-state-disabled > input:checkbox', function() {
49  return false;
50  });
51 
52  // disable simple cache compress settings if simple cache is off
53  $('[name=simplecache_enabled]').click(simplecacheToggle);
54 
55  // plugin category filtering
56  $(document).on('click', '.elgg-admin-plugins-categories a', filterPluginCategory);
57 
58  // plugin details selection
59  $(document).on('click', '.elgg-plugin-details-container > ul a', showPluginDetails);
60 
61  $(document).on('click', '.elgg-plugins-toggle', toggleAllPlugins);
62 
63  $(document).on('click', '.elgg-plugin-state-change', toggleSinglePlugin);
64 
65  // plugin screenshots
66  $(document).on('mouseenter', '.elgg-plugin-details-screenshots .elgg-plugin-screenshot', showPluginScreenshot);
67  }
68 
69  function freezePlugins() {
70  $('#elgg-plugin-list-cover').css('display', 'block');
71  }
72  function unfreezePlugins() {
73  $('#elgg-plugin-list-cover').css('display', 'none');
74  }
75 
76  function initPluginReordering() {
77  $('#elgg-plugin-list > ul').sortable({
78  items: 'li:has(> .elgg-state-draggable)',
79  handle: '.elgg-head',
80  forcePlaceholderSize: true,
81  placeholder: 'elgg-widget-placeholder',
82  opacity: 0.8,
83  revert: 500,
84  stop: movePlugin
85  });
86  }
87 
88  function toggleSinglePlugin(e) {
89  freezePlugins();
90 
91  e.preventDefault();
92 
93  ajax.action(this.href)
94  .done(function (output, statusText, jqXHR) {
95  if (jqXHR.AjaxData.status == -1) {
96  // don't know status :/
97  location.reload();
98  return;
99  }
100 
101  // second request because views list must be rebuilt and this can't be done
102  // within the first.
103  ajax.path('admin_plugins_refresh')
104  .done(function (output) {
105 
106  $('#elgg-plugin-list').html(output.list);
107  $('.elgg-sidebar').html(output.sidebar);
108 
109  // reapply category filtering
110  $(".elgg-admin-plugins-categories > li.elgg-state-selected > a").trigger('click');
111  initPluginReordering();
112  unfreezePlugins();
113  });
114  });
115  }
116 
123  function toggleAllPlugins(e) {
124  e.preventDefault();
125 
126  if (!confirm(elgg.echo('question:areyousure'))) {
127  return;
128  }
129 
130  freezePlugins();
131 
132  var guids = [],
133  state = $(this).data('desiredState'),
134  find_state = state == 'active' ? 'inactive' : 'active';
135 
136  $('.elgg-plugin.elgg-state-' + find_state + ':visible').each(function () {
137  var guid = $(this).data('guid');
138  if (guid) {
139  guids.push(guid);
140  }
141  });
142 
143  if (!guids.length) {
144  elgg.register_error(elgg.echo('admin:plugins:already:' + state));
145  return;
146  }
147 
148  spinner.start();
149 
150  // We create a regular form and submit it. This is the simplest way to send the
151  // data, have the page refreshed, and make sure error messages are still shown on
152  // the new page. Using ajax leads to complexity because Elgg wants to send the error
153  // messages back to the client.
154  var $form = $('<form method="post" />');
155  $form.prop('action', elgg.security.addToken(this.href));
156  $form.append('<input type="hidden" name="guids" value="' + guids.join(',') + '" />');
157  $form.appendTo("body").submit();
158  }
159 
167  function movePlugin (e, ui) {
168  freezePlugins();
169 
170  // get guid from id like elgg-object-<guid>
171  var pluginGuid = ui.item.attr('id');
172  pluginGuid = pluginGuid.replace('elgg-object-', '');
173 
174  elgg.action('admin/plugins/set_priority', {
175  data: {
176  plugin_guid: pluginGuid,
177  // we start at priority 1
178  priority: ui.item.index() + 1
179  },
180  success: function() {
181  // update plugins with priority dependences
182  var priorityDep = new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));
183  ui.item.siblings().andSelf().each(function() {
184  if (priorityDep.test($(this).find('.elgg-dependency-requires').text())) {
185  updatePluginView($(this));
186  }
187  });
188  unfreezePlugins();
189  }
190  });
191  }
192 
199  function updatePluginView (pluginView) {
200  // get guid from id like elgg-object-<guid>
201  var pluginGuid = pluginView.attr('id');
202  pluginGuid = pluginGuid.replace('elgg-object-', '');
203 
204  elgg.get({
205  url: elgg.config.wwwroot + "ajax/view/object/plugin/full",
206  dataType: "html",
207  cache: false,
208  data: {
209  guid: pluginGuid,
210  display_reordering: true
211  },
212  success: function(htmlData) {
213  if (htmlData.length > 0) {
214  pluginView.html(htmlData);
215  }
216  }
217  });
218  }
219 
227  function editProfileField (value, settings) {
228  var id = $(this).attr('id');
229  id = id.replace('elgg-profile-field-', '');
230 
231  var data = {
232  id: id,
233  label: value
234  };
235 
236  elgg.action('profile/fields/edit', data);
237  return value;
238  }
239 
247  function moveProfileField (e, ui) {
248  var orderArr = $('#elgg-profile-fields').sortable('toArray');
249  var orderStr = orderArr.join(',');
250 
251  elgg.action('profile/fields/reorder', {
252  fieldorder: orderStr
253  });
254  }
255 
261  function deleteNotice (e) {
262  e.preventDefault();
263  var $container = $(this).closest('p');
264 
265  elgg.action($(this).attr('href'), {
266  success: function(json) {
267  $container.slideUp('medium');
268  }
269  });
270  }
271 
277  function simplecacheToggle () {
278  // when the checkbox is disabled, do not toggle the compression checkboxes
279  if (!$(this).hasClass('elgg-state-disabled')) {
280  var names = ['simplecache_minify_js', 'simplecache_minify_css', 'cache_symlink_enabled'];
281  for (var i = 0; i < names.length; i++) {
282  var $input = $('input[type!=hidden][name="' + names[i] + '"]');
283  if ($input.length) {
284  $input.parent().toggleClass('elgg-state-disabled');
285  }
286  }
287  }
288  }
289 
295  function filterPluginCategory (e) {
296  e.preventDefault();
297 
298  // remove selected state from all buttons
299  $(".elgg-admin-plugins-categories > li").removeClass("elgg-state-selected");
300 
301  // show plugins with the selected category
302  $(".elgg-plugin").hide();
303  $(".elgg-plugin-category-" + $(this).attr("rel")).show();
304  $(this).closest('li').addClass("elgg-state-selected");
305  }
306 
312  function showPluginDetails () {
313  // remove selected state from all buttons
314  $(".elgg-plugin-details-container > ul > li").removeClass("elgg-state-selected");
315 
316  // must use .hide/show() to work with elgg-tabs
317  $(".elgg-plugin-details-container > div > div").hide();
318  $(".elgg-plugin-details-container ." + $(this).attr("rel")).show();
319 
320  $(this).parent().addClass("elgg-state-selected");
321  }
322 
328  function showPluginScreenshot () {
329  $(this).parent().find(".elgg-plugin-screenshot").removeClass("elgg-state-selected");
330  $(this).addClass("elgg-state-selected");
331 
332  // must use .hide/show() to work with elgg-tabs
333  $(".elgg-plugin-details-screenshots > div > img").hide();
334  $(".elgg-plugin-details-screenshots > div > img[rel='" + $(this).attr("rel") + "']").show();
335  }
336 
337  init();
338 });
elgg
Definition: install.js:23
elgg comments init
Initialize comment inline editing.
Definition: comments.js:122
elgg module widget elgg state draggable elgg widget handle
Definition: admin.css.php:1269
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $input
Definition: edit.php:19
line height
Definition: admin.css.php:82
function editable
html
Definition: admin.css.php:36
elgg form settings
Definition: admin.css.php:627
list style type
Definition: admin.css.php:808
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on
Definition: GPL-LICENSE.txt:43
$form
Definition: settings.php:18
define(function(require){var $=require('jquery');var ui=require('jquery-ui');var elgg=require('elgg');var spinner=require('elgg/spinner');var Ajax=require('elgg/Ajax');var ajax=new Ajax();function init(){$('.elgg-system-messages li').stop(true);$(document).off('click', '.elgg-system-messages li');$(document).on('click', '.elgg-system-messages li', function(e){if(!$(e.target).is('a')){$(this).stop().slideUp('medium');}});initPluginReordering();$(".elgg-state-editable").editable(editProfileField,{type: 'text', onblur: 'submit', width: '300px', height: 'none', style: 'display:inline;'});$('#elgg-profile-fields').sortable({items: 'li', handle: 'span.elgg-state-draggable', stop:moveProfileField});$('a.elgg-admin-notice').click(deleteNotice);$(document).on('click', 'input:checkbox.elgg-state-disabled, label.elgg-state-disabled > input:checkbox', function(){return false;});$('[name=simplecache_enabled]').click(simplecacheToggle);$(document).on('click', '.elgg-admin-plugins-categories a', filterPluginCategory);$(document).on('click', '.elgg-plugin-details-container > ul a', showPluginDetails);$(document).on('click', '.elgg-plugins-toggle', toggleAllPlugins);$(document).on('click', '.elgg-plugin-state-change', toggleSinglePlugin);$(document).on('mouseenter', '.elgg-plugin-details-screenshots.elgg-plugin-screenshot', showPluginScreenshot);}function freezePlugins(){$('#elgg-plugin-list-cover').css('display', 'block');}function unfreezePlugins(){$('#elgg-plugin-list-cover').css('display', 'none');}function initPluginReordering(){$('#elgg-plugin-list > ul').sortable({items: 'li:has(>.elgg-state-draggable)', handle: '.elgg-head', forcePlaceholderSize:true, placeholder: 'elgg-widget-placeholder', opacity:0.8, revert:500, stop:movePlugin});}function toggleSinglePlugin(e){freezePlugins();e.preventDefault();ajax.action(this.href).done(function(output, statusText, jqXHR){if(jqXHR.AjaxData.status==-1){location.reload();return;}ajax.path('admin_plugins_refresh').done(function(output){$('#elgg-plugin-list').html(output.list);$('.elgg-sidebar').html(output.sidebar);$(".elgg-admin-plugins-categories > li.elgg-state-selected > a").trigger('click');initPluginReordering();unfreezePlugins();});});}function toggleAllPlugins(e){e.preventDefault();if(!confirm(elgg.echo('question:areyousure'))){return;}freezePlugins();var guids=[], state=$(this).data('desiredState'), find_state=state== 'active'? 'inactive': 'active';$('.elgg-plugin.elgg-state-'+find_state+ ':visible').each(function(){var guid=$(this).data('guid');if(guid){guids.push(guid);}});if(!guids.length){elgg.register_error(elgg.echo('admin:plugins:already:'+state));return;}spinner.start();var $form=$('< form method="post"/>');$form.prop('action', elgg.security.addToken(this.href));$form.append('< input type="hidden"name="guids"value="' + guids.join(',') + '"/>');$form.appendTo("body").submit();}function movePlugin(e, ui){freezePlugins();var pluginGuid=ui.item.attr('id');pluginGuid=pluginGuid.replace('elgg-object-', '');elgg.action('admin/plugins/set_priority',{data:{plugin_guid:pluginGuid, priority:ui.item.index()+1}, success:function(){var priorityDep=new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));ui.item.siblings().andSelf().each(function(){if(priorityDep.test($(this).find('.elgg-dependency-requires').text())){updatePluginView($(this));}});unfreezePlugins();}});}function updatePluginView(pluginView){var pluginGuid=pluginView.attr('id');pluginGuid=pluginGuid.replace('elgg-object-', '');elgg.get({url:elgg.config.wwwroot+"ajax/view/object/plugin/full", dataType:"html", cache:false, data:{guid:pluginGuid, display_reordering:true}, success:function(htmlData){if(htmlData.length > 0){pluginView.html(htmlData);}}});}function editProfileField(value, settings){var id=$(this).attr('id');id=id.replace('elgg-profile-field-', '');var data={id:id, label:value};elgg.action('profile/fields/edit', data);return value;}function moveProfileField(e, ui){var orderArr=$('#elgg-profile-fields').sortable('toArray');var orderStr=orderArr.join(',');elgg.action('profile/fields/reorder',{fieldorder:orderStr});}function deleteNotice(e){e.preventDefault();var $container=$(this).closest('p');elgg.action($(this).attr('href'),{success:function(json){$container.slideUp('medium');}});}function simplecacheToggle(){if(!$(this).hasClass('elgg-state-disabled')){var names=['simplecache_minify_js', 'simplecache_minify_css', 'cache_symlink_enabled'];for(var i=0;i< names.length;i++){var $input=$('input[type!=hidden][name="' + names[i] + '"]');if($input.length){$input.parent().toggleClass('elgg-state-disabled');}}}}function filterPluginCategory(e){e.preventDefault();$(".elgg-admin-plugins-categories > li").removeClass("elgg-state-selected");$(".elgg-plugin").hide();$(".elgg-plugin-category-"+$(this).attr("rel")).show();$(this).closest('li').addClass("elgg-state-selected");}function showPluginDetails(){$(".elgg-plugin-details-container > ul > li").removeClass("elgg-state-selected");$(".elgg-plugin-details-container > div > div").hide();$(".elgg-plugin-details-container ."+$(this).attr("rel")).show();$(this).parent().addClass("elgg-state-selected");}function showPluginScreenshot(){$(this).parent().find(".elgg-plugin-screenshot").removeClass("elgg-state-selected");$(this).addClass("elgg-state-selected");$(".elgg-plugin-details-screenshots > div > img").hide();$(".elgg-plugin-details-screenshots > div > img[rel='"+$(this).attr("rel")+"']").show();}init();})
Admin-area specific javascript functions.
elgg ajax
Wrapper function for jQuery.ajax which ensures that the url being called is relative to the elgg site...
Definition: ajax.js:19
$container
Definition: delete.php:29
label
Definition: admin.css.php:464
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
elgg output
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
list style
Definition: admin.css.php:1234
GNU GENERAL PUBLIC LICENSE June Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license document
Definition: GPL-LICENSE.txt:4
min width
Definition: admin.css.php:166
elgg message elgg state success
Definition: admin.css.php:252
if(!$site) if(!($site instanceof ElggSite)) $site url
elgg widget placeholder
Definition: admin.css.php:1308
i
Definition: admin.css.php:47