Last active
August 29, 2015 14:05
-
-
Save ramrrr/1d524c30e7c14555af55 to your computer and use it in GitHub Desktop.
Patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package heimdall.ui.send; | |
| import static heimdall.ui.ember.core.EmberSerializer.getString; | |
| import heimdall.alert.AlertTemplateModule; | |
| import heimdall.auth.UserContext; | |
| import heimdall.channel.voice.AudioService; | |
| import heimdall.module.Module; | |
| import heimdall.module.ModuleRepository; | |
| import heimdall.module.ModuleResourceId; | |
| import heimdall.risk.EventRepository; | |
| import heimdall.ui.alert.AlertConstants; | |
| import heimdall.ui.core.menu.MenuEntry; | |
| import heimdall.utility.CallFlowInitializingHelper; | |
| import heimdall.utility.VoiceChannelConfigHelper; | |
| import java.util.Collections; | |
| import java.util.HashMap; | |
| import java.util.LinkedHashMap; | |
| import java.util.Map; | |
| import java.util.Set; | |
| import java.util.TreeMap; | |
| import javax.servlet.http.HttpServletRequest; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.http.HttpStatus; | |
| import org.springframework.http.MediaType; | |
| import org.springframework.http.ResponseEntity; | |
| import org.springframework.security.access.AccessDecisionManager; | |
| import org.springframework.security.access.ConfigAttribute; | |
| import org.springframework.security.core.GrantedAuthority; | |
| import org.springframework.security.core.context.SecurityContextHolder; | |
| import org.springframework.stereotype.Controller; | |
| import org.springframework.transaction.annotation.Transactional; | |
| import org.springframework.ui.Model; | |
| import org.springframework.web.bind.annotation.ModelAttribute; | |
| import org.springframework.web.bind.annotation.RequestBody; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| import org.springframework.web.bind.annotation.RequestMethod; | |
| import com.google.common.base.Strings; | |
| import com.google.gson.JsonObject; | |
| import com.google.gson.JsonParser; | |
| import com.typesafe.config.Config; | |
| import com.typesafe.config.ConfigValue; | |
| /** | |
| * | |
| * @author Vishal Joshi. | |
| * | |
| */ | |
| @Controller | |
| @RequestMapping("/sendDirect") | |
| @MenuEntry(value = "send.menu") | |
| public class SequentialAlertComposerController { | |
| static final int SUB_MENU_RANK = 1000; | |
| static final String REDIRECT_PREFIX = "redirect:"; | |
| static final String BASE_PATH = "/sendDirect"; | |
| private static final String ADDRESS_SEARCH_PROVIDER = "searchProviders"; | |
| private static final String ALERT_TEMPLATE_MODULE = "alertTemplateModule"; | |
| private static final String PRIVILIGE_ADD = "add"; | |
| private static final String RESOURCE_NONE = "none"; | |
| private static final String SIMPLE_SEND = "simpleSend"; | |
| private static final String CONFIG_ALERT_TEMPLATE = "ConfigAlertTemplate"; | |
| private static final String ALERT_TEMPLATE_CATEGORY = "AlertTemplateCategory"; | |
| private static final String MAP_RECIPIENT = "MapRecipient"; | |
| private static final String PERSON_OR_GROUP = "PersonOrGroup"; | |
| private static final String CHANNEL = "Channel"; | |
| private static final String MESSAGE = "Message"; | |
| private static final String EVENT_SUMMARY_CONFIG = "EventSummaryConfig"; | |
| private static final String EVENT_SUMMARY = "EventSummary"; | |
| private CallFlowInitializingHelper callFlowInitializingHelper; | |
| private EventRepository eventRepository; | |
| private AccessDecisionManager accessDecisionManager; | |
| private ModuleRepository moduleRepository; | |
| private UserContext userContext; | |
| private AudioService audioService; | |
| @Autowired | |
| private Config config; | |
| @Autowired | |
| public void setAudioService(final AudioService audioService) { | |
| this.audioService = audioService; | |
| } | |
| @Autowired | |
| public void setAccessDecisionManager( | |
| final AccessDecisionManager accessDecisionManager) { | |
| this.accessDecisionManager = accessDecisionManager; | |
| } | |
| @Autowired | |
| public void setEventRepository(final EventRepository eventRepository) { | |
| this.eventRepository = eventRepository; | |
| } | |
| @Autowired | |
| public void setCallFlowInitializingHelper( | |
| final CallFlowInitializingHelper callFlowInitializingHelper) { | |
| this.callFlowInitializingHelper = callFlowInitializingHelper; | |
| } | |
| @Autowired | |
| public void setModuleRepository(final ModuleRepository moduleRepository) { | |
| this.moduleRepository = moduleRepository; | |
| } | |
| @Autowired | |
| public void setUserContext(final UserContext userContext) { | |
| this.userContext = userContext; | |
| } | |
| /** | |
| * Populates the Country values from application configuration for the saved | |
| * 'address.search.provider' in the organization settings. | |
| * | |
| * @return Populates the Country values. | |
| */ | |
| @ModelAttribute("availableCountriesMap") | |
| public Map<String, String> getCountryValues() { | |
| final Map<String, String> countryMap = new TreeMap<String, String>(); | |
| String orgAddressSearchProvider = userContext.getOrganization() | |
| .getAddressSearchResourceValue(moduleRepository); | |
| if (orgAddressSearchProvider != null && !orgAddressSearchProvider.equals("")) { | |
| orgAddressSearchProvider = orgAddressSearchProvider | |
| + ".countryBounds"; | |
| final Set<Map.Entry<String, ConfigValue>> settings = config | |
| .getConfig(ADDRESS_SEARCH_PROVIDER).entrySet(); | |
| for (Map.Entry<String, ConfigValue> provider : settings) { | |
| if (provider.getKey() | |
| .equalsIgnoreCase(orgAddressSearchProvider)) { | |
| String countryString = provider.getValue().unwrapped() | |
| .toString(); | |
| if (!countryString.equals("")) { | |
| String[] conuntryPairStr = countryString.split(","); | |
| for (String string : conuntryPairStr) { | |
| String[] conuntry = string.split("_"); | |
| countryMap.put(conuntry[1], conuntry[0]); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return countryMap; | |
| } | |
| /** | |
| * | |
| * Populates the default Country which is first country in the country | |
| * bound. | |
| * | |
| * @return the default Country to be Selected | |
| */ | |
| @ModelAttribute("defaultCountrySelected") | |
| public String getDefaultCountry() { | |
| String defaultCountry = null; | |
| String orgAddressSearchProvider = userContext.getOrganization() | |
| .getAddressSearchResourceValue(moduleRepository); | |
| if (orgAddressSearchProvider != null && !orgAddressSearchProvider.equals("")) { | |
| orgAddressSearchProvider = orgAddressSearchProvider | |
| + ".countryBounds"; | |
| final Set<Map.Entry<String, ConfigValue>> settings = config | |
| .getConfig(ADDRESS_SEARCH_PROVIDER).entrySet(); | |
| for (Map.Entry<String, ConfigValue> provider : settings) { | |
| if (provider.getKey() | |
| .equalsIgnoreCase(orgAddressSearchProvider)) { | |
| String countryString = provider.getValue().unwrapped() | |
| .toString(); | |
| if (!countryString.equals("")) { | |
| String[] conuntryPairStr = countryString.split(","); | |
| String[] conuntry = conuntryPairStr[0].split("_"); | |
| defaultCountry = conuntry[0]; | |
| } else { | |
| defaultCountry = "NAN"; | |
| } | |
| } | |
| } | |
| } | |
| return defaultCountry; | |
| } | |
| /** | |
| * Return the view name for the composer view. | |
| * | |
| * @param httpServletRequest http servlet | |
| * @param model to populate. | |
| * @return the composer view. | |
| */ | |
| @RequestMapping("/newComposer") | |
| public String composer(final HttpServletRequest httpServletRequest, final Model model) { | |
| AlertComposerAttribute alertComposerAttribute = | |
| (AlertComposerAttribute) httpServletRequest.getAttribute("alertComposerAttribute"); | |
| callFlowInitializingHelper.ensureCallFlowData(); | |
| model.addAttribute("eventName", eventRepository.nextEventName()); | |
| setUserBasedRoles(model); | |
| boolean isSourceAT = checkSourceAT(alertComposerAttribute); | |
| boolean hasAccessToMap = checkSendAccess(model, isSourceAT); | |
| if (!hasAccessToMap) { | |
| return REDIRECT_PREFIX + BASE_PATH + "/Error"; | |
| } else { | |
| populateEventModel(model); | |
| Object type = alertComposerAttribute.getType(); | |
| if (type != null) { | |
| String typeInString = type.toString(); | |
| model.addAttribute("type", !Strings.isNullOrEmpty(typeInString) ? type : SIMPLE_SEND); | |
| } else { | |
| model.addAttribute("type", SIMPLE_SEND); | |
| } | |
| model.addAttribute("from", alertComposerAttribute.getFrom()); | |
| Object resendEventName = null; | |
| if (alertComposerAttribute.getAlertIds() != null) { | |
| model.addAttribute("alertIds", alertComposerAttribute.getAlertIds()); | |
| } else { | |
| model.addAttribute("alertIds", alertComposerAttribute.getAlertIdsStr()); | |
| } | |
| model.addAttribute("list", alertComposerAttribute.getList()); | |
| resendEventName = alertComposerAttribute.getResendEventName(); | |
| model.addAttribute("mapProvider", userContext.getOrganization() | |
| .getMapServerResourceValue(moduleRepository)); | |
| model.addAttribute("resendEventName", resendEventName); | |
| model.addAttribute("alertTemplateId", alertComposerAttribute.getAlertTemplateId()); | |
| model.addAttribute("sequence", buildSequenceString(model)); | |
| return "/sendDirect/sequentialAlertComposer"; | |
| } | |
| } | |
| private String buildSequenceString(final Model model) { | |
| String sequenceKey = ""; | |
| if (model.asMap().get("from") != null) { | |
| sequenceKey = sequenceKey.concat(CONFIG_ALERT_TEMPLATE + ","); | |
| model.addAttribute("from", "config"); | |
| if (model.asMap().get("alertTemplateId") != null) { | |
| model.addAttribute("type", "alertTemplateEdit"); | |
| } | |
| } else { | |
| sequenceKey = sequenceKey.concat(ALERT_TEMPLATE_CATEGORY + ","); | |
| } | |
| for (GrantedAuthority grantedAuthority : userContext.getUserDetails() | |
| .getAuthorities()) { | |
| if (grantedAuthority.getAuthority().equalsIgnoreCase( | |
| "MODULE:mapModule")) { | |
| sequenceKey = sequenceKey.concat(MAP_RECIPIENT + ","); | |
| } | |
| if (grantedAuthority.getAuthority().equalsIgnoreCase( | |
| "MODULE:recipientConfigurationModule")) { | |
| sequenceKey = sequenceKey.concat(PERSON_OR_GROUP + ","); | |
| } | |
| } | |
| sequenceKey = sequenceKey.concat(CHANNEL + ","); | |
| sequenceKey = sequenceKey.concat(MESSAGE + ","); | |
| if (model.asMap().get("from") != null) { | |
| sequenceKey = sequenceKey.concat(EVENT_SUMMARY_CONFIG + ","); | |
| } else { | |
| sequenceKey = sequenceKey.concat(EVENT_SUMMARY + ","); | |
| } | |
| return sequenceKey; | |
| } | |
| private boolean checkSourceAT(final AlertComposerAttribute alertComposerAttribute) { | |
| if (alertComposerAttribute != null && alertComposerAttribute.getSource() != null | |
| && (alertComposerAttribute.getSource().equalsIgnoreCase("alertTemplateEdit") | |
| || alertComposerAttribute.getSource().equalsIgnoreCase("alertTemplateAdd"))) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * Checks for event name unique. | |
| * | |
| * @param body event json | |
| * @return ResponseEntity<String> | |
| */ | |
| @RequestMapping(value = "/event/isNameExists", method = RequestMethod.POST, | |
| produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) | |
| @Transactional | |
| public ResponseEntity<String> isNameExists(@RequestBody final String body) { | |
| final JsonObject eventJson = new JsonParser().parse(body).getAsJsonObject(); | |
| String eventName = getString(eventJson.get("name")); | |
| final boolean isNameExists = eventRepository | |
| .getByEventName(eventName) == null ? false : true; | |
| if (isNameExists) { | |
| return new ResponseEntity<>("\"true\"", HttpStatus.OK); | |
| } else { | |
| return new ResponseEntity<>("\"false\"", HttpStatus.OK); | |
| } | |
| } | |
| /** | |
| * | |
| * @param model as model | |
| */ | |
| public void setUserBasedRoles(final Model model) { | |
| boolean hasAccessToSetMapAsDefault = false; | |
| try { | |
| accessDecisionManager.decide(SecurityContextHolder.getContext() | |
| .getAuthentication(), this, Collections | |
| .<ConfigAttribute>singleton(new ConfigAttribute() { | |
| @Override | |
| public String getAttribute() { | |
| return "MODULE:mapModule"; | |
| } | |
| })); | |
| accessDecisionManager.decide(SecurityContextHolder.getContext() | |
| .getAuthentication(), this, Collections | |
| .<ConfigAttribute>singleton(new ConfigAttribute() { | |
| @Override | |
| public String getAttribute() { | |
| return "PRIVILEGE:mapModule.setMapAsDefault:add"; | |
| } | |
| })); | |
| hasAccessToSetMapAsDefault = true; | |
| } catch (Exception e) { | |
| hasAccessToSetMapAsDefault = false; | |
| } | |
| model.addAttribute("hasAccessToSetMapAsDefault", | |
| hasAccessToSetMapAsDefault); | |
| } | |
| /** | |
| * Checks whether user has access to alertComposerModule. | |
| * @param isSourceAT true if source AT | |
| * @param model as model | |
| * @return true user has access to alertComposerModule else false. | |
| */ | |
| public boolean checkSendAccess(final Model model, final Boolean isSourceAT) { | |
| if (!(fillModelForAccesses(checkModulePrivilegesFor()).get( | |
| "alertComposerModule.none:live") || fillModelForAccesses( | |
| checkModulePrivilegesFor()).get( | |
| "alertComposerModule.none:training")) && !isSourceAT) { | |
| model.addAttribute("hasAccessToSetMapAsDefault", false); | |
| return false; | |
| } else { | |
| model.addAttribute("hasAccessToSetMapAsDefault", true); | |
| return true; | |
| } | |
| } | |
| /** | |
| * Returns map of module and their required privileges. | |
| * | |
| * @return map | |
| */ | |
| protected Map<String, String> checkModulePrivilegesFor() { | |
| final Map<String, String> modulePrivilegesMap = new HashMap<String, String>(); | |
| modulePrivilegesMap.put("alertComposerModule.none:live", | |
| "alertComposerModule"); | |
| modulePrivilegesMap.put("alertComposerModule.none:training", | |
| "alertComposerModule"); | |
| modulePrivilegesMap.put("recipientConfigurationModule.person:view", | |
| "recipientConfigurationModule"); | |
| modulePrivilegesMap.put("recipientConfigurationModule", | |
| "none"); | |
| modulePrivilegesMap.put("mapModule", | |
| "none"); | |
| return modulePrivilegesMap; | |
| } | |
| /** | |
| * Fills model for access privileges. | |
| * | |
| * @param modulePrivilegeMap map of module and privileges. | |
| * @return map | |
| */ | |
| protected Map<String, Boolean> fillModelForAccesses( | |
| final Map<String, String> modulePrivilegeMap) { | |
| final Map<String, Boolean> accessMap = new HashMap<>(); | |
| for (final Map.Entry<String, String> entry : modulePrivilegeMap | |
| .entrySet()) { | |
| try { | |
| if (!"none".equals(entry.getValue())) { | |
| setAccess(entry, "MODULE:" + entry.getValue()); | |
| setAccess(entry, "PRIVILEGE:" + entry.getKey()); | |
| } else { | |
| setAccess(entry, "MODULE:" + entry.getKey()); | |
| } | |
| accessMap.put(entry.getKey(), true); | |
| } catch (Exception e) { | |
| accessMap.put(entry.getKey(), false); | |
| } | |
| } | |
| return accessMap; | |
| } | |
| private void setAccess(final Map.Entry<String, String> entry, | |
| final String entryVal) { | |
| accessDecisionManager.decide(SecurityContextHolder.getContext() | |
| .getAuthentication(), this, Collections | |
| .<ConfigAttribute>singleton(new ConfigAttribute() { | |
| @Override | |
| public String getAttribute() { | |
| return entryVal; | |
| } | |
| })); | |
| } | |
| private boolean canUserAddAlertTemplate() { | |
| for (Module module : moduleRepository.getModules()) { | |
| if (module instanceof AlertTemplateModule) { | |
| ModuleResourceId resourceId = new ModuleResourceId( | |
| ALERT_TEMPLATE_MODULE, RESOURCE_NONE, PRIVILIGE_ADD); | |
| boolean hasAccess = userContext.getUserRole().hasPrivilege( | |
| resourceId); | |
| if (userContext.isModuleAccessible(module) && hasAccess) { | |
| return true; | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| public Map<String, String> getAllVoices() { | |
| return audioService.getVoices(); | |
| } | |
| private void populateEventModel(final Model model) { | |
| model.addAttribute("voiceNoOfTries", | |
| VoiceChannelConfigHelper.getNumberOfTries()); | |
| model.addAttribute("voiceHangupTimes", | |
| VoiceChannelConfigHelper.getNoOfCallTimes()); | |
| model.addAttribute("voiceIntervalOfTries", | |
| VoiceChannelConfigHelper.getIntervalTimes()); | |
| model.addAttribute("validityDays", | |
| VoiceChannelConfigHelper.getValidityDays()); | |
| model.addAttribute("originNumbers", AlertComposerUtil.getOriginNumbers( | |
| moduleRepository, userContext)); | |
| Map<String, String> priorities = new LinkedHashMap<>(); | |
| final int maxPriority = AlertComposerUtil.getMaxPriority( | |
| moduleRepository, userContext); | |
| for (int i = maxPriority; i <= 8; i++) { | |
| priorities.put(String.valueOf(i), String.valueOf(i)); | |
| } | |
| model.addAttribute("voicePriorities", priorities); | |
| model.addAttribute("voiceMaxoutboundLines", AlertComposerUtil | |
| .getMaxOutboundLines(moduleRepository, userContext)); | |
| model.addAttribute("voiceMaxCancelAlertDays", | |
| AlertComposerUtil.getMaxAlertDays()); | |
| model.addAttribute("voices", | |
| AlertComposerUtil.getVoices(moduleRepository, userContext)); | |
| model.addAttribute("smsOperators", | |
| AlertComposerUtil.getSmsOperators(moduleRepository)); | |
| model.addAttribute("canAddAlertTemplate", canUserAddAlertTemplate()); | |
| model.addAttribute("allVoices", getAllVoices()); | |
| model.addAttribute("allVoices", getAllVoices()); | |
| model.addAttribute("orgModules", userContext.getOrganization() | |
| .getModules(moduleRepository)); | |
| model.addAttribute("privelegeMap", | |
| fillModelForAccesses(checkModulePrivilegesFor())); | |
| model.addAttribute("timeZoneOffset", userContext.getUser() | |
| .getTimeZone().getRawOffset()); | |
| model.addAttribute("dateFormat", heimdall.utility.DateUtil.getDateFormat(userContext)); | |
| model.addAttribute("maxLimit", AlertConstants.LENGTH_FOR_TTS_TEXTS); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var App = require("core/App"); | |
| var HasModal = require("core/HasModal"); | |
| require("../map/MapRecipientView") | |
| require("../map/MapRecipientController") | |
| require("../map/MapActionsView") | |
| require("../map/MapActionsController") | |
| require("../map/MapDirectoryView") | |
| require("../map/MapDirectoryController") | |
| require("../availableChannels/ChannelSelectionView") | |
| require("../availableChannels/ChannelSelectionController") | |
| require("../messagesForChannels/MessageForChannelsView") | |
| require("../messagesForChannels/MessageForChannelsController") | |
| require("../gas/GasView") | |
| require("../gas/GasController") | |
| require("../recipient/PersonSelectView") | |
| require("../recipient/PersonSelectController") | |
| require("../recipient/GroupSelectView") | |
| require("../recipient/GroupSelectController") | |
| require("./NavigationButton") | |
| require("./TabButton") | |
| require("../eventStatus/EventStatusView") | |
| require("../eventStatus/EventStatusController") | |
| var ViewSwitcher = require("alertComposer/send/ViewSwitcher"); | |
| var fromAtConfig = AlertTemplateData.fromAlertTemplate; | |
| /** | |
| * Create a value that is bound to the current alert. | |
| * | |
| * This will create a computed property, which will have one value for each | |
| * alert. | |
| * | |
| * @param defaultValue initial value for the property | |
| * @returns computed property for the value | |
| */ | |
| function alertBoundValue(defaultValue) { | |
| var values = {} | |
| return function (key, value) { | |
| if (!values[this.get("model")]) { | |
| values[this.get("model")] = defaultValue; | |
| } | |
| if (arguments.length === 1) { | |
| return values[this.get("model")]; | |
| } else { | |
| values[this.get("model")] = value | |
| return value; | |
| } | |
| }.property("model"); | |
| } | |
| module.exports = App.SequentialEventAlertController = Ember.ObjectController.extend(HasModal, ViewSwitcher, { | |
| currentViewName: null, | |
| isMap: false, | |
| isAlertTemplate: false, | |
| isPersonOrGroup: false, | |
| isChannel: false, | |
| isMessage: false, | |
| isEventSummary: false, | |
| resetAlertTemplate: false, | |
| isAlertTemplateConfig: false, | |
| isEventSummaryConfig: false, | |
| fromATConfig: false, | |
| isReset:false, | |
| isPersonView:false, | |
| isGasTabEnabled: false, | |
| isMapTabEnabled: false, | |
| disabled:[], | |
| overViewSequence : 0, | |
| disabledQueueManipulator: function() { | |
| this.get('disabled').removeObject(this.get('currentViewName')) | |
| }.observes('currentViewName'), | |
| init: function () { | |
| var self = this; | |
| this.set('currentViewName', this.swtichToFirst()); | |
| this.populateArrayWithSequence(this.get('disabled')); | |
| //remove first screen as it has to be enabled by default | |
| this.get('disabled').removeObject(this.get('currentViewName')) | |
| if (fromAtConfig) { | |
| this.set("fromATConfig", true); | |
| } | |
| window.privelegeMap.forEach(function (option) { | |
| if ("recipientConfigurationModule.person:view" == option.key && "true" == option.value) { | |
| self.isPersonView = true; | |
| } | |
| if ("recipientConfigurationModule" == option.key && "true" == option.value) { | |
| self.isGasTabEnabled = true; | |
| } | |
| if ("mapModule" == option.key && "true" == option.value) { | |
| self.isMapTabEnabled = true; | |
| } | |
| }) | |
| this.populateOverViewSequence(); | |
| }, | |
| populateOverViewSequence:function(){ | |
| this.set("overViewSequence", this.getSequence("EventSummary")); | |
| console.log("overViewSequence",this.get("overViewSequence")) | |
| }, | |
| next: function () { | |
| //call for view centric logic will be fired from here. | |
| this.set('currentViewName', this.nextView(this.get('currentViewName'))); | |
| }, | |
| previous: function () { | |
| //call for view centric logic will be fired from here. | |
| this.set('currentViewName', this.previousView(this.get('currentViewName'))); | |
| }, | |
| cancel: function (e) { | |
| //call for view centric logic will be fired from here. | |
| this.setModal('none'); | |
| // On clicking the cancel button, we need to reset the event model as well as alert template | |
| //data if user is editing the AT. Also need to reset event model if user is resending the alert. | |
| if (this.get('fromATConfig')) { | |
| var alertTemplate = this.get('target.controllers.AlertTemplateDetails.alertTemplate'); | |
| if (alertTemplate && alertTemplate.get('id')) { // Edit Alert template | |
| location.href = App.get("baseUrl") + "/alertTemplate/edit/"+ alertTemplate.get('id'); | |
| } else { // Add new alert template | |
| location.href = App.get("baseUrl") + "/alertTemplate/add"; | |
| } | |
| } else { // Simple send | |
| location.href = App.get("baseUrl") + "/sendDirect/newComposer"; | |
| } | |
| }, | |
| save: function() { | |
| //here I am not using switch to last of ViewSwitcher as click | |
| //on save should always take to event summary view and not | |
| // to last view. | |
| if (this.get('fromATConfig')) { | |
| this.set('currentViewName', 'EventSummaryConfig'); | |
| } else { | |
| this.set('currentViewName', 'EventSummary'); | |
| } | |
| }, | |
| currentViewSequence:function(){ | |
| return this.getCurrentSequence(this.get('currentViewName')); | |
| }.property('currentViewName'), | |
| alertModelObserver:function() { | |
| this.set('model',this.get('target.activeAlert')) | |
| }.observes('target.activeAlert'), | |
| getSequence: function(viewName){ | |
| return this.getCurrentSequence(viewName)+1; | |
| }, | |
| setCurrentViewName: function(viewName) { | |
| this.set('currentViewName',viewName); | |
| }, | |
| confirmCancel: function () { | |
| this.setModal('cancleComposer'); | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var App = require("core/App"); | |
| var HasModal = require("core/HasModal"); | |
| require("../map/MapRecipientView") | |
| require("../map/MapRecipientController") | |
| require("../map/MapActionsView") | |
| require("../map/MapActionsController") | |
| require("../map/MapDirectoryView") | |
| require("../map/MapDirectoryController") | |
| require("../availableChannels/ChannelSelectionView") | |
| require("../availableChannels/ChannelSelectionController") | |
| require("../messagesForChannels/MessageForChannelsView") | |
| require("../messagesForChannels/MessageForChannelsController") | |
| require("../gas/GasView") | |
| require("../gas/GasController") | |
| require("../recipient/PersonSelectView") | |
| require("../recipient/PersonSelectController") | |
| require("../recipient/GroupSelectView") | |
| require("../recipient/GroupSelectController") | |
| require("./NavigationButton") | |
| require("./TabButton") | |
| require("../eventStatus/EventStatusView") | |
| require("../eventStatus/EventStatusController") | |
| var ViewSwitcher = require("alertComposer/send/ViewSwitcher"); | |
| var fromAtConfig = AlertTemplateData.fromAlertTemplate; | |
| /** | |
| * Create a value that is bound to the current alert. | |
| * | |
| * This will create a computed property, which will have one value for each | |
| * alert. | |
| * | |
| * @param defaultValue initial value for the property | |
| * @returns computed property for the value | |
| */ | |
| function alertBoundValue(defaultValue) { | |
| var values = {} | |
| return function (key, value) { | |
| if (!values[this.get("model")]) { | |
| values[this.get("model")] = defaultValue; | |
| } | |
| if (arguments.length === 1) { | |
| return values[this.get("model")]; | |
| } else { | |
| values[this.get("model")] = value | |
| return value; | |
| } | |
| }.property("model"); | |
| } | |
| module.exports = App.SequentialEventAlertController = Ember.ObjectController.extend(HasModal, ViewSwitcher, { | |
| currentViewName: null, | |
| isMap: false, | |
| isAlertTemplate: false, | |
| isPersonOrGroup: false, | |
| isChannel: false, | |
| isMessage: false, | |
| isEventSummary: false, | |
| resetAlertTemplate: false, | |
| isAlertTemplateConfig: false, | |
| isEventSummaryConfig: false, | |
| fromATConfig: false, | |
| isReset:false, | |
| isPersonView:false, | |
| isGasTabEnabled: false, | |
| isMapTabEnabled: false, | |
| disabled:[], | |
| overViewSequence : 0, | |
| disabledQueueManipulator: function() { | |
| this.get('disabled').removeObject(this.get('currentViewName')) | |
| }.observes('currentViewName'), | |
| init: function () { | |
| var self = this; | |
| this.set('currentViewName', this.swtichToFirst()); | |
| this.populateArrayWithSequence(this.get('disabled')); | |
| //remove first screen as it has to be enabled by default | |
| this.get('disabled').removeObject(this.get('currentViewName')) | |
| if (fromAtConfig) { | |
| this.set("fromATConfig", true); | |
| } | |
| window.privelegeMap.forEach(function (option) { | |
| if ("recipientConfigurationModule.person:view" == option.key && "true" == option.value) { | |
| self.isPersonView = true; | |
| } | |
| if ("recipientConfigurationModule" == option.key && "true" == option.value) { | |
| self.isGasTabEnabled = true; | |
| } | |
| if ("mapModule" == option.key && "true" == option.value) { | |
| self.isMapTabEnabled = true; | |
| } | |
| }) | |
| this.populateOverViewSequence(); | |
| }, | |
| populateOverViewSequence:function(){ | |
| this.set("overViewSequence", this.getSequence("EventSummary")); | |
| console.log("overViewSequence",this.get("overViewSequence")) | |
| }, | |
| next: function () { | |
| //call for view centric logic will be fired from here. | |
| this.set('currentViewName', this.nextView(this.get('currentViewName'))); | |
| }, | |
| previous: function () { | |
| //call for view centric logic will be fired from here. | |
| this.set('currentViewName', this.previousView(this.get('currentViewName'))); | |
| }, | |
| cancel: function (e) { | |
| //call for view centric logic will be fired from here. | |
| this.setModal('none'); | |
| // On clicking the cancel button, we need to reset the event model as well as alert template | |
| //data if user is editing the AT. Also need to reset event model if user is resending the alert. | |
| if (this.get('fromATConfig')) { | |
| var alertTemplate = this.get('target.controllers.AlertTemplateDetails.alertTemplate'); | |
| if (alertTemplate && alertTemplate.get('id')) { // Edit Alert template | |
| location.href = App.get("baseUrl") + "/alertTemplate/edit/"+ alertTemplate.get('id'); | |
| } else { // Add new alert template | |
| location.href = App.get("baseUrl") + "/alertTemplate/add"; | |
| } | |
| } else { // Simple send | |
| location.href = App.get("baseUrl") + "/sendDirect/newComposer"; | |
| } | |
| }, | |
| save: function() { | |
| //here I am not using switch to last of ViewSwitcher as click | |
| //on save should always take to event summary view and not | |
| // to last view. | |
| if (this.get('fromATConfig')) { | |
| this.set('currentViewName', 'EventSummaryConfig'); | |
| } else { | |
| this.set('currentViewName', 'EventSummary'); | |
| } | |
| }, | |
| currentViewSequence:function(){ | |
| return this.getCurrentSequence(this.get('currentViewName')); | |
| }.property('currentViewName'), | |
| alertModelObserver:function() { | |
| this.set('model',this.get('target.activeAlert')) | |
| }.observes('target.activeAlert'), | |
| getSequence: function(viewName){ | |
| return this.getCurrentSequence(viewName)+1; | |
| }, | |
| setCurrentViewName: function(viewName) { | |
| this.set('currentViewName',viewName); | |
| }, | |
| confirmCancel: function () { | |
| this.setModal('cancleComposer'); | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment