// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
///
///
///
///
///
Type.registerNamespace('AjaxControlToolkit');
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior = function(element) {
///
/// The MutuallyExclusiveCheckBoxBehavior allows only one checkbox in
/// a group with the same Key to be checked at a time
///
///
/// The DOM Element the behavior is associated with
///
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.initializeBase(this, [element]);
this._key = "";
this._clickHandler = Function.createDelegate(this, this._onclick);
}
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.prototype = {
initialize : function() {
///
/// Initialize the behavior
///
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.callBaseMethod(this, 'initialize');
$addHandler(this.get_element(), "click", this._clickHandler);
},
dispose : function() {
///
/// Dispose the behavior
///
if (this._key) {
var keys = AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.Keys;
var ar = keys[this._key];
Array.remove(ar, this);
this._key = null;
}
if (this._clickHandler) {
$removeHandler(this.get_element(), "click", this._clickHandler);
this._clickHandler = null;
}
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.callBaseMethod(this, 'dispose');
},
get_Key : function() {
///
/// The unique key to use to associate checkboxes. This key does not respect INamingContainer renaming.
///
return this._key;
},
set_Key : function(value) {
var keys = AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.Keys;
if(value != this._key) {
if(this._key) {
var ar = keys[this._key];
Array.remove(ar, this._key);
}
this._key = value;
if(value) {
var ar = keys[this._key];
if(ar == null) {
ar = keys[this._key] = [];
}
Array.add(ar, this);
}
}
},
_onclick : function() {
///
/// Click handler used to ensure only one checkbox in its key is checked
///
var element = this.get_element();
var keys = AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.Keys;
if(this._key && element.checked) {
var ar = keys[this._key];
var t = this;
Array.forEach(ar, function(b) {
///
/// Uncheck all other checkboxes in the same key group
///
///
/// Checkbox in the same key group
///
if(b != t) {
b.get_element().checked = false;
$common.tryFireEvent(b.get_element(), "change");
}
});
}
this.raiseChecked(new AjaxControlToolkit.MutuallyExclusiveCheckBoxEventArgs(element, this._key));
},
add_checked : function(handler) {
///
/// Add an event handler for the checked event
///
///
/// Event handler
///
///
this.get_events().addHandler('checked', handler);
},
remove_checked : function(handler) {
///
/// Remove an event handler from the checked event
///
///
/// Event handler
///
///
this.get_events().removeHandler('checked', handler);
},
raiseChecked : function(eventArgs) {
///
/// Raise the checked event
///
///
/// Event arguments for the checked event
///
///
var handler = this.get_events().getHandler('checked');
if (handler) {
handler(this, eventArgs);
}
}
}
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.registerClass('AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior', AjaxControlToolkit.BehaviorBase);
AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior.Keys = {};
AjaxControlToolkit.MutuallyExclusiveCheckBoxEventArgs = function(checkbox, key) {
///
/// Event arguments used when the checked event is raised
///
///
/// Checkbox that was checked or unchecked
///
///
/// The unique key used to associate checkboxes
///
AjaxControlToolkit.MutuallyExclusiveCheckBoxEventArgs.initializeBase(this);
this._key = key;
this._checkbox = checkbox;
}
AjaxControlToolkit.MutuallyExclusiveCheckBoxEventArgs.prototype = {
get_checkbox : function() {
///
/// Checkbox that was checked or unchecked
///
return this._checkbox;
},
get_key : function() {
///
/// The unique key used to associate checkboxes
///
return this._key;
}
}
AjaxControlToolkit.MutuallyExclusiveCheckBoxEventArgs.registerClass('AjaxControlToolkit.MutuallyExclusiveCheckBoxEventArgs', Sys.EventArgs);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();