Search in sources :

Example 1 with SysMenuVO

use of com.netsteadfast.greenstep.vo.SysMenuVO in project bamboobsc by billchen198318.

the class MenuSupportUtils method getMenuData.

/**
	 * 取回下拉選單
	 * 
	 * @param basePath
	 * @param sys
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
public static Map<String, String> getMenuData(String basePath, TbSys sys, String jsessionId, String localeCode) throws ServiceException, Exception {
    Map<String, String> menuData = new HashMap<String, String>();
    List<SysMenuVO> menuList = loadSysMenuData(sys.getSysId());
    if (menuList == null || menuList.size() < 1) {
        return menuData;
    }
    StringBuilder htmlSb = new StringBuilder();
    StringBuilder jsSb = new StringBuilder();
    StringBuilder dlgSb = new StringBuilder();
    Map<String, String> jsFunctionMap = new HashMap<String, String>();
    /*
		for (SysMenuVO sysMenu : menuList) { // create combobox menu javascript
			if (!YesNo.YES.equals(sysMenu.getEnableFlag())) {
				continue;
			}
			if (TYPE_IS_FOLDER.equals(sysMenu.getItemType())) { // 目錄不須要 
				continue;
			}
			String openTabFn = sysMenu.getProgId() + "_TabShow()";
			String refreshTabFn = sysMenu.getProgId() + "_TabRefresh()";
			String closeTabFn = sysMenu.getProgId() + "_TabClose()";
			String tabId = sysMenu.getProgId() + "_ChildTab";	
			jsSb.append("function ").append( openTabFn ).append(" { ");
			jsSb.append("	viewPage.addOrUpdateContentPane(	");
			jsSb.append("		'").append(Constants.MAIN_TabContainer_ID).append("',	");
			jsSb.append("		'").append(tabId).append("',	");
			jsSb.append("		'").append( StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysMenu.getIcon()) ) ).append(StringEscapeUtils.escapeEcmaScript(sysMenu.getName())).append("',	");
			jsSb.append("		'").append( getUrl(basePath, sys, sysMenu, jsessionId) ).append("',	");			
			jsSb.append("		true,	");
			jsSb.append("		true");
			jsSb.append("	);	");
			jsSb.append("}	");
			jsSb.append("\n");
			jsSb.append("function ").append( refreshTabFn ).append(" { ");
			jsSb.append("	viewPage.refreshContentPane('").append(tabId).append("'); ");
			jsSb.append("}	");
			jsSb.append("\n");
			jsSb.append("function ").append( closeTabFn ).append(" { ");
			jsSb.append("	viewPage.closeContentPane('").append(Constants.MAIN_TabContainer_ID).append("', '").append(tabId).append("'); ");
			jsSb.append("}	");
			jsSb.append("\n");			
			jsFunctionMap.put(sysMenu.getProgId(), openTabFn );
		}
		*/
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("progSystem", sys.getSysId());
    List<TbSysProg> sysProgList = sysProgService.findListByParams(params);
    for (int i = 0; sysProgList != null && i < sysProgList.size(); i++) {
        TbSysProg sysProg = sysProgList.get(i);
        if (MenuItemType.FOLDER.equals(sysProg.getItemType())) {
            // 目錄不須要 
            continue;
        }
        String openTabFn = sysProg.getProgId() + "_TabShow()";
        if (YesNo.YES.equals(sysProg.getEditMode())) {
            openTabFn = sysProg.getProgId() + "_TabShow(oid)";
        }
        String refreshTabFn = sysProg.getProgId() + "_TabRefresh()";
        String closeTabFn = sysProg.getProgId() + "_TabClose()";
        String tabId = sysProg.getProgId() + "_ChildTab";
        boolean iframeMode = false;
        if (YesNo.YES.equals(sysProg.getIsWindow())) {
            iframeMode = true;
        }
        String progMultiName = getProgramMultiName(sysProg, localeCode);
        jsSb.append("function ").append(openTabFn).append(" { ");
        jsSb.append("	viewPage.addOrUpdateContentPane(	");
        jsSb.append("		'").append(Constants.MAIN_TabContainer_ID).append("',	");
        jsSb.append("		'").append(tabId).append("',	");
        //jsSb.append("		'").append( StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysProg.getIcon()) ) ).append(StringEscapeUtils.escapeEcmaScript(sysProg.getName())).append("',	");
        // 改用讀取多語系名稱
        jsSb.append("		'").append(StringEscapeUtils.escapeEcmaScript(IconUtils.getMenuIcon(basePath, sysProg.getIcon()))).append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("',	");
        if (YesNo.YES.equals(sysProg.getEditMode())) {
            // 編輯資料Edit 模式
            jsSb.append("		'").append(getUrl(basePath, sys, sysProg, jsessionId)).append("&fields.oid=' + oid,	");
        } else {
            // 查詢Query 或 新增Create 模式
            jsSb.append("		'").append(getUrl(basePath, sys, sysProg, jsessionId)).append("',	");
        }
        jsSb.append("		true,	");
        jsSb.append("		true,	");
        jsSb.append("	").append(String.valueOf(iframeMode)).append("	");
        jsSb.append("	);	");
        jsSb.append("}	");
        jsSb.append("\n");
        jsSb.append("function ").append(refreshTabFn).append(" { ");
        jsSb.append("	viewPage.refreshContentPane('").append(tabId).append("'); ");
        jsSb.append("}	");
        jsSb.append("\n");
        jsSb.append("function ").append(closeTabFn).append(" { ");
        jsSb.append("	viewPage.closeContentPane('").append(Constants.MAIN_TabContainer_ID).append("', '").append(tabId).append("'); ");
        jsSb.append("}	");
        jsSb.append("\n");
        //jsSb.append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("['").append( sysProg.getProgId() ).append("'] = '").append( StringEscapeUtils.escapeEcmaScript( sysProg.getName() ) ).append("';");
        // 改用讀取多語系名稱
        jsSb.append(Constants.GS_GET_APPLICATION_NAME_SCRIPT_OBJ).append("['").append(sysProg.getProgId()).append("'] = '").append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append("';");
        jsSb.append("\n");
        jsFunctionMap.put(sysProg.getProgId(), openTabFn);
        String dlgId = "";
        if (YesNo.YES.equals(sysProg.getIsDialog())) {
            dlgId = sysProg.getProgId() + "_Dlg";
        }
        if (!StringUtils.isBlank(dlgId)) {
            // 有 dialog 
            dlgSb.append("<div id=\"" + dlgId + "\" data-dojo-type=\"dojox.widget.DialogSimple\" ").append("data-dojo-props='href:\"").append(getUrl(basePath, sys, sysProg, jsessionId)).append("\",").append("	style:\"width: ").append(sysProg.getDialogW()).append("px; height: ").append(sysProg.getDialogH()).append("px\",").append("	title:\"").append(IconUtils.getMenuIcon(basePath, sysProg.getIcon()).replaceAll("'", "\\\\\"")).append(StringEscapeUtils.escapeEcmaScript(progMultiName)).append(// 改用讀取多語系名稱
            "\",").append("	refreshOnShow:\"true\", executeScripts:\"true\" ").append(" '></div>").append("\n");
            String dlgOpenFn = sysProg.getProgId() + "_DlgShow()";
            String dlgHideFn = sysProg.getProgId() + "_DlgHide()";
            if (YesNo.YES.equals(sysProg.getEditMode())) {
                dlgOpenFn = sysProg.getProgId() + "_DlgShow(oid)";
            }
            jsSb.append("function ").append(dlgOpenFn).append(" { ");
            String dlgUrl = "";
            if (YesNo.YES.equals(sysProg.getEditMode())) {
                // 編輯資料Edit 模式					
                dlgUrl = "'" + getUrl(basePath, sys, sysProg, jsessionId) + "&fields.oid=' + oid; ";
                jsSb.append("	var dlgUrl=").append(dlgUrl);
                jsSb.append("	dijit.byId('").append(dlgId).append("').set('href', dlgUrl); ");
            }
            jsSb.append("	dijit.byId('").append(dlgId).append("').show();	");
            jsSb.append("}	");
            jsSb.append("\n");
            jsSb.append("function ").append(dlgHideFn).append(" { ");
            jsSb.append("	dijit.byId('").append(dlgId).append("').hide();	");
            jsSb.append("}	");
            jsSb.append("\n");
        }
    }
    // create combobox menu html
    htmlSb.append("<div data-dojo-type='dijit.PopupMenuItem' >");
    //htmlSb.append("	<span>").append( IconUtils.getMenuIcon(basePath, sys.getIcon()) ).append(sys.getName()).append("</span>");		
    // 改用找多語言設定
    htmlSb.append("	<span>").append(IconUtils.getMenuIcon(basePath, sys.getIcon())).append(getSystemMultiName(sys, localeCode)).append("</span>");
    List<SysMenuVO> parentSysMenuList = searchFolder(menuList);
    htmlSb.append("<div dojoType='dijit.Menu' >");
    for (SysMenuVO sysMenu : parentSysMenuList) {
        List<SysMenuVO> itemSysMenuList = searchItem(sysMenu.getOid(), menuList);
        if (itemSysMenuList == null || itemSysMenuList.size() < 1) {
            continue;
        }
        String multiProgName = getProgramMultiName(sysMenu, localeCode);
        htmlSb.append("<div data-dojo-type='dijit.PopupMenuItem' >");
        //htmlSb.append("<span>").append( IconUtils.getMenuIcon(basePath, sysMenu.getIcon()) ).append(sysMenu.getName()).append("</span>");
        // 改用找多語言設定
        htmlSb.append("<span>").append(IconUtils.getMenuIcon(basePath, sysMenu.getIcon())).append(multiProgName).append("</span>");
        htmlSb.append("<div data-dojo-type='dijit.Menu' >");
        for (SysMenuVO itemMenu : itemSysMenuList) {
            String itemMultiProgName = getProgramMultiName(itemMenu, localeCode);
            htmlSb.append("<div data-dojo-type='dijit.MenuItem' data-dojo-props='onClick:function(){ ").append(StringUtils.defaultString(jsFunctionMap.get(itemMenu.getProgId()))).append(" }'>").append(IconUtils.getMenuIcon(basePath, itemMenu.getIcon())).append(// 改用找多語言設定
            itemMultiProgName).append("</div>");
        }
        htmlSb.append("</div>");
        htmlSb.append("</div>");
    }
    htmlSb.append("</div>");
    htmlSb.append("</div>");
    menuData.put(MENU_ITEM_JAVASCRIPT, jsSb.toString());
    menuData.put(MENU_ITEM_HTML, htmlSb.toString());
    menuData.put(MENU_ITEM_DIALOG, dlgSb.toString());
    return menuData;
}
Also used : HashMap(java.util.HashMap) SysMenuVO(com.netsteadfast.greenstep.vo.SysMenuVO) TbSysProg(com.netsteadfast.greenstep.po.hbm.TbSysProg)

Example 2 with SysMenuVO

use of com.netsteadfast.greenstep.vo.SysMenuVO in project bamboobsc by billchen198318.

the class MenuSupportUtils method loadSysMenuData.

protected static List<SysMenuVO> loadSysMenuData(String system) throws ServiceException, Exception {
    List<SysMenuVO> menuList = null;
    TbSys sys = new TbSys();
    sys.setSysId(system);
    if (sysService.countByEntityUK(sys) != 1) {
        // 必需要有 TB_SYS 資料
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
    }
    Subject subject = SecurityUtils.getSubject();
    String account = (String) subject.getPrincipal();
    if (StringUtils.isBlank(account)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
    }
    if (subject.hasRole(Constants.SUPER_ROLE_ADMIN) || subject.hasRole(Constants.SUPER_ROLE_ALL)) {
        account = null;
    }
    DefaultResult<List<SysMenuVO>> result = sysMenuService.findForMenuGenerator(system, account);
    if (result.getValue() != null) {
        menuList = result.getValue();
    }
    if (menuList == null) {
        menuList = new ArrayList<SysMenuVO>();
    }
    return menuList;
}
Also used : TbSys(com.netsteadfast.greenstep.po.hbm.TbSys) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysMenuVO(com.netsteadfast.greenstep.vo.SysMenuVO) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Subject(org.apache.shiro.subject.Subject)

Example 3 with SysMenuVO

use of com.netsteadfast.greenstep.vo.SysMenuVO in project bamboobsc by billchen198318.

the class SystemMenuLogicServiceImpl method createOrUpdate.

/**
	 * 更新或是新增 TB_SYS_MENU 資料
	 * 
	 * @param folderProgramOid
	 * @param childProgramOidList
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> createOrUpdate(String folderProgramOid, List<String> childProgramOidList) throws ServiceException, Exception {
    if (StringUtils.isBlank(folderProgramOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    result.setValue(false);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
    // 找 TB_SYS_PROG 資料
    SysProgVO sysProg = new SysProgVO();
    sysProg.setOid(folderProgramOid);
    DefaultResult<SysProgVO> spResult = this.sysProgService.findObjectByOid(sysProg);
    if (spResult.getValue() == null) {
        throw new ServiceException(spResult.getSystemMessage().getValue());
    }
    sysProg = spResult.getValue();
    // 找出 TB_SYS_MENU 原資料 , 沒有資料就是新增
    SysMenuVO sysMenu = new SysMenuVO();
    sysMenu.setProgId(sysProg.getProgId());
    sysMenu.setParentOid(ZeroKeyProvide.OID_KEY);
    if (this.sysMenuService.countByUK(sysMenu) > 0) {
        // update 更新
        DefaultResult<SysMenuVO> smResult = this.sysMenuService.findByUK(sysMenu);
        if (smResult.getValue() == null) {
            throw new ServiceException(smResult.getSystemMessage().getValue());
        }
        sysMenu = smResult.getValue();
    } else {
        // create new 新產
        sysMenu.setProgId(sysProg.getProgId());
        sysMenu.setParentOid(ZeroKeyProvide.OID_KEY);
        sysMenu.setEnableFlag(YesNo.YES);
        DefaultResult<SysMenuVO> smResult = this.sysMenuService.saveObject(sysMenu);
        if (smResult.getValue() == null) {
            throw new ServiceException(smResult.getSystemMessage().getValue());
        }
        sysMenu = smResult.getValue();
    }
    this.removeMenuChildData(sysMenu);
    this.createOrUpdate(sysMenu, childProgramOidList);
    result.setValue(true);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysMenuVO(com.netsteadfast.greenstep.vo.SysMenuVO) SysProgVO(com.netsteadfast.greenstep.vo.SysProgVO) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SysMenuVO

use of com.netsteadfast.greenstep.vo.SysMenuVO in project bamboobsc by billchen198318.

the class SystemMenuLogicServiceImpl method createOrUpdate.

private void createOrUpdate(SysMenuVO parentSysMenu, List<String> childProgramOidList) throws ServiceException, Exception {
    for (String progOid : childProgramOidList) {
        SysProgVO sysProg = new SysProgVO();
        sysProg.setOid(progOid);
        DefaultResult<SysProgVO> spResult = this.sysProgService.findObjectByOid(sysProg);
        if (spResult.getValue() == null) {
            throw new ServiceException(spResult.getSystemMessage().getValue());
        }
        sysProg = spResult.getValue();
        SysMenuVO childSysMenu = new SysMenuVO();
        childSysMenu.setProgId(sysProg.getProgId());
        childSysMenu.setParentOid(parentSysMenu.getOid());
        childSysMenu.setEnableFlag(YesNo.YES);
        DefaultResult<SysMenuVO> result = this.sysMenuService.saveObject(childSysMenu);
        if (result.getValue() == null) {
            throw new ServiceException(result.getSystemMessage().getValue());
        }
    }
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysMenuVO(com.netsteadfast.greenstep.vo.SysMenuVO) SysProgVO(com.netsteadfast.greenstep.vo.SysProgVO)

Example 5 with SysMenuVO

use of com.netsteadfast.greenstep.vo.SysMenuVO in project bamboobsc by billchen198318.

the class SystemMenuLogicServiceImpl method findForMenuSettingsEnableAndAll.

/**
	 * 找出選單設定功能要的
	 * 已在選單的程式 與 同SYS的程式
	 * 
	 * map 中的  key 
	 * enable	- 已在選單的程式
	 * all	- 同SYS的程式
	 * 
	 * @param folderProgramOid
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@ServiceMethodAuthority(type = { ServiceMethodType.SELECT })
@Override
public Map<String, List<SysProgVO>> findForMenuSettingsEnableAndAll(String folderProgramOid) throws ServiceException, Exception {
    if (StringUtils.isBlank(folderProgramOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    SysProgVO sysProg = new SysProgVO();
    sysProg.setOid(folderProgramOid);
    DefaultResult<SysProgVO> spResult = this.sysProgService.findObjectByOid(sysProg);
    if (spResult.getValue() == null) {
        throw new ServiceException(spResult.getSystemMessage().getValue());
    }
    sysProg = spResult.getValue();
    Map<String, List<SysProgVO>> dataMap = new HashMap<String, List<SysProgVO>>();
    SysMenuVO sysMenu = new SysMenuVO();
    List<SysProgVO> enableList = null;
    List<SysProgVO> allList = null;
    sysMenu.setProgId(sysProg.getProgId());
    sysMenu.setParentOid(ZeroKeyProvide.OID_KEY);
    DefaultResult<SysMenuVO> smResult = this.sysMenuService.findByUK(sysMenu);
    if (smResult.getValue() != null) {
        sysMenu = smResult.getValue();
        enableList = this.sysProgService.findForInTheFolderMenuItems(sysProg.getProgSystem(), sysMenu.getOid(), MenuItemType.ITEM);
    }
    allList = this.sysProgService.findForSystemItems(sysProg.getProgSystem());
    if (enableList == null) {
        enableList = new ArrayList<SysProgVO>();
    }
    if (allList == null) {
        allList = new ArrayList<SysProgVO>();
    }
    dataMap.put("enable", enableList);
    dataMap.put("all", allList);
    return dataMap;
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HashMap(java.util.HashMap) SysMenuVO(com.netsteadfast.greenstep.vo.SysMenuVO) SysProgVO(com.netsteadfast.greenstep.vo.SysProgVO) ArrayList(java.util.ArrayList) List(java.util.List) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)

Aggregations

SysMenuVO (com.netsteadfast.greenstep.vo.SysMenuVO)7 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)5 SysProgVO (com.netsteadfast.greenstep.vo.SysProgVO)3 HashMap (java.util.HashMap)3 List (java.util.List)3 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)2 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)2 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)2 TbSys (com.netsteadfast.greenstep.po.hbm.TbSys)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 TbSysProg (com.netsteadfast.greenstep.po.hbm.TbSysProg)1 Map (java.util.Map)1 Subject (org.apache.shiro.subject.Subject)1 Transactional (org.springframework.transaction.annotation.Transactional)1