/****************************************************************************
Namespace -- this should be the file name, but camelcased
Custom form component implementations should go in the UI file for the
entity they deal with.
*****************************************************************************/
Aptify.framework.utility.ensureNameSpaceExists("Aptify.applications.topLevelEntityName.UI");
/*****************************************************************************
Form Component
*****************************************************************************/
Aptify.applications.topLevelEntityName.UI.formComponentName = function (domElement) {
///
/// Constructs a new Form Component Name in domElement
///
/// This element will hold the form component
///
function _formComponentName(domElement) {
///
/// Constructs a new Form Component Name in domElement
///
/// This element will hold the form component
try {
// Inherit from the generic bound control
// Do this even if your control is NOT bound to a specific field.
Aptify.framework.inheritance.inherit(this, new Aptify.framework.dataControls.UI.boundControlBase(domElement));
// Override Bound Control Base methods
// (Delete any you don't override, to avoid confusion)
// (This does not represent a full catalog of overridable methods)
Aptify.framework.inheritance.overrides(this, "refresh", _refresh);
Aptify.framework.inheritance.overrides(this, "onContainerResize", _refresh);
Aptify.framework.inheritance.overrides(this, "enable", _refresh);
// Define instance-wide variables
var _ctrl = this;
// Do anything that should be done on instantiation but NOT on refresh
// If nothing should change on refresh, finish setting up the control right here.
// _completeControl(domElement);
// If things might change on refresh, finish setting up the control there.
this.refresh();
} catch (ex) {
Aptify.framework.exceptionManager.publish(ex);
}
// Define function to complete the control's setup
function _completeControl(domElement) {
///
/// Completes setting up the control, including adding it to the domElement.
///
/// This element will hold the form component
try {
// If we didn't get a domElement passed in, get the one from the control
if (!domElement) { domElement = _ctrl._domElement; }
// Define display options for the control
var options = { e: domElement, bHeight: true, widthPadding: 0, heightPadding: 4 };
var s = this.getStyle(options);
// Create the HTML for the component.
var sHTML = "";
// Clear the domElement and add the HTML we've constructed
$(domElement).empty().append(sHTML);
// Do any additional setup that needs to happen after the element is in the DOM
} catch (ex) {
Aptify.framework.exceptionManager.publish(ex);
}
}
// Define overriding functions
// (Delete any you don't override, to avoid confusion)
function _refresh(domElement) {
/// Triggered whenever the data changes.
/// The domElement of the control
try {
// If we didn't get a domElement passed in, get the one from the control
if (!domElement) { domElement = _ctrl._domElement; }
// Call parent's refresh()
_ctrl.base().refresh();
// Do control setup that should happen on every refresh
_completeControl(domElement);
} catch (ex) {
Aptify.framework.exceptionManager.publish(ex);
}
}
function _onContainerResize(data) {
/// Triggers when the control's container is resized. Default behavior does nothing.
/// Data about the container: {
/// bHeightChanged (boolean),
/// bWidthChanged (boolean),
/// css (the container's css),
/// jqE (jQuery representation of the container),
/// domElement (the container),
/// elementOnly (???),
/// fh (???),
/// fw (???),
/// newHeight (in px),
/// newWidth (in px),
/// oldHeight (in px),
/// oldWidth (in px)
/// }
///
try {
// Call parent's onContainerResize()
_ctrl.base().onContainerResize(data);
// Do any resize work
} catch (ex) {
Aptify.framework.exceptionManager.publish(ex);
}
}
function _enable(enabled, domElement) {
///
/// Enables or disables the control
///
/// True to enable the control; False to disable
/// the DOM element of the control
try {
// Call parent's enable()
_ctrl.base().enable();
// Do any enable work
} catch (ex) {
Aptify.framework.exceptionManager.publish(ex);
}
}
}
// Return a new instance of this control
return new _formComponentName(domElement);
}