qwc2
Version:
QGIS Web Client
9 lines • 2.13 kB
JavaScript
/**
* Copyright 2016-2024 Sourcepole AG
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/import ReducerIndex from"../reducers/index";import taskReducer from"../reducers/task";import ConfigUtils from"../utils/ConfigUtils";ReducerIndex.register("task",taskReducer);export var SET_CURRENT_TASK="SET_CURRENT_TASK";export var SET_CURRENT_TASK_BLOCKED="SET_CURRENT_TASK_BLOCKED";export function setCurrentTask(task){var mode=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var mapClickAction=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var data=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;return function(dispatch,getState){// Don't do anything if current task is blocked
if(getState().task&&getState().task.blocked===true){return}// Attempt to read mapClickAction from plugin configuration block if not set
if(!mapClickAction){var _find,_getState$localConfig;var device=ConfigUtils.isMobile()?"mobile":"desktop";mapClickAction=(_find=(((_getState$localConfig=getState().localConfig)===null||_getState$localConfig===void 0||(_getState$localConfig=_getState$localConfig.plugins)===null||_getState$localConfig===void 0?void 0:_getState$localConfig[device])||[]).find(function(config){return config.name===task}))===null||_find===void 0?void 0:_find.mapClickAction}dispatch({type:SET_CURRENT_TASK,id:task,mode:mode,data:data,unsetOnMapClick:mapClickAction==="unset",identifyEnabled:task===null||mapClickAction==="identify"})}}var beforeUnloadListener=null;export function setCurrentTaskBlocked(blocked){var unloadmsg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(beforeUnloadListener){window.removeEventListener("beforeunload",beforeUnloadListener);beforeUnloadListener=null}if(blocked&&unloadmsg!==null){beforeUnloadListener=function beforeUnloadListener(event){event.preventDefault();event.returnValue=unloadmsg;return unloadmsg};window.addEventListener("beforeunload",beforeUnloadListener)}return{type:SET_CURRENT_TASK_BLOCKED,blocked:blocked}}