// Deals app // =============================================== // Takes in data obj, an element to append to, and utility functions // // Data set: // []Deal // - id string // - name string // // Example data: // [ // { "id" : "1", "name" : "Super deal"} // ] // var deals = (function(){ 'use strict' var template = new Template; return newDeals; function newDeals(d, t, fns){ return new Deals(d, t, fns); } function Deals(d, t, fns) { var e = getElementFromString(template.index, { 'name' : fns.getAppName('deals') }), view = e.querySelector('.view'), isSelected = !!d && !!d.length, eles = new Elements(e, { 'status': { 'target' : new ToggleInput(e.querySelector('.toggle'), updateStatus, { 'initialValue' : d.status === true }) }, 'list': { 'target' : new DynamicInputList(e.querySelector('.view'), template.deals, updateDeals, { 'values' : d.list })}, "remove" : { 'target' : new ConfirmationButton(e.querySelector('.remove'), { 'text' : 'Remove app', 'noClass' : true, 'confirmText' : 'Confirm?' }, removeAction) }, }); this.exit = exit; t.appendChild(e); function updateStatus(e) { d.status = e; if(e) { view.classList.remove('noDisplay'); } else { view.classList.add('noDisplay'); d.list = null; } } function updateDeals(e, v) { d.list = v; } function removeAction(e){ fns.removeApp('deals'); } function exit(){ if(!!e) removeChild(t, e); if(!!eles) eles.exit(); e = eles = view = null; } } function Template(){ var h = '