define(["require", "exports", "services/validateNames", "services/nav", "services/utils"], function (require, exports, validateNames, srvNav, util) { "use strict"; var ConfigStore = (function () { function ConfigStore(requirements, deviceId, registerOnPrefsChanged) { var _this = this; this.requirements = requirements; this.deviceId = deviceId; this.listeners = []; this.navItems = []; this.filteredNavItems = []; this.searchText = ""; this.activeDesignSummaryTab = util.DesignSummaryTab.Summary; this.configureVoltage = function () { srvNav.configureVoltage(_this.selectedNavItem.getName(), _this.selectedMyListItem.getID()); }; this.viewIOSets = function (peripheralName, ioSetName) { srvNav.configureIOSets(peripheralName, ioSetName, _this.selectedNavItem.getName(), _this.selectedMyListItem.getID()); }; this.setSelectedNavItem = function (navItem, myListItem) { _this.selectedNavItem = navItem; _this.selectedMyListItem = myListItem ? myListItem : navItem.getMyListItems()[0]; _this.notify(); }; this.add = function (navItem) { _this.selectedNavItem = navItem; _this.selectedMyListItem = navItem.add(); _this.solveAndNotify(); }; this.removeAll = function (navItem) { navItem.removeAll(); _this.selectedMyListItem = null; _this.solveAndNotify(); }; this.setSearchText = function (text) { _this.searchText = text; _this.filteredNavItems = _.filter(_this.navItems, function (item) { return item.getName().toLowerCase().indexOf(_this.searchText.toLowerCase()) !== -1; }); _this.notify(); }; this.setSelectedMyListItem = function (myListItem) { _this.selectedMyListItem = myListItem; _this.notify(); }; this.remove = function (myListItem) { _this.selectedMyListItem = _this.selectedNavItem.remove(myListItem); _this.solveAndNotify(); }; this.setMyListItemName = function (myListItem, newName) { myListItem.setName(newName); validateNames(_this.navItems); _this.notify(); }; this.setSelectedUseCase = function (req, useCaseName) { req.setUseCase(useCaseName); _this.solveAndNotify(); }; this.setSelectedPeripheral = function (req, peripheralName) { req.setPeripheral(peripheralName); _this.solveAndNotify(); }; this.setSelectedVoltage = function (req, voltage) { req.setVoltage(voltage); _this.solveAndNotify(); }; this.setConfigurableValue = function (configurable, value) { configurable.setValue(value); _this.notify(); }; this.setSelectedDevicePin = function (req, name) { req.setSelectedDevicePin(name); _this.solveAndNotify(); }; this.setUsed = function (req, val) { req.setUsed(val); _this.solveAndNotify(); }; this.setCount = function (req, val) { req.setCount(val); _this.solveAndNotify(); }; this.setSelectAll = function (req, val) { req.setSelectAll(val); _this.solveAndNotify(); }; this.setNumOfGPIOPins = function (req, numOfGPIOPins) { req.setNumOfGPIOPins(numOfGPIOPins); _this.solveAndNotify(); }; this.downloadFiles = function (fileList, selectedCategory) { _this.requirements.downloadFiles(fileList, _this.deviceId, selectedCategory); }; this.downloadFile = function (fileEntry) { _this.requirements.downloadFile(fileEntry); }; this.setActiveTab = function (tab) { _this.activeDesignSummaryTab = tab; _this.notify(); }; this.getErrorWarningItemContainer = function () { return util.getErrorWarningItems(_this.navItems); }; this.generateCode = function (file) { return _this.requirements.generateCode(file); }; this.navItems = _.sortBy(requirements.getAllInterfaces(), function (navItem) { return navItem.getName().toLowerCase(); }); this.filteredNavItems = this.navItems; this.selectedNavItem = _.find(this.navItems, function (navItem) { return navItem.getName() === srvNav.selectedInterfaceId; }); if (!this.selectedNavItem) { this.selectedNavItem = _.find(this.navItems, function (navItem) { return navItem.getMaxAllowed() > 0; }); this.selectedMyListItem = this.selectedNavItem.getMyListItems()[0]; } else { this.selectedMyListItem = _.find(this.selectedNavItem.getMyListItems(), function (myListItem) { return myListItem.getID() === srvNav.selectedRequirementId; }); } registerOnPrefsChanged(function () { return _this.notify(); }); } ConfigStore.prototype.addListener = function (listener) { this.listeners.push(listener); }; ConfigStore.prototype.removeListener = function (listener) { var index = this.listeners.indexOf(listener); if (index !== -1) { this.listeners.splice(index, 1); } }; ConfigStore.prototype.getNavItems = function () { return this.filteredNavItems; }; ConfigStore.prototype.getSelectedNavItem = function () { return this.selectedNavItem; }; ConfigStore.prototype.isPreview = function () { return !this.selectedMyListItem; }; ConfigStore.prototype.getSelectedMyListItem = function () { return this.selectedMyListItem || this.selectedNavItem.getPreviewMyListItem(); }; ConfigStore.prototype.arePowerDomainSettingsEnabled = function () { return this.requirements.arePowerDomainSettingsEnabled(); }; ConfigStore.prototype.getDevicePinSolutionMap = function () { return this.requirements.getDevicePinSolutionMap(); }; ConfigStore.prototype.getNumGPIO = function () { return this.requirements.getNumGPIO(); }; ConfigStore.prototype.getNumGPIOLeft = function () { return this.requirements.getNumGPIOLeft(); }; ConfigStore.prototype.getActiveDesignSummaryTab = function () { return this.activeDesignSummaryTab; }; ConfigStore.prototype.getAvailablePeripheralNames = function () { return this.availablePeripheralNames; }; ConfigStore.prototype.solveAndNotify = function () { this.requirements.solve(); this.notify(); }; ConfigStore.prototype.notify = function () { _.each(this.listeners, function (listener) { listener(); }); }; return ConfigStore; }()); return ConfigStore; }); //# sourceMappingURL=configStore.js.map