Skip to content

Instantly share code, notes, and snippets.

@viralsolani
Created March 22, 2018 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viralsolani/24415f2657baabfd58ebaf544380aaa4 to your computer and use it in GitHub Desktop.
Save viralsolani/24415f2657baabfd58ebaf544380aaa4 to your computer and use it in GitHub Desktop.
Example of Vanila Js and IIFEs
(function(window)
{
FTXCommon.ProductAttribute = {
selectors: {
accountSelect: document.querySelector('[name="account_id"]'),
attributeSetSelect: document.querySelector('.attributeSetSelect')
},
/**
* Initialize
*
*/
init: function()
{
this.addHandlers();
},
/**
* Add Handlers
*
*/
addHandlers: function()
{
var context = this;
if(this.selectors.accountSelect)
{
this.selectors.accountSelect.onchange = function(event)
{
context.getAttributeSet();
};
}
},
/**
* Get Attribute Set
*
*/
getAttributeSet: function()
{
var accountId = this.selectors.accountSelect.value;
FTXCommon.Utils.emptySelect2(this.selectors.attributeSetSelect);
// Add select box for finding department groups
FTXCommon.Utils.addAjaxSelect2(this.selectors.attributeSetSelect, moduleConfig.attributeSetFindUrl, { placeholder: "Select Attribute Set"}, function(params)
{
return {
q: params.term,
account_id: accountId,
page: params.page
};
});
},
/**
* Set AttributeSet Value
*
*/
setAttributeSetValue: function(value)
{
this.selectors.attributeSetSelect.value = value;
var accountId = this.selectors.accountSelect.value;
// Add select box for finding department groups
FTXCommon.Utils.addAjaxSelect2(this.selectors.attributeSetSelect, moduleConfig.attributeSetFindUrl, {}, function(params)
{
return {
q: params.term,
account_id: accountId,
page: params.page
};
});
}
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment