1Jsw.namespace('PleskExt.Kolab'); 2 3function messageBoxYesNo(url, ids, i18n) 4{ 5 Jsw.messageBox.show({ 6 'type': Jsw.messageBox.TYPE_YESNO, 7 'subtype': 'toggle', 8 'text': i18n['confirm-text'], 9 'description': i18n['confirm-description'], 10 'buttonTitles': { 11 'yes': i18n['confirm-button-yes'], 12 'no': i18n['confirm-button-no'] 13 }, 14 'onYesClick': function () { 15 new Ajax.Request(url, { 16 method: 'post', 17 parameters: ids, 18 onSuccess: function (data) { 19 window.location.reload(); 20 } 21 }); 22 23 }.bind(this) 24 }); 25} 26 27function saveAcl(button) 28{ 29 "use strict" 30 var domain = $('aclForm').getAttribute('data-domain'); 31 var url = button.getAttribute('data-url'); 32 var aclList = $H(); 33 var isValid = true; 34 //http://trac.webkit.org/browser/trunk/Source/WebCore/html/EmailInputType.cpp#L38 35 var mailRegEx = new RegExp("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+$"); 36 37 $$('#aclForm > .dynamicSubFormContent input.aclinput').each(function (item) { 38 var row = item.up('.form-row'); 39 var errors = row.select('.field-errors')[0]; 40 var rights = row.select('.select-field')[0]; 41 row.removeClassName('error'); 42 errors.update(); 43 44 if (item.value && mailRegEx.exec(item.value)) { 45 var right = rights.value; 46 var mail = item.value + '@' + domain; 47 aclList.set('acl[' + mail + ']', right); 48 } else { 49 row.addClassName('error'); 50 errors.update('<span class="error-hint">' + PleskExt.Kolab.Config.i18n.validation["invalid-email"] + '</span>'); 51 isValid = false; 52 } 53 }); 54 55 if (isValid) { 56 new Ajax.Request(url, { 57 method: 'post', 58 parameters: aclList, 59 onSuccess: function (data) { 60 var response = data.responseJSON; 61 if (response) { 62 if (response.errors) { 63 var i, inputs = $$('#aclForm > .dynamicSubFormContent input.aclinput'); 64 for (i in response.errors) { 65 if (!isNaN(parseInt(i))) { 66 var item = inputs[i]; 67 var row = item.up('.form-row').addClassName('error'); 68 row.select('.field-errors')[0].update('<span class="error-hint">' + response.errors[i] + '</span>'); 69 } 70 } 71 } else if (response.url) { 72 location.assign(response.url); 73 } 74 } 75 } 76 }); 77 } 78} 79var Kolab = {}; 80Kolab.AclDynamicSubForm = Class.create(Jsw.AddRemoveDynamicSubForm, { 81 // phpcs:ignore 82 _onInitDynamic: function ($super) { 83 $super(); 84 this.setDomain(); 85 }, 86 _bindDynamicContent: function ($super, content, isFirstElement) { 87 var domainElement = new Element('span', { 88 'class': 'aclDomainName' 89 }); 90 var input = content.select('.field-value input').last(); 91 input.insert({ 92 after: domainElement 93 }); 94 95 aclInputHandler(input); 96 97 return $super(content, isFirstElement); 98 }, 99 _onUpdateDynamic: function ($super) { 100 $super(); 101 this.setDomain(); 102 }, 103 setDomain: function () { 104 var childs = this._componentElement.select('.aclDomainName'); 105 var domainName = this.getDomainName(); 106 childs.each(function (child) { 107 child.update(' @' + domainName); 108 }); 109 }, 110 getDomainName: function () { 111 var domain = $('aclForm').getAttribute('data-domain'); 112 return domain; 113 }, 114 deleteContent: function ($super, content, event) { 115 aclMessageBoxYesNo(PleskExt.Kolab.Config.i18n.acl, function (confirmation) { 116 if (confirmation) { 117 $super(content, event); 118 } 119 Event.stop(event); 120 }); 121 } 122}); 123 124var datalist_counter = 0; 125 126function aclInputHandler(item) 127{ 128 "use strict"; 129 var id = 'datalist-' + datalist_counter++, 130 datalist = new Element('datalist', { 131 id: id 132 }); 133 134 item.insert({ 135 after: datalist 136 }).setAttribute('list', id); 137 item.on('input', function (event) { 138 var input = event.target; 139 // if datalist is supported by the browser use user autocompletion 140 if (datalist.options) { 141 if (!input.value.length || 142 !datalist.select('[value="' + input.value + '"]').length 143 ) { 144 aclAutocomplete(input, input.value); 145 } 146 } 147 }); 148} 149 150var ac_request, ac_timeout; 151 152function aclAutocomplete(input, search) 153{ 154 "use strict"; 155 156 clearTimeout(ac_timeout); 157 if (ac_request) { 158 ac_request.abort(); 159 } 160 161 if (!search || !search.length) { 162 $(input.getAttribute('list')).update(); 163 return; 164 } 165 166 ac_timeout = setTimeout(function () { 167 ac_request = new Ajax.Request(location.href.replace(/\/acl\?/, '/acl-search?'), { 168 method: 'post', 169 parameters: $H({ search: search }), 170 onSuccess: function (data) { 171 var options = []; 172 173 if (data.responseJSON.options) { 174 data.responseJSON.options.forEach(function (v) { 175 options.push((new Element('option', { 176 value: v 177 })).outerHTML); 178 }); 179 180 $(input.getAttribute('list')).update(options.join()); 181 } 182 } 183 }); 184 }, 100); 185} 186 187function aclMessageBoxYesNo(i18n, callback) 188{ 189 Jsw.messageBox.show({ 190 'type': Jsw.messageBox.TYPE_YESNO, 191 'subtype': 'toggle', 192 'text': i18n['confirm-text'], 193 'description': i18n['confirm-description'], 194 'buttonTitles': { 195 'yes': i18n['confirm-button-yes'], 196 'no': i18n['confirm-button-no'] 197 }, 198 'onYesClick': function () { 199 callback(true); 200 }, 201 'onNoClick': function () { 202 callback(false); 203 }.bind(this) 204 }); 205} 206 207document.observe("dom:loaded", function () { 208 "use strict" 209 210 // Move the Kolab subform into the "general" tab 211 // so it's not shown on all tabs (which is the default) 212 var tabGeneral = $('tab-general') 213 var kolabForm = $('kolab') 214 if (!tabGeneral || !kolabForm) { 215 return; 216 } 217 tabGeneral.insert(kolabForm) 218 219 var templateFormRow = $('kolab-delegation-form-row').clone(true) 220 var templateRemove = $('kolab-removeButton-element').select('a')[0].clone(true) 221 $('kolab-removeButton-label').remove() 222 $('kolab-removeButton-element').remove() 223 224 var delegationItemCounter = 1 225 var formReady = false 226 227 var isFirstDelegationItem = true 228 229 function delegationNextCounter() 230 { 231 return delegationItemCounter++; 232 } 233 234 function moveAddbuttonDown() 235 { 236 var contentArea = $('kolab-content-area') 237 var buttonDT = $('kolab-addButton-label') 238 var buttonDD = $('kolab-addButton-element') 239 240 contentArea.insert(buttonDT) 241 contentArea.insert(buttonDD) 242 } 243 244 function updateStoredFromForm() 245 { 246 if (!formReady) { 247 return 248 } 249 var newValues = [] 250 var hasInputs = false 251 $('kolab-content-area').select('input[type=text]').each(function (inp) { 252 if (inp.name != 'error-target') { 253 hasInputs = true 254 } 255 if (inp.value !== '') { 256 // Only add delegate entry if there's some text in it 257 newValues.push(inp.value) 258 } 259 }) 260 261 if (!hasInputs) { 262 addDelegationElement('') 263 } 264 265 $('kolab-storedData').value = JSON.stringify(newValues) 266 console.log('KOLAB: updating stored form data', newValues) 267 } 268 269 function addDelegationElement(value) 270 { 271 var contentArea = $('kolab-content-area') 272 // Clone the form row 273 var newElem = templateFormRow.clone(true) 274 var newRemove = templateRemove.clone(true) 275 276 var domain = $('kolab-domainName').value 277 var span = document.createElement('span') 278 span.appendChild(document.createTextNode('@' + domain)) 279 280 var input = newElem.select('.field-value input')[0] 281 282 input.insert({ 283 'after': newRemove 284 }) 285 input.insert({ 286 'after': span 287 }) 288 289 newRemove.observe('click', function () { 290 newElem.remove() 291 updateStoredFromForm() 292 }) 293 294 var nextID = delegationNextCounter() 295 296 // Modify the clones 297 newElem.id = newElem.id + nextID 298 input.id = input.id + nextID 299 300 if (formReady) { 301 newElem.select('label')[0].hide() 302 } 303 304 contentArea.insert(newElem) 305 306 input.value = value 307 308 input.observe('blur', updateStoredFromForm) 309 input.observe('keyUp', updateStoredFromForm) 310 input.observe('change', updateStoredFromForm) 311 updateStoredFromForm() 312 moveAddbuttonDown() 313 314 return newElem 315 } 316 317 function initErrorTarget() 318 { 319 // add fake input above the other so the Plesk JS 320 // knows where to put the validation error 321 var errortarget = addDelegationElement('') 322 errortarget.select('input')[0].id = 'kolab-delegation' 323 errortarget.select('input')[0].name = 'error-target' 324 errortarget.select('input')[0].hide() 325 errortarget.select('span')[0].hide() // first is our artificial "@$DOMAIN" label 326 errortarget.select('a')[0].hide() 327 errortarget.select('label')[0].hide() 328 } 329 330 function addFormElements() 331 { 332 // Initialize the inputs from the stored data 333 var storedData = JSON.parse($('kolab-storedData').value) 334 335 // remove original input element if we have data, so 336 // we don't get an empty element on top 337 $('kolab-delegation-form-row').remove() 338 339 storedData.each(addDelegationElement) 340 if (!storedData.length) { 341 // add empty form field inf nothing there yet 342 addDelegationElement('') 343 } 344 } 345 346 function initAddButton() 347 { 348 // Initialize the "add delegation item" button 349 $('kolabAddDelegationItem').observe('click', function (evt) { 350 351 addDelegationElement('') 352 353 evt.preventDefault() 354 return false 355 }) 356 } 357 358 function fixLabels() 359 { 360 // first label is the error target, second label we want to actually keep 361 $('kolab-content-area').select('label').slice(2).each(function (label) { 362 label.hide() 363 }) 364 } 365 366 initAddButton() 367 initErrorTarget() 368 addFormElements() 369 fixLabels() 370 formReady = true 371 372})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.