This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
SXS20240115/SRC/iMES_PDA/config/common.js

1216 lines
58 KiB
JavaScript
Raw Normal View History

2024-01-24 16:47:50 +08:00
//common function
define(["app", "moment"], function (app, moment) {
app.run(["$state", "$rootScope", "$filter", "$mdDialog", "$mdlToast", "$timeout", "$location", "$anchorScroll", "$templateRequest", "$compile", "config", 'MMWService',
function ($state, $rootScope, $filter, $mdDialog, $mdlToast, $timeout, $location, $anchorScroll, $templateRequest, $compile, config, $MMWService) {
//2021-12-03 modify by YENRU
//Add Title Info.
$rootScope.title_hidden=false;
$rootScope.login_environment_info;
$rootScope.login_user_info;
$rootScope.loadFinish = false;
$rootScope.lang = config.setting.lang
config.APKVersion = "";
//20170802 modify by Dustdusk for 判斷目前版本
if (window.nodeRequire) {
$rootScope.platform = 'desktop';
} else if (typeof cordova !== 'undefined') {
$rootScope.platform = 'cordova';
//20220418 13871,取得cordova apk version
try {
cordova.getAppVersion.getVersionNumber(function (version) {
config.APKVersion = version;
});
} catch (e) { }
} else {
$rootScope.platform = 'web';
}
// 紀錄目前Loading的狀態
//disabled : true - 隱藏/false - 顯示
$rootScope.Loading = {
disabled: true,
count: 0,
msg: ''
}
//顯示Loading, 會記錄目前顯示幾次Loading
$rootScope.showLoading = function (msg) {
angular.element(document.getElementsByClassName('LoadingContener')[0]).removeClass('ng-hide');
$rootScope.Loading.msg = msg || 'Loading...';
$rootScope.Loading.disabled = false;
$rootScope.Loading.count++;
}
window.showLoading = function (msg) {
$timeout(function () {
$rootScope.showLoading(msg);
});
}
//隱藏Loading, 當Loading 全部被關閉的時候才會完全關閉
$rootScope.hideLoading = function (isForce) {
if (isForce) {
$rootScope.Loading.count = 0;
}
$rootScope.Loading.count--;
if ($rootScope.Loading.count <= 0) {
angular.element(document.getElementsByClassName('LoadingContener')[0]).addClass('ng-hide');
$rootScope.Loading.disabled = true;
$rootScope.Loading.count == 0;
}
}
window.hideLoading = function (isForce) {
$timeout(function () {
$rootScope.hideLoading(isForce);
});
}
//20210730 13871,組成Alert物件
$rootScope.CreateAlert = function () {
}
//顯示 Alert
$rootScope.showAlert = function (alertMsg, confirm) {
if (alertMsg.length != undefined) {
$mdDialog.alert(alertMsg, confirm);
} else if (Object.keys(alertMsg).length > 1) {
if (Object.keys(alertMsg).length == 3) {
$mdDialog.alert_top_right(alertMsg, confirm);
} else {
//20210730 13871,錯誤訊息,Action翻譯
if (alertMsg.code != undefined) {
var action = $filter('translate')('imes_action.' + alertMsg.code);
if (action == 'imes_action.' + alertMsg.code) action = "N/A";
alertMsg.action = action;
var codeInfo = $filter('translate')('imes_name.' + alertMsg.code);
if (codeInfo != 'imes_name.' + alertMsg.code) alertMsg.title = codeInfo;
}
$mdDialog.alert_full(alertMsg, confirm);
}
}
}
window.showAlert = function (alertMsg, confirm) {
$timeout(function () {
$rootScope.showAlert(alertMsg, confirm);
});
}
//20211125 13871,顯示 Message,msg允許傳入[%%]翻譯格式
$rootScope.showMessage = function (msg, code, confirm) {
var message = "";
if (code != undefined)
message = code + ":" + $filter('translate')('imes_name.' + code);
if (message.length > 0)
message += "</br>";
var index = msg.indexOf('[%');
while (index >= 0) {
var index2 = msg.indexOf('%]', index + 2);
if (index2 < 0) break;
var key = msg.substring(index + 2, index2);
var key_tran = $filter('translate')('imes_resources.' + key);
msg = msg.substring(0, index) + (key == key_tran ? key : key_tran) + msg.substring(index2 + 2, msg.length);
index = msg.indexOf('[%');
}
message += msg;
$mdDialog.alert(message, confirm);
}
//Yes Or No Dialog
$rootScope.ShowYesOrNo = function (options, callback, cancel) {
//沒有msg直接回傳
if (options.msg == null || options.msg == undefined) {
if (callback)
callback();
return;
}
$mdDialog.dialog('JSplugins/angular-material-lite/template/rule.tmp.html', function (dialog) {
//2020/09/22 雋辰,增加取消確認按鈕
dialog.isOKCancel = options.isOKCancel;
return {
title: options.title,
msg: options.msg,
confirm: function () {
dialog.hide();
if (callback)
callback();
},
back: function () {
dialog.hide();
if (cancel)
cancel();
}
};
});
}
//顯示 confirm
$rootScope.showConfirm = function (alertMsg, confirm, cancel) {
$mdDialog.confirm(alertMsg, confirm, cancel);
}
//顯示Select
/*
* options : {
* title : 標題
* label : list 中外顯值得變數名稱
* sub_label : list 中外顯值得其他資訊
* code : list 中內存值的變數名稱
* selectCode : 預設值對應code設定的變數
* list : 要呈現的list
* confirm : 按下list以後的處理會傳入dialog可以用dialog.hide()
* 關閉開窗
* }
*/
$rootScope.showSelect = function (options) {
if (options.list.length != 0) {
$mdDialog.dialog('JSplugins/angular-material-lite/template/radioList.tmp.html', function (dialog) {
return {
title: options.title || $filter('translate')('common.msg.plz_select'),
label: options.label,
sub_label: options.sub_label,
code: options.code,
order: options.order || options.label,
selectCode: options.selectCode,
back: function () {
this.hide();
},
itemList: options.list,
itemClick: function (item, event) {
//$translate.use(item.code);
//$scope.currentUse = item.code;
if (options.confirm)
options.confirm(item, this);
//this.hide();
},
itemCancel: function () {
dialog.hide();
if (options.cancel)
options.cancel(this);
},
isCancel: options.cancel != undefined,
background: {
click: function () {
dialog.hide();
if (typeof (feedback) == 'function')
feedback();
}
}
}
});
} else {
$rootScope.showAlert($filter('translate')('common.msg.no_data'));
}
}
$rootScope.showToast = function (msg) {
$mdlToast.show(msg);
};
//顯示模糊查詢開窗 QueryList
/*
* options : {
* title : 標題
* label : list 中外顯值得變數名稱
* code : list 中內存值的變數名稱
* selectCode : 預設值對應code設定的變數
* confirm : 按下list以後的處理會傳入dialog可以用dialog.hide()
* 關閉開窗
* }
*/
$rootScope.showQueryList = function (options) {
//20180331 增加初始化ConditionsmodeList沒設定的話則使用預設值
//預設查詢條件
var modeList = [
{ name: $filter('translate')('common.report.condition.equal'), code: '0' },
{ name: $filter('translate')('common.report.condition.nequal'), code: '1' },
{ name: $filter('translate')('common.report.condition.contain'), code: '2' },
{ name: $filter('translate')('common.report.condition.ncontain'), code: '3' },
{ name: $filter('translate')('common.report.condition.exceed-equal'), code: '4' },
{ name: $filter('translate')('common.report.condition.less-equal'), code: '5' },
{ name: $filter('translate')('common.report.condition.exceed'), code: '6' },
{ name: $filter('translate')('common.report.condition.less'), code: '7' }
];
function initConditions(conditions) {
if (conditions && conditions.length) {
conditions.forEach(function (condition) {
var temp_modeList = modeList;//用來判斷目前該使用哪些條件
if (condition.modeList == undefined) {
condition.modeList = modeList;//將預設條件放進查詢裡面
} else if (condition.modeList.length > 0) {
temp_modeList = condition.modeList;//因為查詢有設定條件所以將條件放進temp_modeList
}
if (temp_modeList.length > 0) {
var isMatch = false;
//當有設定query_mode時則需要從modeList找出對應的查詢條件名稱
//如果沒有對應的則抓第一筆
if (condition.query_mode && condition.query_mode != '') {
for (var i = 0; i < temp_modeList.length; i++) {
if (condition.query_mode == temp_modeList[i].code) {
condition.query_name = temp_modeList[i].name;
isMatch = true;
break;
}
}
if (!isMatch) {
//表示設定的query_mode並不在modeList內
//使用第一筆作為預設值
condition.query_name = modeList[0].name;
condition.query_mode = modeList[0].code;
}
}
}
});
return conditions;
}
}
function getConditions(conditions) {
var query_condition_info = [];
if (conditions && conditions.length > 0) {
conditions.forEach(function (condition) {
if (condition.column_name != '' && condition.query_mode != '' && condition.value && condition.value != '') {
var query_conditoin = angular.extend({}, condition);
query_conditoin.modeList = undefined;
if (!query_conditoin.merge_condition_model)
query_conditoin.merge_condition_model = 'AND';
if (condition.data_type == 'D') {
query_conditoin.value = moment(condition.value).format('YYYY-MM-DD');
} else if (condition.query_mode == '2') {
query_conditoin.value = '%' + condition.value + '%';
} else {
query_conditoin.value = condition.value;
}
query_condition_info.push(query_conditoin);
}
});
}
return query_condition_info;
}
function calcPage(queryResults, pageInfo) {
pageInfo.totalPage = Math.floor(queryResults.length / pageInfo.perPageRow);
if (queryResults.length % pageInfo.perPageRow > 0) {
pageInfo.totalPage++;
}
return queryResults.slice((pageInfo.nowPage - 1) * pageInfo.perPageRow, (pageInfo.nowPage) * pageInfo.perPageRow);
}
function getQueryOrder(key, header) {
if (key) {
for (var i = 0; i < header.length; i++) {
if (header[i].code == key) {
return i;
}
}
return -1;
} else {
return 0;
}
}
function QueryListCompile(template, options) {
var header = template.find('#query_list_header');
var list = template.find('#query_list');
if (options.header && options.header.length > 0) {
for (var i = 0; i < options.header.length; i++) {
var headerColumn = '<div class="kmi-list__column head-controls" style="flex:1;" ng-style="{\'max-width\' : \'' + options.header[i].width + '\'}">';
headerColumn += '<div class="filter" ng-show="dialog.header[' + i + '].isFilter">';
headerColumn += '<input ng-model="dialog.filterColumns[\'' + options.header[i].code + '\']"/>';
headerColumn += '<i class="material-icons clear" style="position: absolute;top: 2px;right: 4px;" ng-click="dialog.header[' + i + '].isFilter = false;dialog.filterColumns[\'' + options.header[i].code + '\'] = \'\';">clear</i>';
headerColumn += '</div>';
headerColumn += '<div class="order" ng-hide="dialog.header[' + i + '].isFilter">';
headerColumn += '<i class="material-icons search" style="z-index:1;" ng-click="dialog.header[' + i + '].isFilter = true">search</i>';
headerColumn += '<label ng-bind="\'' + options.header[i].label + '\' | translate"></label>';
headerColumn += '<i class="material-icons" ng-show="dialog.qeryOrder == ' + i + '">{{!dialog.header[' + i + '].order?\'&#xE5D8;\':\'&#xE5DB;\'}}</i>';
headerColumn += '<div class="kmi-can-click" ng-click="dialog.orderResult(' + i + ', dialog.header[' + i + ']);"></div>';
headerColumn += '</div>';
headerColumn += '</div>';
header.append(headerColumn);
var listColumn = '<div class="kmi-list__column" style="flex:1;z-index:0;"';
listColumn += 'ng-class="{\' column-border\':!$last}" ng-style="{\'max-width\' : \'' + options.header[i].width + '\'}" ng-bind="item[\'' + options.header[i].code + '\']" >';
listColumn += '</div>';
list.append(listColumn);
}
list.append('<div class="kmi-can-click" ng-click="dialog.itemDbClick(item, $event);"></div>');
}
return template;
}
function openDialog(options, pageInfo, queryResults) {
var selectItem;
options.condition = initConditions(options.condition);
if (options.mode == 'M') {
if (options.selectItem && options.selectItem.length > 0) {
selectItem = {};
options.selectItem.forEach(function (item) {
selectItem[item[options.key || options.header[0].code]] = item;
});
}
}
$mdDialog.dialog('JSplugins/angular-material-lite/template/queryList.tmp.html', function (dialog) {
return {
mode: options.mode || 'S', //m (多選) / s (單選)
key: options.key || options.header[0].code,
queryTitle: options.title || $filter('translate')('common.msg.plz_select'),
qeryOrder: getQueryOrder(options.order || options.key, options.header),
orderColumn: function () {
if (dialog.qeryOrder == -1) {
return options.order;
} else {
return dialog.header[dialog.qeryOrder].code;
}
},
orderColumnSeq: function () {
if (dialog.qeryOrder == -1) {
return options.orderSeq;
} else {
return dialog.header[dialog.qeryOrder].order;
}
},
IsSelect: function (item) {
if (dialog.mode == 'S') {
return item[dialog.key] == dialog.selectCode;
} else if (dialog.mode == 'M') {
if (options.selectKey != undefined) {
item.$is_select = item[options.selectKey.key] == options.selectKey.true;
}
return false;
}
return false;
},
selectCode: options.selectCode,
seletItem: selectItem,
condition: options.condition,
filterColumns: options.filterColumns || {},//20180202 新增模糊查詢
beforeShown: options.beforeShown,
beforeCompile: function (template) {
return QueryListCompile(template, options);
},
loadCodeList: function (item) {
if (!item.require) {
$rootScope.showSelect({
title: $filter('translate')('common.report.condition_fields'),
label: 'name',
code: 'column_name',
selectCode: item.column_name,
list: options.condition,
confirm: function (selectItem, CodeDialog) {
item.modeList = [];
item.query_name = undefined;
item.query_mode = undefined;
item.data_type = undefined;
item.value = undefined;
item = angular.extend(item, selectItem);
CodeDialog.hide();
}
});
}
},
loadTypeList: function (item) {
if (!item.require) {
if (item.modeList && item.modeList.length > 0) {
$rootScope.showSelect({
title: $filter('translate')('common.condition_title'),
label: 'name',
code: 'code',
order: 'code',
selectCode: item.code,
list: item.modeList,
confirm: function (selectItem, TypeDialog) {
item.query_name = selectItem.name;
item.query_mode = selectItem.code;
TypeDialog.hide();
}
});
}
}
},
header: options.header,
orderResult: function (index, head) {
if (dialog.qeryOrder != index) {
head.order = false;
} else {
head.order = !head.order;
}
dialog.qeryOrder = index;
},
pageInfo: pageInfo,
getPageRange: function () {
return new Array(dialog.pageInfo.totalPage);
},
gotoPage: function (pageNum) {
dialog.pageInfo.nowPage = pageNum;
},
getQueryResults: function () {
var _queryResults = queryResults.filter(function (item, index, array) {
var isOK = true,
keys = Object.keys(dialog.filterColumns);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (isOK && item[key] && dialog.filterColumns[key] && dialog.filterColumns[key] != '') {
if ((item[key] + '').indexOf(dialog.filterColumns[key]) == -1) {
isOK = false;
break;
}
}
}
return isOK;
});
if (dialog.pageInfo != undefined) {
return calcPage(_queryResults, dialog.pageInfo);
} else {
return _queryResults;
}
},
confirm: function () {
//var selectItem = [];
if (dialog.mode == 'S') {
if (!dialog.seletItem) {
//完全未選擇的情況
if (queryResults && queryResults.length > 0) {
if (dialog.selectCode && dialog.selectCode != '') {
var tObject = {};
tObject[dialog.key] = dialog.selectCode;
var temp = $filter('filter')(queryResults, tObject);
if (temp && temp.length > 0) {
dialog.seletItem = temp[0];
}
}
}
}
} else if (dialog.mode == 'M') {
if (options.selectKey != undefined) {
dialog.seletItem = queryResults;
} else if (dialog.seletItem != undefined) {
var selectItem = [];
for (var key in dialog.seletItem) {
if (dialog.seletItem[key] != undefined)
selectItem.push(dialog.seletItem[key]);
}
dialog.seletItem = selectItem;
}
}
if (dialog.seletItem) {
if (options.confirm)
options.confirm(dialog.seletItem, dialog);
} else {
$rootScope.showAlert($filter('translate')('common.msg.plz_select_one'));
}
},
back: function () {
if (options.back) {
options.back(dialog.hide);
} else {
dialog.hide();
}
},
itemClick: function (item) {
if (dialog.mode == 'S') {
dialog.selectCode = item[dialog.key];
dialog.seletItem = item;
} else {
//dialog.selectCode = item[dialog.key];
if (options.selectKey != undefined) {
item.$is_select = item[options.selectKey.key] == options.selectKey.true;
if (item.$is_select) {
item[options.selectKey.key] = options.selectKey.false;
item.$is_select = false;
} else {
item[options.selectKey.key] = options.selectKey.true;
item.$is_select = true;
}
} else if (dialog.seletItem) {
//dialog.seletItem = {};
if (dialog.seletItem[item[dialog.key]]) {
dialog.seletItem[item[dialog.key]] = undefined;
} else {
dialog.seletItem[item[dialog.key]] = item;
}
}
}
},
itemDbClick: function (item, event) {
if (dialog.mode == 'S') {
dialog.selectCode = item[dialog.key];
dialog.seletItem = item;
dialog.confirm();
} else {
dialog.itemClick(item, event);
}
},
search: function () {
var query_condition_info = getConditions(options.condition);
options.query(query_condition_info, function (_queryResults) {
if (!_queryResults || _queryResults.length == 0) {
$rootScope.showToast($filter('translate')('common.msg.no_data'), 'error');
}
if (dialog.pageInfo != undefined) {
dialog.pageInfo.nowPage = 1;
}
queryResults = _queryResults;
});
},
cancel: options.cancel
};
});
}
(function (options) {
if (options.header && options.header.length > 0) {
if (options.query) {
var pageInfo;
if (options.pageRecord != undefined) {
pageInfo = {
nowPage: 1,
perPageRow: options.pageRecord,
totalPage: 0
};
}
if (options.notQuery && options.condition) {
//當有設定查詢條件以及 notQuery 的時候,開啟不會伴隨查詢
openDialog(options, pageInfo, []);
} else {
var query_condition_info = getConditions(options.condition);
options.query(query_condition_info, function (queryResults) {
if (queryResults && queryResults.length > 0) {
openDialog(options, pageInfo, queryResults);
} else if (options.noDataException) {
options.noDataException(options, function () {
openDialog(options, pageInfo, queryResults);
});
} else {
$rootScope.showAlert($filter('translate')('common.msg.no_data'));
//20181024 modify by Dustdusk for M#: 當有設定查詢條件時,查無資料還是會開啟視窗
if (options.condition && options.condition.length > 0)
openDialog(options, pageInfo, queryResults);
}
});
}
} else {
console.error('showQueryList : plz set options.query');
}
} else {
console.error('showQueryList : plz set options.header');
}
})(options);
};
// Change Program
$rootScope.changeProgram = function (program, parameters, isLeave) {
if(program=='mms03_system_home' || program=='mms01_user_login' || program =='mms02_system_setting'){
$rootScope.hideSideTitle();
}
else{
$rootScope.showSideTitle();
}
$rootScope.reciprocalRestart();
if (typeof (parameters) == 'boolean') {
isLeave = parameters;
} else {
isLeave = isLeave || false;
}
if (!isLeave) {
//從任何地點 > 載入一般程式
$rootScope.programState = 'load-program';
} else {
//從其他程式> 載入home
$rootScope.programState = 'leave-program';
}
//20210601 13871,檢查頁面是否存在避免錯誤
if (!config.program.some(item => item.name == program)) {
$rootScope.showAlert(program + $filter('translate')('error.pageNotFound'));
return;
}
if (parameters != undefined) {
$state.go(program, parameters);
} else {
$state.go(program);
}
}
$rootScope.showSideTitle = function () {
angular.element(document.getElementById('side-title')).removeClass('title-hide');
$rootScope.title_hidden = true;
};
$rootScope.hideSideTitle = function () {
angular.element(document.getElementById('side-title')).addClass('title-hide');
$rootScope.title_hidden = false;
};
/***
* 顯示 local Notification, 由App本身所觸發的通知
* 此部分有加入使用html5 實作 web browser 通知
* data {
* id : id表示此訊息的身分,當有兩個相同的id時,後者會覆蓋前者
* msg : 通知的訊息
* sound : 通知的聲音, 預設是file://sound/sound.mp3
* target : 點擊通知訊息後會開啟的頁面
* }
*/
$rootScope.ShowNotification = function (data, prepareData, clickHandler) {
try {
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
cordova.plugins.notification.local.schedule(prepareData(data));
cordova.plugins.notification.local.on("click", clickHandler(data), this);
} else {
//產生HTML5的通知
Notification.requestPermission(function (permission) {
var feedbackData = prepareData(data);
var notification = new Notification(feedbackData.title, {
body: feedbackData.text,
dir: 'auto'
});
notification.click = function () {
window.location = "/";
}
});
}
} catch (error) {
console.log(error);
}
}
// Open Background Service
$rootScope.OpenBackgroundService = function (data) {
try {
// Android customization
cordova.plugins.backgroundMode.setDefaults(data);
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function () {
}
} catch (error) {
console.log(error);
}
}
// Screen always on
$rootScope.DisplayOn = function (ScreenOn) {
if (window.plugins) {
if (ScreenOn)
window.plugins.insomnia.keepAwake();
else
window.plugins.insomnia.allowSleepAgain();
}
}
// open Server Send Event Connection
$rootScope.openSSECenection = function (config, prepareData, clickHandler) {
if (typeof (EventSource) !== "undefined") {
var server = config.server;
var source = new EventSource('http://' + server.ip + ':' + server.port + '/' + server.name + '/' + 'startSSE');
source.addEventListener('open', function (e) {
//console.log("Open Connection");
}, false);
//Set CallbackFunction
source.addEventListener('message', function (msg) {
//console.log("SSE get message ");
//console.log(msg.data);
var data = JSON.parse(msg.data);
if (data.command == 'refresh') {
if ($rootScope.refresh != undefined) {
$rootScope.refresh(data);
}
if (data.equipment && config.setting.machineNot) {
$rootScope.ShowNotification(data, prepareData, clickHandler);
}
}
});
source.addEventListener('error', function (e) {
console.log(e);
try {
if (cordova.plugins.backgroundMode.isEnabled()) {
cordova.plugins.backgroundMode.configure({
text: $filter('translate')('error.connectRefused')
});
}
} catch (error) {
console.log(error);
}
source.close();
console.log('prepare alert');
$MDLUtirlity.alert($filter('translate')('error.connectRefused'), function () {
$rootScope.openSSECenection();
$MDLUtirlity.alertClose();
});
}, false);
} else {
console.log('Your browser don\'t support SSE.');
}
}
//20201113 雋辰,深拷貝
$rootScope.deepCopy = function (obj, cache) {
if (cache == undefined)
cache = new WeakMap();
// 基本型別 & function
if (obj === null || typeof obj !== 'object') return obj
// Date 及 RegExp
if (obj instanceof Date || obj instanceof RegExp) return obj.constructor(obj)
// 檢查快取
if (cache.has(obj)) return cache.get(obj) // 使用原物件的 constructor
const copy = new obj.constructor() // 先放入 cache 中
cache.set(obj, copy)
// 取出所有一般屬性 & 所有 key 為 symbol 的屬性
;
[...Object.getOwnPropertyNames(obj), ...Object.getOwnPropertySymbols(obj)].forEach(key => {
copy[key] = $rootScope.deepCopy(obj[key], cache)
});
return copy;
}
//20210911 13871,檢查提示視窗是否已經開啟
$rootScope.CheckAlertDialog = function () {
var doc = document.getElementById("alertpage");
if (doc != undefined)
return true;
doc = document.getElementById("alertpage_full");
if (doc != undefined)
return true;
return false;
}
/**
* open Camera for barcode/QRcode scan
* options {
* descript,
* after,
* exception,
* formats,
* orientation // Android only (portrait|landscape), default unset so it rotates with the device
* }
*/
$rootScope.OpenScanner = function (options) {
//options.formats = options.formats||"QR_CODE";
options.orientation = options.orientation || "unset";
options.descript = options.descript || "";
setTimeout(function () {
$rootScope.showLoading();
$rootScope.$apply();
setTimeout(function () {
try {
/***
* result.text
* Format: " + result.format
* result.cancelled
*/
cordova.plugins.barcodeScanner.scan(
function (result) {
$rootScope.hideLoading(true);
$rootScope.$apply();
if (options.after)
options.after(result);
},
function (error) {
$rootScope.hideLoading(true);
$rootScope.$apply();
},
{
"preferFrontCamera": false, // iOS and Android //使用前鏡頭
"showFlipCameraButton": false, // iOS and Android //切換前後鏡頭
"prompt": options.descript, // 掃描的文字
"formats": options.formats, // 要掃描的格式
"orientation": options.orientation // Android only (portrait|landscape), default unset so it rotates with the device
}
);
} catch (e) {
$rootScope.hideLoading(true);
$rootScope.$apply();
if (options.exception)
options.exception();
}
}, 400);
}, 200);
}
//auto logout
var LogoutTimer = (function () {
var reciprocalTime = 0;
var timer;
function LogoutTimer(rt) {
if (rt)
reciprocalTime = rt;
}
LogoutTimer.prototype.start = function (rt) {
if (!timer) {
if (rt)
reciprocalTime = rt;
reciprocal();
}
}
LogoutTimer.prototype.stop = function () {
clearTimeout(timer);
timer = undefined;
}
LogoutTimer.prototype.refresh = function (rt) {
LogoutTimer.prototype.stop();
LogoutTimer.prototype.start(rt);
}
function reciprocal() {
if (reciprocalTime != 0) {
timer = setTimeout(function () {
//$rootScope.hideMenu();
//$rootScope.changeProgram('login',true);
$MMWService.sendToMESSrv_plain({
uri: 'wsUSR.ClearLoginInfo_plainjson',
content: {
userno: config.cache.account,
computername: config.client.ip,
sessionid: config.mdssessionno
},
success: function (data) {
$rootScope.hideMenu();
$timeout(function () {
$rootScope.changeProgram("mms01_user_login", true);
}, 200);
}
});
}, reciprocalTime * 60 * 1000);
} else {
console.warn('config.setting.timeout is 0, auto logout wound\'t start');
}
}
return LogoutTimer;
})();
var logoutTimerIns;
$rootScope.reciprocalStart = function () {
logoutTimerIns = new LogoutTimer(config.setting.timeout);
logoutTimerIns.start();
}
$rootScope.reciprocalRestart = function () {
if (logoutTimerIns)
logoutTimerIns.refresh();
}
/*
//fix keyboard cover input problem - only work with 'Material Design Lite' framework and cordova-keyboard-plugin
window.addEventListener('native.keyboardshow', function(info) {
var element = document.activeElement;
if(element!=undefined && element.tagName == 'INPUT'){
$timeout(function(){
if($location.hash() == element.id){
// set the $location.hash to `newHash` and
// $anchorScroll will automatically scroll to it
$anchorScroll();
} else{
// call $anchorScroll() explicitly,
// since $location.hash hasn't changed
$location.hash(element.id);
}
});
}
});
*/
/*
if($ && $.jqplot && $.jqplot.postDrawHooks){
$.jqplot.preDrawHooks.push(function(){
$rootScope.showLoading();
});
$.jqplot.postDrawHooks.push(function(){
$rootScope.hideLoading();
});
}
*/
$rootScope.isElectron = false;
try {
$rootScope.isElectron = nodeRequire ? true : false;
} catch (e) { }
//20210703 13871,判斷undefined null 空值
$rootScope.IsNullOrEmpty = function (str) {
if (str == undefined || str === "")
return true;
return false;
}
/*
*20220510 13871,取得ValueList,並將翻譯後的值放入指定欄位
*tblName:ValueList資料表名稱
*colName:ValueList資料表欄位名稱
*list:資料集合
*sourceCol:資料集合的欄位名稱,會將此欄位的值用作語系翻譯
*replaceCol:資料集合的欄位名稱,會將翻譯後的值放入此欄位
*callback:執行完後端取得ValueList資訊,並翻譯值後呼叫
*/
$rootScope.GetValueList = function (tblName, colName, list, sourceCol, replaceCol, callback) {
var uri = [];
var content = [];
uri.push("kcSYS.clsValueList.LoadValueList");
content.push({
pTableName: tblName,
pColumnName: colName
});
$MMWService.sendToMESSrv_Multi({
uri: uri,
content: content,
success: function (data) {
var tmpJson = JSON.parse(data.ResultJson);
var tmp;
var index = 0;
tmp = JSON.parse(tmpJson[uri[index]]);
tmp = tmp[Object.keys(tmp)[0]];
if (list) {
list.forEach(item=> {
var drSel;
drSel = tmp.filter(valList => {
return valList.COLUMNVALUE == item[sourceCol];
});
if (drSel.length > 0)
item[replaceCol] = $filter('translate')('imes_resources.' + drSel[0].DISPLAYTEXT);
else
item[replaceCol] = item[sourceCol];
});
}
if (callback) {
callback();
}
}
});
}
$rootScope.focusById = function (id) {
$timeout(function () {
var target = document.getElementById(id);
if (target) {
target.focus();
target.select();
}
});
}
$rootScope.logout = function (callback) {
$rootScope.showConfirm(
$filter('translate')('common.msg.is_logout'),
function (dialog) {
dialog.hide();
$MMWService.sendToMESSrv_plain({
uri: 'wsUSR.ClearLoginInfo_plainjson',
content: {
userno: config.cache.account,
computername: config.client.ip,
sessionid: config.mdssessionno
},
success: function (data) {
//20220425 13871,登出,清除使用的session
config.mdssessionno = '';
if (callback) callback();
if ($rootScope.brLogOut) {
$rootScope.brLogOut();
$rootScope.brLogOut = undefined;
}
$rootScope.hideMenu();
$timeout(function () {
$rootScope.changeProgram("mms01_user_login", true);
}, 200);
}
});
}, function (dialog) {
dialog.hide();
});
}
//20170809 modify by Dustdusk for 開啟虛擬鍵盤
if ($rootScope.platform != 'web' && $rootScope.platform != 'cordova') {
$(document).on('click', 'input', function (event) {
if (config.setting.virtualKeyboard == 'Y') {
if (!$(event.currentTarget).is('[readonly]') && !$(event.currentTarget).is('[disabled]')) {
const exec = window.nodeRequire('child_process').exec;
exec('start /d "C:\\Program Files\\Common Files\\microsoft shared\\ink" TabTip.exe', function (error, stdout, stderr) {
if (error) {
console.error(error);
return;
}
});
}
}
});
}
}]).controller('gallery', ["$scope", "$gallery", function ($scope, $gallery) {
$scope.gallery = $gallery;
}]).provider('$gallery', function () {
this.$get = ["$rootScope", "$controller", function ($rootScope, $controller) {
return {
url: '',
title: '',
isHide: true,
hide: function () {
this.isHide = true;
if (this.feedback) {
this.feedback();
}
},
show: function (title, url, feedback) {
this.title = title;
this.url = url;
this.feedback = feedback;
this.isHide = false;
try {
StatusBar.backgroundColorByHexString("#000000");
} catch (e) { }
},
feedback: null
};
}];
})
.directive('kmiReportPanel', ["$rootScope", "$filter", function ($rootScope, $filter) {
return {
restrict: "C",
replace: true,
templateUrl: "program/C00/C00.html",
link: function (scope, elem, attrs, ctrl) {
scope.queryMode = 'query';
scope.addCondition = function () {
scope.conditionList.push({ column_name: '', query_mode: '', value: '' });
};
scope.removeCondition = function (index, item) {
scope.conditionList.splice(index, 1);
}
//設定查詢畫面的"欄位"有哪些
scope.loadCodeList = function (item, $index) {
if (!item.require) {
$rootScope.showSelect({
title: $filter('translate')('common.report.condition_fields'),
label: 'name',
code: 'column_name',
selectCode: item.column_name,
list: scope.codeList,
confirm: function (selectItem, dialog) {
item.modeList = [];
item.query_name = undefined;
item.query_mode = undefined;
item.data_type = undefined;
item.value = undefined;
item = angular.extend(item, selectItem);
dialog.hide();
}
});
}
};
//根據欄位的modeList決定他條件有哪些
scope.loadTypeList = function (item, $index) {
if (!item.require) {
if (item.modeList) {
$rootScope.showSelect({
title: $filter('translate')('common.condition_title'),
label: 'name',
code: 'code',
selectCode: item.code,
list: item.modeList,
confirm: function (selectItem, dialog) {
item.query_name = selectItem.name;
item.query_mode = selectItem.code;
dialog.hide();
}
});
}
}
};
scope.changeDate = function (item, date) {
item.value_s = moment(new Date()).subtract(date, 'days').toDate();
item.value_e = new Date();
item.date_type = date;
}
$rootScope.genConditioninfo = function () {
var query_condition_info = [];
scope.conditionList.forEach(function (condition) {
if (condition.data_type == 'D-SE') {
query_condition_info.push({
column_name: condition.column_name_s,
query_mode: 4,
merge_condition_model: 'AND',
value: moment(condition.value_s).format('YYYY-MM-DD')
});
query_condition_info.push({
column_name: condition.column_name_e,
query_mode: 5,
merge_condition_model: 'AND',
value: moment(condition.value_e).format('YYYY-MM-DD')
});
} else if (condition.column_name != '' && condition.query_mode != '' && condition.value && condition.value != '') {
var query_conditoin = {};
query_conditoin.column_name = condition.column_name;
query_conditoin.query_mode = condition.query_mode;
query_conditoin.merge_condition_model = 'AND';
if (condition.data_type == 'D') {
query_conditoin.value = moment(condition.value).format('YYYY-MM-DD');
} else {
query_conditoin.value = condition.value;
}
query_condition_info.push(query_conditoin);
}
});
return query_condition_info;
};
}
}
}]);
});