Blame view

framework/admin/javascript/SecurityAdmin.js 2.2 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /**
   * File: SecurityAdmin.js
   */
  (function($) {
  	
  	var refreshAfterImport = function(e) {
  		// Check for a message <div>, an indication that the form has been submitted.
  		var existingFormMessage = $($(this).contents()).find('.message');
  		if(existingFormMessage && existingFormMessage.html()) {
  			// Refresh member listing
  			var memberTableField = $(window.parent.document).find('#Form_EditForm_Members').get(0);
  			if(memberTableField) memberTableField.refresh();
  			
  			// Refresh tree
  			var tree = $(window.parent.document).find('.cms-tree').get(0);
  			if(tree) tree.reload();
  		}
  	};
  	
  	/**
  	 * Refresh the member listing every time the import iframe is loaded,
  	 * which is most likely a form submission.
  	 */
  	$('#MemberImportFormIframe, #GroupImportFormIframe').entwine({
  		onadd: function() {
  			this._super();
  			// TODO entwine can't seem to bind to iframe load events
  			$(this).bind('load', refreshAfterImport);
  		}
  	});
  
  	$.entwine('ss', function($){
  		/**
  		 * Class: #Permissions .checkbox[value=ADMIN]
  		 * 
  		 * Automatically check and disable all checkboxes if ADMIN permissions are selected.
  		 * As they're disabled, any changes won't be submitted (which is intended behaviour),
  		 * checking all boxes is purely presentational.
  		 */
  		$('#Permissions .checkbox[value=ADMIN]').entwine({
  			onmatch: function() {
  				this.toggleCheckboxes();
  
  				this._super();
  			},
  			onunmatch: function() {
  				this._super();
  			},
  			/**
  			 * Function: onclick
  			 */
  			onclick: function(e) {
  				this.toggleCheckboxes();
  			},
  			/**
  			 * Function: toggleCheckboxes
  			 */
  			toggleCheckboxes: function() {
  				var self = this, checkboxes = this.parents('.field:eq(0)').find('.checkbox').not(this);
  				
  				if(this.is(':checked')) {
  					checkboxes.each(function() {
  						$(this).data('SecurityAdmin.oldChecked', $(this).is(':checked'));
  						$(this).data('SecurityAdmin.oldDisabled', $(this).is(':disabled'));
  						$(this).prop('disabled', true);
  						$(this).prop('checked', true);
  					});
  				} else {
  					checkboxes.each(function() {
  						$(this).prop('checked', $(this).data('SecurityAdmin.oldChecked'));
  						$(this).prop('disabled', $(this).data('SecurityAdmin.oldDisabled'));
  					});
  				}
  			}
  		});
  	});
  	
  }(jQuery));