Index: trunk/phase3/skins/common/protect.js |
— | — | @@ -1,3 +1,10 @@ |
| 2 | +/** |
| 3 | + * Set up the protection chaining interface (i.e. "unlock move permissions" checkbox) |
| 4 | + * on the protection form |
| 5 | + * |
| 6 | + * @param String tableId Identifier of the table containing UI bits |
| 7 | + * @param String labelText Text to use for the checkbox label |
| 8 | + */ |
2 | 9 | function protectInitialize( tableId, labelText ) { |
3 | 10 | if( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) ) |
4 | 11 | return false; |
— | — | @@ -51,24 +58,37 @@ |
52 | 59 | return true; |
53 | 60 | } |
54 | 61 | |
| 62 | +/** |
| 63 | + * When protection levels are locked together, update the rest |
| 64 | + * when one action's level changes |
| 65 | + * |
| 66 | + * @param Element source Level selector that changed |
| 67 | + */ |
55 | 68 | function protectLevelsUpdate(source) { |
56 | | - if (!protectUnchained()) { |
57 | | - protectUpdateAll(source.selectedIndex); |
58 | | - } |
| 69 | + if( !protectUnchained() ) |
| 70 | + protectUpdateAll( source.selectedIndex ); |
59 | 71 | allowCascade(); |
60 | 72 | } |
61 | 73 | |
| 74 | +/** |
| 75 | + * Update chain status and enable/disable various bits of the UI |
| 76 | + * when the user changes the "unlock move permissions" checkbox |
| 77 | + */ |
62 | 78 | function protectChainUpdate() { |
63 | | - if (protectUnchained()) { |
64 | | - protectEnable(true); |
| 79 | + if( protectUnchained() ) { |
| 80 | + protectEnable( true ); |
65 | 81 | } else { |
66 | 82 | protectChain(); |
67 | | - protectEnable(false); |
| 83 | + protectEnable( false ); |
68 | 84 | } |
69 | 85 | allowCascade(); |
70 | 86 | } |
71 | 87 | |
72 | | - |
| 88 | +/** |
| 89 | + * Are all actions protected at the same level? |
| 90 | + * |
| 91 | + * @return boolean |
| 92 | + */ |
73 | 93 | function protectAllMatch() { |
74 | 94 | var values = new Array(); |
75 | 95 | protectForSelectors(function(set) { |
— | — | @@ -82,6 +102,11 @@ |
83 | 103 | return true; |
84 | 104 | } |
85 | 105 | |
| 106 | +/** |
| 107 | + * Is protection chaining on or off? |
| 108 | + * |
| 109 | + * @return bool |
| 110 | + */ |
86 | 111 | function protectUnchained() { |
87 | 112 | var unchain = document.getElementById( 'mwProtectUnchained' ); |
88 | 113 | return unchain |
— | — | @@ -89,8 +114,10 @@ |
90 | 115 | : true; // No control, so we need to let the user set both levels |
91 | 116 | } |
92 | 117 | |
| 118 | +/** |
| 119 | + * Find the highest-protected action and set all others to that level |
| 120 | + */ |
93 | 121 | function protectChain() { |
94 | | - // Find the highest-protected action and bump them all to this level |
95 | 122 | var maxIndex = -1; |
96 | 123 | protectForSelectors(function(set) { |
97 | 124 | if (set.selectedIndex > maxIndex) { |
— | — | @@ -100,6 +127,11 @@ |
101 | 128 | protectUpdateAll(maxIndex); |
102 | 129 | } |
103 | 130 | |
| 131 | +/** |
| 132 | + * Protect all actions at the specified level |
| 133 | + * |
| 134 | + * @param int index Protection level |
| 135 | + */ |
104 | 136 | function protectUpdateAll(index) { |
105 | 137 | protectForSelectors(function(set) { |
106 | 138 | if (set.selectedIndex != index) { |
— | — | @@ -108,6 +140,11 @@ |
109 | 141 | }); |
110 | 142 | } |
111 | 143 | |
| 144 | +/** |
| 145 | + * Apply a callback to each protection selector |
| 146 | + * |
| 147 | + * @param callable func Callback function |
| 148 | + */ |
112 | 149 | function protectForSelectors(func) { |
113 | 150 | var selectors = protectSelectors(); |
114 | 151 | for (var i = 0; i < selectors.length; i++) { |
— | — | @@ -115,6 +152,11 @@ |
116 | 153 | } |
117 | 154 | } |
118 | 155 | |
| 156 | +/** |
| 157 | + * Get a list of all protection selectors on the page |
| 158 | + * |
| 159 | + * @return Array |
| 160 | + */ |
119 | 161 | function protectSelectors() { |
120 | 162 | var all = document.getElementsByTagName("select"); |
121 | 163 | var ours = new Array(); |
— | — | @@ -127,6 +169,11 @@ |
128 | 170 | return ours; |
129 | 171 | } |
130 | 172 | |
| 173 | +/** |
| 174 | + * Enable/disable protection selectors |
| 175 | + * |
| 176 | + * @param boolean val Enable? |
| 177 | + */ |
131 | 178 | function protectEnable(val) { |
132 | 179 | // fixme |
133 | 180 | var first = true; |