/*! * Angular Material Design KMI * v3.0.0 * author Dustdusk */ var moment, d3, sortablejs; try { moment = require('moment'); d3 = require('d3'); sortablejs = require('sortablejs'); } catch (e) { moment = moment; } (function (window, angular, moment, d3, sortablejs) { 'use strict'; var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/); (function () { 'use strict'; angular.module('ngMaterialLite', ['ng', 'pascalprecht.translate', 'material.components.dialog', 'material.components.datePicker', 'material.components.calculater', 'material.components.dashboard', 'material.components.barcode', 'material.components.list', 'material.components.toast', 'material.components.Marquee']) .directive('kmiCanClick', function () { return { restrict: 'C', link: function (scope, elem) { var startEvent, endEvent; if (isMobile) { startEvent = 'touchstart'; endEvent = 'touchend'; } else { startEvent = 'mousedown'; endEvent = 'mouseup mouseleave'; } $(elem[0]).on(startEvent, function () { if (angular.element(elem[0]).parent().attr('disabled') != 'disabled') angular.element(elem[0]).addClass('is-active'); }); $(elem[0]).on(endEvent, function () { if (angular.element(elem[0]).parent().attr('disabled') != 'disabled') angular.element(elem[0]).removeClass('is-active'); }); } }; }); })(); (function () { 'use strict'; var dialogContent, dialogInstances = {}; //backupDialog = [], //backupContent = [], //nowScope, //nowContent; angular .module('material.components.dialog', []) .provider('$mdDialog', function () { function appendDialog(template, options) { options.templateRequest(template).then(function (respose) { nowContent = options.compile('
' + respose + '
')(dialogScope); angular.element(dialogContent).append(nowContent); dialog.show(function () { options.timeout(function () { angular.element(nowContent).removeClass('lay-hide'); //20170620 modify by Dustdusk for 新增開窗後事件beforeShown if (dialog.beforeShown) { dialog.beforeShown(); } }, 10); }); }); } function initDialogScope(instance, $css) { instance.scope.dialog = {}; //20190807 add by Dustdusk for M#: 取得開窗GUID instance.scope.dialog.getGUID = function () { return instance.guid; }; //20190807 add by Dustdusk for M#: 取得Dialog的Scope instance.scope.dialog.getDialogScope = function () { return instance.scope; }; instance.scope.dialog.hide = function (callback) { //沒有舊版的就全部關閉 //instance.scope.dialog.isShow = false; angular.element(instance.content).remove();; if (instance.scope.dialog.css_url) $css.remove(instance.scope.dialog.css_url); instance.scope.$destroy(); delete dialogInstances[instance.guid]; if (Object.keys(dialogInstances).length == 0) { angular.element(dialogContent).html(''); angular.element(dialogContent).addClass('ng-hide'); } if (typeof callback === 'function') { callback(); } }; instance.scope.dialog.show = function (feedback) { //20180201 modify by Dustdusk for 附加CSS上去 if (instance.scope.dialog.css_url) { $css.add(instance.scope.dialog.css_url); } angular.element(dialogContent).removeClass('ng-hide'); dialogInstances[instance.guid] = instance; if (typeof (feedback) == 'function') feedback(instance); }; return instance; } function CreateDialog(providers, options) { providers.templateRequest(options.templateURL).then(function (respose) { var _dialog_instance = { guid: Date.now(), scope: providers.rootScope.$new(true) } try { _dialog_instance = initDialogScope(_dialog_instance, providers.css); _dialog_instance.scope.dialog = angular.extend(_dialog_instance.scope.dialog, options.controller(_dialog_instance.scope.dialog)); //20180801 modify by Dustdusk for 增加組裝html; if (_dialog_instance.scope.dialog.beforeCompile) { respose = _dialog_instance.scope.dialog.beforeCompile($(respose)).prop('outerHTML'); } _dialog_instance.content = providers.compile('
' + respose + '
')(_dialog_instance.scope); angular.element(dialogContent).append(_dialog_instance.content); } catch (e) { console.error(e); _dialog_instance.scope.$destroy(); delete _dialog_instance.scope; } if (_dialog_instance.scope) { _dialog_instance.scope.dialog.show(function () { providers.timeout(function () { angular.element(_dialog_instance.content).removeClass('lay-hide'); //20170620 modify by Dustdusk for 新增開窗後事件beforeShown if (_dialog_instance.scope.dialog.beforeShown) { _dialog_instance.scope.dialog.beforeShown(); } }, 10); }); } }); } function closeDialog(callback) { for (var guid in Object.keys(dialogInstances)) { dialogInstances[guid].scope.dialog.hide(); } if (typeof callback === 'function') { callback(); } } this.$get = ['$compile', '$templateRequest', '$controller', '$rootScope', '$timeout', '$css', function ($compile, $templateRequest, $controller, $rootScope, $timeout, $css) { return { alert: function (msg, level, feedback) { if (typeof (level) == 'function') { feedback = level; level = ''; } CreateDialog({ templateRequest: $templateRequest, compile: $compile, timeout: $timeout, css: $css, rootScope: $rootScope }, { templateURL: 'JSplugins/angular-material-lite/template/alert.tmp.html', controller: function (dialog) { return { content: msg, level: level, confirm: function () { dialog.hide(); if (typeof (feedback) == 'function') feedback(); }, background: { click: function () { dialog.hide(); if (typeof (feedback) == 'function') feedback(); } }, } } }); }, alert_full: function (content, level, feedback) { if (typeof (level) == 'function') { feedback = level; level = ''; } CreateDialog({ templateRequest: $templateRequest, compile: $compile, timeout: $timeout, css: $css, rootScope: $rootScope }, { templateURL: 'JSplugins/angular-material-lite/template/alert_full.tmp.html', controller: function (dialog) { dialog.show_detail = false; return { title: content.title, code: content.code, message: content.message, exception: content.exception, stack: (content.stack.replace(/\r\n/, '
')), action:content.action, //20210730 13871,add action,"處理方式"訊息 level: level, background: { click: function () { dialog.hide(); if (typeof (feedback) == 'function') feedback(); } }, tog: function () { dialog.show_detail = !dialog.show_detail; }, confirm: function () { dialog.hide(); if (typeof (feedback) == 'function') feedback(); } } } }); }, alert_top_right: function (content, level, feedback) { if (typeof (level) == 'function') { feedback = level; level = ''; } CreateDialog({ templateRequest: $templateRequest, compile: $compile, timeout: $timeout, css: $css, rootScope: $rootScope }, { templateURL: 'JSplugins/angular-material-lite/template/alert_top_right.tmp.html', controller: function (dialog) { dialog.show_detail = false; return { title: content.title, item: content.item, message: content.message, level: level, background: { click: function () { dialog.hide(); if (typeof (feedback) == 'function') feedback(); } }, confirm: function () { dialog.hide(); if (typeof (feedback) == 'function') feedback(); } } } }); }, confirm: function (msg, confirm, cancel) { CreateDialog({ templateRequest: $templateRequest, compile: $compile, timeout: $timeout, css: $css, rootScope: $rootScope }, { templateURL: 'JSplugins/angular-material-lite/template/confirm.tmp.html', controller: function (dialog) { return { background: { class: ['confirm-background'] }, content: msg, confirm: confirm, cancel: cancel || function () { dialog.hide(); } } } }); }, dialog: function (templateURL, controller) { CreateDialog({ templateRequest: $templateRequest, compile: $compile, css: $css, timeout: $timeout, rootScope: $rootScope }, { templateURL: templateURL, controller: controller }); }, //20190807 add by Dustdusk for M#: 透過名稱取得Service進行開窗 serviceDialog: function () { if (arguments.length > 0) { var _params = Array.prototype.slice.call(arguments); var _service_name = _params.splice(0, 1)[0]; $rootScope.getService(_service_name, function (_service_instance) { _service_instance.init.apply(null, _params); }); } }, //20190807 add by Dustdusk for M#: 透過GUID取得目前已開窗的實體 getDialogByGUID: function (guid) { if (dialogInstances[guid]) return dialogInstances[guid].scope.dialog; }, dialogObject: { isShow: false, content: '', templateURL: '', hide: function () { //判斷有沒有舊版的dialog if (!backupDialog[backupDialog.length - 1]) { //沒有舊版的就全部關閉 dialog.isShow = false; angular.element(dialogContent).html(''); backupDialog = []; backupContent = []; angular.extend(clearDialog(dialog), dialogObject); //$timeout(function(){ angular.element(dialogContent).addClass('ng-hide'); //}, 300); } else { //有舊版的就把舊版的拉出來, 把新版的移除 angular.element(nowContent).remove(); angular.extend(clearDialog(dialog), backupDialog[backupDialog.length - 1]); nowContent = backupContent[backupContent.length - 1]; backupDialog.splice(backupDialog.length - 1, 1); backupContent.splice(backupContent.length - 1, 1); //console.log(dialog); } }, show: function (feedback) { //dialog.content = msg; dialog.isShow = true; angular.element(dialogContent).removeClass('ng-hide'); if (feedback) feedback(); }, confirm: null, cancel: function () { dialog.hide(); }, controller: null }, isShow: function () { if (Object.keys(dialogInstances).length > 0) return true; else return false; }, closeAll: function (callback) { closeDialog(callback); } }; }]; }) .config(function () { angular.element(document.getElementsByTagName('body')).append('
'); dialogContent = document.getElementsByClassName('dialog-background')[0]; }) ; })(); (function () { 'use strict'; angular .module('material.components.datePicker', ['material.components.dialog']) .provider('$datePicker', ['$translateProvider', function ($translateProvider) { var DatePicker = (function () { moment.locale('zh_TW', { months: '1 月_2 月_3 月_4 月_5 月_6 月_7 月_8 月_9 月_10 月_11 月_12 月'.split('_'), monthsShort: '1 月_2 月_3 月_4 月_5 月_6 月_7 月_8 月_9 月_10 月_11 月_12 月'.split('_'), weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'), weekdaysShort: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'), weekdaysMin: '日_一_二_三_四_五_六'.split('_'), }); var pickDate; //選擇的日子 var today; //紀錄今天 var date; //目前頁面選擇的日子 var startDate; var endDate; var weekdays; var dayArray; var hourArray; var minArray; //var monthArray; var datepickerURL; var isYearList = false; if (!last_hour) { var last_hour = { value: "00", }; } if (!last_min) { var last_min = { value: "00", }; } var hour_minute; // constructors function DatePicker(pickDate, limitDate) { moment.locale($translateProvider.use()); // users this.today = new Date(); this.weekdays = moment.weekdaysMin(); this.dayArray = []; this.hourArray = []; this.minArray = []; for (let i = 1; i <= 24; i++) { if (i < 10) { i = '0' + String(i); } else { i = String(i); } if (last_hour.value === String(i)) { this.hourArray.push(last_hour); } else { this.hourArray.push({ value: i, is_selected: false }); } } for (let i = 1; i <= 60; i++) { if (i < 10) { i = '0' + String(i); } if (last_min.value === String(i)) { this.minArray.push(last_min); } else { this.minArray.push({ value: i, is_selected: false }); } } this.datepickerURL = 'JSplugins/angularMDL/template/mdl-datepicker.html'; this.pickDate = pickDate; this.date = moment(pickDate).clone().toDate(); //this.date Mon Apr 20 2020 10:02:27 GMT+0800 (台北標準時間) if (limitDate) { this.startDate = limitDate.start; this.endDate = limitDate.end; } this.monthDays(); } //prev month DatePicker.prototype.prevMonth = function () { this.date = moment(this.date).add(-1, 'M').toDate(); this.monthDays(); }; //next month DatePicker.prototype.nextMonth = function () { this.date = moment(this.date).add(1, 'M').toDate(); this.monthDays(); }; DatePicker.prototype.showHourAndMin = function () { hour_minute = last_hour.value + ":" + last_min.value; return hour_minute; } // methods //20151208 [modify] create day array DatePicker.prototype.monthDays = function () { var date = moment(this.date); var tempDayArray = []; for (var i = 0; i < date.startOf('month').day() ; i++) { tempDayArray.push({ value: '', isDisabled: true }); } var today = moment(this.today); var pickDate = moment(this.pickDate); for (var i = 1; i <= date.endOf('month').date() ; i++) { var isDsiabled = true; if (this.startDate != undefined) { isDsiabled = isDsiabled && (date.date(i).isAfter(this.startDate) || date.date(i).isSame(this.startDate)); } if (this.endDate != undefined) { isDsiabled = isDsiabled && (date.date(i).isBefore(this.endDate) || date.date(i).isSame(this.endDate)); } tempDayArray.push({ value: i, isTody: today.isSame(this.date, 'month') && (today.date() == i), isDisabled: !isDsiabled }); } this.dayArray = tempDayArray; }; DatePicker.prototype.isEqual = function (day) { var pickDate = moment(this.pickDate); return pickDate.isSame(this.date, 'month') && (pickDate.date() == day); }; DatePicker.prototype.pick = function (day) { if (!day.isDisabled) { var tempDate = moment(this.date).clone().date(day.value); this.pickDate = tempDate.toDate(); } }; DatePicker.prototype.dayClass = function (day) { var dayClass = ''; if (this.isEqual(day.value)) { dayClass += ' is-checked'; } if (day.isTody) { dayClass += ' mdl-datepicker-date__today'; } return dayClass; }; DatePicker.prototype.hourClass = function (hour) { if (last_hour) { last_hour.is_selected = false; } console.log('last_hour', last_hour); hour.is_selected = true; last_hour = hour; } DatePicker.prototype.minClass = function (min) { if (last_min.is_selected == true) { last_min.is_selected = false; } min.is_selected = true; last_min = min; } DatePicker.prototype.gotoToday = function () { this.date.setFullYear(this.pickDate.getFullYear()); this.date.setMonth(this.pickDate.getMonth()); this.monthDays(); //this.isYearList = false; }; DatePicker.prototype.displayMonth = function () { return moment(this.date).format('YYYY 年 MMMM'); }; DatePicker.prototype.withoutTimeBar = function () { return true; }; DatePicker.prototype.displayHour = function () { return moment(this.date).format('HH:mm'); } DatePicker.prototype.displayPickDate = function () { return moment(this.pickDate).format('dddd, MMM D'); }; /* DatePicker.prototype.showYearList = function(){ this.isYearList = true; this.yearMonth(); } DatePicker.prototype.yearMonth = function(){ var tempMonthArray = []; var month = this.pickDate.getMonth()-12; for(var i = month ; i < 24;i++){ tempMonthArray.push({ year : 2000, month: month+i }); } this.monthArray = tempMonthArray; } */ // return return DatePicker; })(); this.$get = ['$mdDialog', function ($mdDialog) { return { open: function (pickDate, confirm, cancel, options) { var datePickerInstance = new DatePicker(pickDate, options); $mdDialog.dialog('JSplugins/angular-material-lite/template/datepicker.tmp.html', function (dialog) { var returnObject = {}; returnObject.datePacker = datePickerInstance; returnObject.confirm = confirm; returnObject.background = { click: function () { dialog.hide(); } }; if (cancel) returnObject.cancel = cancel; return returnObject; }); }, getDatePickerInstance: function (pickDate, limitDate) { return new DatePicker(pickDate, limitDate); } }; }]; }]) .directive('mdlDatepicker', ['$parse', '$datePicker', function ($parse, $datePicker) { return { restrict: 'A', scope: { mdlDatepicker: '=', //日期 mdlDateMin: '=', //最小日期 mdlDateMax: '=' //最大日期 }, compile: function (tElem, tAttrs) { return { post: function (scope, element, attrs) { var eventName; if (isMobile) { eventName = 'touchend'; } else { eventName = 'mouseup'; } angular.element(element[0]).attr('readonly', 'readonly').on(eventName, function () { angular.element(element[0]).addClass('is-focus'); $datePicker.open(scope.mdlDatepicker || new Date(), function (dialog) { angular.element(element[0]).removeClass('is-focus'); scope.mdlDatepicker = dialog.datePacker.pickDate; dialog.hide(); }, function (dialog) { angular.element(element[0]).removeClass('is-focus'); dialog.hide(); }, { start: scope.mdlDateMin, end: scope.mdlDateMax }); }); scope.$watch('mdlDatepicker', function (newVals, oldVals) { if (newVals == undefined) element[0].value = ''; else element[0].value = moment(newVals).format('YYYY/MM/DD'); }); } }; } }; }]); })(); (function () { 'use strict'; angular .module('material.components.calculater', ['material.components.dialog']) .provider('$calculater', function () { var calculater = (function () { // constructors /** * options : { * title, * defaultNum, * numMax:0, * numMin:0, * decimalMax:2, * decimalMin:0, * decimal:true/false, * decimalLength:0, * type: string/number/date * } */ function Calculater(options) { this.options = angular.merge({ type: 'number' }, options); //20180531 modify by Dustdusk for 有輸入小數位數時則直接開啟小數輸入 if (this.options.decimalLength && this.options.decimalLength > 0) { this.options.decimal = true; } this.options.title = this.options.title; if (this.options.type == 'date') { this.focus = 'hour'; var time = this.options.defaultNum.split(':'); try { this.timeDisplay = { hour: time[0], minute: time[1], second: time[2] }; } catch (e) { this.timeDisplay = { hour: '00', minute: '00', second: '00' }; } } else { if (this.options.enableEmpty == true) this.numDisplay = '' + (this.options.defaultNum || ''); else this.numDisplay = '' + (this.options.defaultNum || '0'); } } Calculater.prototype.addNum = function (numBtn) { if (this.options.type != 'date') { if (numBtn == '.' && this.numDisplay.indexOf(numBtn) != -1) { return; } else if (numBtn == '.' && !this.options.decimal) { return; } if (this.options.type == 'number') { if (numBtn != '.' && this.numDisplay === '0' || this.numDisplay === '0%') { this.numDisplay = ''; } else if (this.numDisplay.indexOf('.') != -1) { if (this.numDisplay.split('.')[1].length >= (+this.options.decimalLength)) { return; } } } //20210622 百分比處理 if (this.numDisplay.includes('%')) this.numDisplay = this.numDisplay.substr(0, this.numDisplay.length - 1) + numBtn + '%'; else this.numDisplay += numBtn + ''; } else { this.timeDisplay[this.focus] += numBtn + ''; } }; Calculater.prototype.deleteNum = function () { if (this.options.type != 'date') { this.numDisplay = this.numDisplay.substr(0, this.numDisplay.length - 1); if (this.options.type == 'number' && this.options.enableEmpty != true) { if (this.numDisplay === '') this.numDisplay = '0'; } } else { this.timeDisplay[this.focus] = this.timeDisplay[this.focus].substr(0, this.timeDisplay[this.focus].length - 1); if (this.timeDisplay[this.focus] === '') { this.timeDisplay[this.focus] = '00'; } } }; Calculater.prototype.confirmNum = function (confirm) { //20210622 百分比處理 var per = false; if (this.numDisplay.includes('%')) { this.numDisplay = this.numDisplay.substr(0, this.numDisplay.length - 1); per = true; } if (this.options.enableEmpty == true) { if (this.numDisplay != '') this.numDisplay = new Number(this.numDisplay) + ''; } else if (this.options.type == 'number') { this.numDisplay = new Number(this.numDisplay) + ''; } //20210622 百分比處理 if (this.numDisplay != "NaN" && per) this.numDisplay += '%'; if (confirm) confirm(this.numDisplay); }; //20210622 負號處理 Calculater.prototype.negative = function () { if (this.numDisplay && this.numDisplay != '0' && this.numDisplay != '0%') { if (!this.numDisplay.includes('-')) this.numDisplay = '-' + this.numDisplay; else this.numDisplay = this.numDisplay.substr(1, this.numDisplay.length - 1); } }; //20210622 百分比處理 Calculater.prototype.percent = function () { if (this.numDisplay) { if (!this.numDisplay.includes('%')) this.numDisplay = this.numDisplay + '%'; else this.numDisplay = this.numDisplay.substr(0, this.numDisplay.length - 1); } }; return Calculater; })(); this.$get = ['$mdDialog', '$filter', function ($mdDialog, $filter) { return { open: function (calcConfirm, calcCancel, options) { options.title = options.title || $filter('translate')('common.msg.please_input_num'); var calculaterInstance = new calculater(options); $mdDialog.dialog('JSplugins/angular-material-lite/template/SMTCalculater.tmp.html', function (dialog) { //20210622 百分比處理 dialog.canPercent = false; dialog.canNegative = false; if (calculaterInstance.options.Percent) dialog.canPercent = calculaterInstance.options.Percent; if (calculaterInstance.options.Negative) dialog.canNegative = calculaterInstance.options.Negative; return { calculater: calculaterInstance, time_focus: {}, title: $filter('translate')('common.calc_num'), beforeShown: function () { if (this.calculater.options.type != 'date') { //20170620 modify by Dustdusk for 新增開啟後focus(only on windows),Android裝置則是會readOnly dialog.display = document.getElementById('calculater_display'); if (!window.cordova) { dialog.display.focus(); dialog.display.select(); } else { dialog.display.select(); dialog.display.readOnly = true; } } else { dialog.hour_display = document.getElementById('hour_display'); dialog.minute_display = document.getElementById('minute_display'); dialog.second_display = document.getElementById('second_display'); if (!window.cordova) { dialog.hour_display.focus(); dialog.hour_display.select(); } else { dialog.hour_display.select(); dialog.hour_display.readOnly = true; dialog.minute_display.readOnly = true; dialog.second_display.readOnly = true; } } }, //20170620 modify by Dustdusk for 控卡只能數字輸入 //20170622 modify by Dustdusk for Enter 輸入 key_input: function (event, type) { if (dialog.calculater.options.type != 'date') { if (event.keyCode == 13) { dialog.calculater.confirmNum(dialog.confirm); } else if (event.keyCode >= 48 && event.keyCode <= 57) { if (dialog.calculater.options.type == 'number') { if (dialog.calculater.numDisplay === '0') { dialog.calculater.numDisplay = ''; } if (dialog.calculater.options.decimal && dialog.calculater.numDisplay.indexOf('.') != -1) { if (dialog.calculater.numDisplay.split('.')[1].length > (+dialog.calculater.options.decimalLength)) { event.stopPropagation(); event.preventDefault(); } } } } else if (dialog.calculater.options.decimal && event.keyCode == 46 && dialog.calculater.numDisplay.indexOf('.') == -1) { } else { event.stopPropagation(); event.preventDefault(); } } else { if (event.keyCode == 13) { if (dialog.calculater.focus == 'hour') { dialog.calculater.focus = 'minute'; dialog.minute_display.select(); if (!window.cordova) dialog.minute_display.focus(); } else if (dialog.calculater.focus == 'minute') { dialog.calculater.focus = 'second'; dialog.second_display.select(); if (!window.cordova) dialog.second_display.focus(); } else if (dialog.calculater.focus == 'second') { dialog.confirm(); } } else if (event.keyCode >= 48 && event.keyCode <= 57) { if (dialog.calculater.timeDisplay[dialog.calculater.focus].length >= 2) { dialog.calculater.timeDisplay[dialog.calculater.focus] = ''; } } else { event.stopPropagation(); event.preventDefault(); } } }, add_num: function (num) { if (dialog.calculater.options.type == 'date') { if (dialog.calculater.timeDisplay[dialog.calculater.focus].length >= 2) { dialog.calculater.timeDisplay[dialog.calculater.focus] = ''; } dialog.calculater.addNum(num); //當輸入完為2位則自動切換到下一格 if (dialog.calculater.timeDisplay[dialog.calculater.focus].length == 2) { if (dialog.calculater.focus == 'hour') { dialog.calculater.focus = 'minute'; } else if (dialog.calculater.focus == 'minute') { dialog.calculater.focus = 'second'; } else if (dialog.calculater.focus == 'second') { dialog.confirm(); } } } else { if (dialog.display.selectionStart == dialog.display.selectionEnd) { dialog.calculater.addNum(num); } else { var display_str = dialog.display.value; var startStr = display_str.substring(0, dialog.display.selectionStart); var endStr = display_str.substring(dialog.display.selectionEnd, display_str.length); dialog.calculater.numDisplay = ''; dialog.calculater.addNum(num); dialog.calculater.numDisplay = startStr + dialog.calculater.numDisplay + endStr; //20181221 modify by Dustdusk for M#: 單一數字時會無法使用螢幕鍵盤輸入 //因此每次輸入後手動重製selectEnd、selectStart if (!window.cordova) { dialog.display.focus(); dialog.display.setSelectionRange(dialog.display.selectionStart + 1, dialog.display.selectionStart + 1); } } } }, deleteNum: function () { if (dialog.calculater.options.type == 'date') { dialog.calculater.deleteNum(); } else { if (dialog.display.selectionStart == dialog.display.selectionEnd) { dialog.calculater.deleteNum(); } else { var startStr = dialog.calculater.numDisplay.substring(0, dialog.display.selectionStart); var endStr = dialog.calculater.numDisplay.substring(dialog.display.selectionEnd, dialog.calculater.numDisplay.length); dialog.calculater.numDisplay = startStr + endStr; if (dialog.calculater.options.type == 'number' && dialog.calculater.options.enableEmpty != true) { if (dialog.calculater.numDisplay == '') dialog.calculater.numDisplay = '0'; } } } }, confirm: function (numDisplay) { if (dialog.calculater.options.type != 'date') { dialog.calculater.confirmNum(function () { calcConfirm(dialog.calculater.numDisplay, dialog); }); } else { calcConfirm(dialog.calculater.timeDisplay, dialog); } }, cancel: function () { if (calcCancel) calcCancel(dialog); }, back: function () { dialog.hide(); }, background: { class: ['calculater-background'], click: function (event) { //20191107 modify by Dustdusk for M#: 修正開窗很難點 if (!window.cordova) { if (dialog.cancel) dialog.cancel(); } } }, negative: function () { dialog.calculater.negative(); }, percent: function () { dialog.calculater.percent(); }, clear: function () { dialog.calculater.numDisplay = '0'; } }; }); }, decimalAdd: function (num1, num2) { var r1, r2, m; try { r1 = num1.toString().split('.')[1].length; } catch (e) { r1 = 0; } try { r2 = num2.toString().split('.')[1].length; } catch (e) { r2 = 0; } m = Math.pow(10, Math.max(r1, r2)); return Math.round(num1 * m + num2 * m) / m; }, decimalSub: function (num1, num2) { var r1, r2, m; try { r1 = num1.toString().split('.')[1].length; } catch (e) { r1 = 0; } try { r2 = num2.toString().split('.')[1].length; } catch (e) { r2 = 0; } m = Math.pow(10, Math.max(r1, r2)); return Math.round(num1 * m - num2 * m) / m; }, decimalMutiple: function (num1, num2, decimal_length) { var m = 0, s1 = num1.toString(), s2 = num2.toString(); try { m += s1.split('.')[1].length; } catch (e) { } try { m += s2.split('.')[1].length; } catch (e) { } if (decimal_length) { if (m > (+decimal_length)) { var temp = Number(s1.replace('.', '')) * Number(s2.replace('.', '')); temp = Math.round(temp / Math.pow(10, (m - (+decimal_length)))); return temp / Math.pow(10, decimal_length); } else { return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m); } } else { return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m); } } }; }]; }) .directive('mdlCalculater', ['$parse', '$calculater', '$filter', function ($parse, $calculater, $filter) { return { restrict: 'A', scope: { mdlCalculater: '=', mdlCalculaterTitle: '@', mdlCalculaterDecimal: '=', mdlCalculaterDecimalLength: '=', mdlCalculaterNoZero: '=', mdlCalculaterMax: '=', mdlCalculaterMin: '=', enableEmpty: '=', mdlCalculaterNegative: '=', mdlCalculaterPercent: '=', mdlCalculaterConfirm: '=', mdlCalculaterCancel: '=' }, compile: function () { return { post: function (scope, element) { var eventName; if (isMobile) { eventName = 'touchend'; } else { eventName = 'mouseup'; } angular.element(element[0]).attr('readonly', 'readonly').on(eventName, function () { angular.element(element[0]).addClass('is-focus'); var options = { defaultNum: scope.mdlCalculater, title: scope.mdlCalculaterTitle, decimal: scope.mdlCalculaterDecimal, decimalLength: scope.mdlCalculaterDecimalLength, enableEmpty: scope.enableEmpty, Negative: scope.mdlCalculaterNegative, Percent: scope.mdlCalculaterPercent, Confirm: scope.mdlCalculaterConfirm, Cancel: scope.mdlCalculaterCancel }; $calculater.open(function (num, dialog) { scope.mdlCalculaterTitle = scope.mdlCalculaterTitle || ''; var msg = ''; if (scope.mdlCalculaterMax && (+scope.mdlCalculaterMax) < (+num)) { msg += scope.mdlCalculaterTitle + $filter('translate')('common.msg.great_than') + scope.mdlCalculaterMax + '
'; } if (scope.mdlCalculaterMin && (+scope.mdlCalculaterMin) > (+num)) { msg += scope.mdlCalculaterTitle + $filter('translate')('common.msg.less_than') + scope.mdlCalculaterMin + '
'; } if (scope.mdlCalculaterNoZero && (+num) == 0) { msg += scope.mdlCalculaterTitle + $filter('translate')('common.msg.input_zero') + '
'; } if (msg == '') { angular.element(element[0]).removeClass('is-focus'); scope.mdlCalculater = num; dialog.hide(); } else { if (scope.$root.showAlert) scope.$root.showAlert(msg); } }, function (dialog) { angular.element(element[0]).removeClass('is-focus'); dialog.hide(); }, options); }); scope.$watch('mdlCalculater', function (newVals, oldVals) { if (newVals == undefined) element[0].value = ''; else element[0].value = newVals; }); } }; } }; }]) .directive('mdlTimepicker', ['$parse', '$calculater', '$filter', function ($parse, $calculater, $filter) { return { restrict: 'A', scope: { mdlTimepicker: '=', mdlTimepickerTitle: '@' }, compile: function () { return { post: function (scope, element) { var eventName; if (isMobile) { eventName = 'touchend'; } else { eventName = 'mouseup'; } angular.element(element[0]).attr('readonly', 'readonly').on(eventName, function () { angular.element(element[0]).addClass('is-focus'); scope.mdlTimepicker = scope.mdlTimepicker || ''; var options = { defaultNum: scope.mdlTimepicker,//.replace(/:/g,''), title: $filter('translate')('common.msg.select_time'), decimal: false, type: 'date' }; $calculater.open(function (timeDisplay, dialog) { var hour = timeDisplay.hour, min = timeDisplay.minute, sec = timeDisplay.second; if ((0 <= (+hour) && (+hour) < 24) && (0 <= (+min) && (+min) < 60) && (0 <= (+sec) && (+sec) < 60)) { scope.mdlTimepicker = hour + ':' + min + ':' + sec; angular.element(element[0]).removeClass('is-focus'); dialog.hide(); } else { if (scope.$root.showAlert) scope.$root.showAlert($filter('translate')('common.msg.time_format_error')); } }, function (dialog) { angular.element(element[0]).removeClass('is-focus'); dialog.hide(); }, options); }); scope.$watch('mdlTimepicker', function (newVals) { if (newVals == undefined) element[0].value = ''; else element[0].value = newVals; }); } }; } }; }]); })(); (function () { 'use strict'; angular .module('material.components.barcode', []) .provider('$mdlBarcode', function () { this.$get = ["$mdlBarcode", function ($mdlBarcode) { return { avgTimeByChar: 30, minLength: 5 }; }]; }) .directive('mdlBarcode', ["$mdlBarcode", function ($mdlBarcode) { return { restrict: 'A', scope: { onComplete: '&mdlBarcode' }, link: function (scope, element, attrs) { var input_value = ''; var input_time; angular.element(element).on('keypress', function (events) { events.preventDefault(); events.stopImmediatePropagation(); if (input_value === '') { input_time = Date.now(); } if (Date.now() - input_time < $mdlBarcode.avgTimeByChar) { if (events.keyCode != 13) { input_time = Date.now(); input_value += events.key; } else if (input_value.length > $mdlBarcode.minLength) { element[0].value = input_value; scope.onComplete({ value: input_value }); input_value = ''; } } else { input_value = ''; } }); } }; }]); })(); (function () { "use strict"; angular .module('material.components.barcode', []) .provider('$mdlBarcode', function () { this.$get = function () { return { avgTimeByChar: 30, minLength: 1 }; }; }) .directive('mdlBarcode', function ($mdlBarcode, $timeout) { return { restrict: 'A', scope: { onComplete: '=mdlBarcode' }, link : function(scope, element, attrs){ var input_value = ''; var input_time; //*** only for develope angular.element(element).on('keypress', function(events){ //events.preventDefault(); //events.stopImmediatePropagation(); if(events.keyCode == 13){ $timeout(function(){ scope.onComplete(element[0].value); }) } }); } } }) })(); (function () { 'use strict'; angular .module('material.components.dashboard', []) .directive('mdlDashboard', function () { var config = {}; var defualt_config = { radius: 48, //圓環半徑 innerRadiusRate: 0.7, //圓環的比例 startAngle: -80, //起始的角度 endAngle: 80, //結束的角度 padding_top: 16, //上方的padding padding_left: 28, //兩邊的padding limit_font_size: 10, //邊界值字體大小 value_font_size: 20, //目前數值字體大小 line_width: 6, //指針寬度 colorType: []//綠黃紅 }; var pie, arc, arcs; function prepareDatas(data) { var datas = []; config.colorType = []; //if(data.guideline_max && data.guideline_max!=''){ //datas.push({label:data.guideline_min, value:1}); //datas.push({label:'', value:0});//紅色 if (data.min_spec !== null) { datas.push({ label: data.min_spec, value: 1 });//紅色 config.colorType.push('#db4b3c'); } else { datas.push({ label: '', value: 1 });//黃色 config.colorType.push('#f6cf5a'); } if (data.min_warn !== null) { datas.push({ label: '', value: 1 });//黃色 config.colorType.push('#f6cf5a'); } else { datas.push({ label: '', value: 1 });//綠色 config.colorType.push('#68bd84'); if (data.min_spec === null) { config.colorType[0] = '#68bd84'; } } datas.push({ label: data.stardard_value, value: 1 });//綠 config.colorType.push('#68bd84'); datas.push({ label: '', value: 1 });//綠 config.colorType.push('#68bd84'); if (data.max_warn !== null) { if (data.max_spec == null) datas.push({ label: '', value: 1 });//黃 else datas.push({ label: data.max_spec, value: 1 });//黃 config.colorType.push('#f6cf5a'); } else { if (data.max_spec == null) datas.push({ label: '', value: 1 });//黃 else datas.push({ label: data.max_spec, value: 1 });//黃 config.colorType.push('#68bd84'); } if (data.max_spec !== null) { datas.push({ label: '', value: 1 });//紅色 config.colorType.push('#db4b3c'); } else { datas.push({ label: '', value: 1 });//紅色 //如果上限不存在則延續上一個的顏色 config.colorType.push(config.colorType[config.colorType.length - 1]); } //} else { // datas.push({label:'', value:100}); //} return datas; } function prepareHtml(element) { d3.select(element[0]).selectAll('div').remove(); d3.select(element[0]).attr('class', 'mdl-dashboard'); d3.select(element[0]).append('div').attr('class', 'mdl-dashboard-cicle'); d3.select(element[0]).append('div').attr('class', 'mdl-dashboard-bottom'); // d3.select(element[0]).append('div').attr('class', 'mdl-dashboard-label'); return element; } function calcValueDeg(data) { var deg = 0, max = null, min = null; if (data.max_warn !== '') { max = data.max_warn; } else if (data.max_spec !== null) { max = data.max_spec; } if (data.min_warn !== null) { min = data.min_warn; } else if (data.min_spec !== null) { min = data.min_spec; } if (data.min_spec !== null && data.param_value < (+data.min_spec)) { deg = (1 / 12) * (config.endAngle - config.startAngle); } else if (data.max_spec !== null && data.param_value > (+data.max_spec)) { deg = (1 - 1 / 12) * (config.endAngle - config.startAngle); } else if (data.min_warn !== null && data.param_value < (+data.min_warn)) { deg = (3 / 12) * (config.endAngle - config.startAngle); } else if (data.max_warn !== null && data.param_value > (+data.max_warn)) { deg = (1 - 3 / 12) * (config.endAngle - config.startAngle); } else if (min !== null && max !== null) { var _temp = ((+data.param_value) - (+min)) / ((+max) - (+min)); deg = ((2 * _temp + 2) / 6) * (config.endAngle - config.startAngle); } else { deg = (config.endAngle - config.startAngle) / 2; } return deg; } function nowRangeColor(result) { if (result == 'green') { return '#68bd84'; } else if (result == 'yellow') { return '#f6cf5a'; } else if (result == 'red') { return '#db4b3c'; } } /* function checkWarn(data){ if(data.guideline_max && data.guideline_max!=''){ if(data.guideline_mode == '1'){ if((+data.guideline_2) <= (+data.param_value)) //return 'is-warn'; data.isWarn = true; } else if(data.guideline_mode == '2'){ if((+data.guideline_1) >= (+data.param_value)) //return 'is-warn'; data.isWarn = true; } else if(data.guideline_mode == '3'){ if((+data.guideline_2) <= (+data.param_value)|| (+data.guideline_1) >= (+data.param_value)){ //return 'is-warn'; data.isWarn = true; } } } return data; }*/ function initDashboard(element, data) { data.param_value = new Number(data.param_value); element = prepareHtml(element); var circle = d3.select(element[0]).select('.mdl-dashboard-cicle'); var pi = pi = Math.PI; //var datas = prepareDatas(checkWarn(data)); //產生出d3.js 能讀取的資料集合 var datas = prepareDatas(data); //產生出d3.js 能讀取的資料集合 var valueDeg = calcValueDeg(data); //算出目前的度數 var color = d3.scaleOrdinal(config.colorType); //清空directive下的svg d3.select(element[0]).selectAll('svg').remove(); //建立SVG var vis = circle.append('svg').attr('width', config.radius * 2 + config.padding_left * 2).attr('height', config.radius + config.padding_top + 5)//設定長寬 //建立G節點 .append('svg:g').attr('transform', 'translate(' + (config.radius + config.padding_left) + ',' + (config.radius + config.padding_top) + ')'); //設定圓的內外徑 arc = d3.arc() .outerRadius(config.radius) //.outerRadius(config.radius*(1-(config.innerRadiusRate/2))) .innerRadius(config.radius * config.innerRadiusRate); //.innerRadius(config.radius*(1-(config.innerRadiusRate/2))); pie = d3.pie().value(function (d) { return d.value; }) .startAngle(config.startAngle * (pi / 180)).endAngle(config.endAngle * (pi / 180))//設定起始/結束角度 .sort(null); //取消排序 //產生扇型態 arcs = vis.data([datas]) .selectAll('g.slice').data(pie).enter()//for 迴圈 .append('svg:g').attr('class', 'slice'); arcs.append('svg:path') .attr('fill', function (d, i) { return color(i); }) //.attr('fill', '#ffffff' ) //.attr('stroke', '#eeeeee') //.attr('stroke-dasharray','2,4') //.attr('stroke-width', 2) .attr('d', arc); arcs.append('text').attr('transform', function (d) { var x = Math.sin(d.endAngle) * (config.radius + 4); var y = 0 - Math.cos(d.endAngle) * (config.radius + 4); return 'translate(' + x + ',' + y + ')'; }) .style('font-size', config.limit_font_size + 'px') .attr('text-anchor', function (d, i) { //console.log(i); if (datas.length / 2 == (i + 1)) { return 'middle'; } else if (d.endAngle < 0) { return 'end'; } else { return 'start'; } }) .text(function (d, i) { return datas[i].label != '' ? new Number(datas[i].label) : datas[i].label; }); //指針 /* circle.selectAll('svg').append('line').attr('class', 'pointer') .attr('x1', config.padding_left-2).attr('y1', config.radius+config.padding_top)//起 .attr('x2', config.padding_left + (config.radius*(1-config.innerRadiusRate)) + 2).attr('y2', config.radius+config.padding_top)//迄 .style('stroke', 'black').style('stroke-width', config.line_width) */ //var right = config.radius*(1-config.innerRadiusRate); var right = config.radius - (config.value_font_size); circle.selectAll('svg').append('polygon') .attr( 'points', (config.padding_left + 2) + ',' + (config.radius + config.padding_top) //左 + ' ' + (config.padding_left + right + 4) + ',' + (config.radius + config.padding_top - (config.line_width / 2)) //上 + ' ' + (config.padding_left + right + 8) + ',' + (config.radius + config.padding_top) //右 + ' ' + (config.padding_left + right + 4) + ',' + (config.radius + config.padding_top + (config.line_width / 2)) //下 ) .attr('class', 'pointer') .style('fill', '#000000') .style('transform-origin', config.radius + config.padding_left + 'px ' + (config.radius + config.padding_top) + 'px') .style('transform', 'rotate(' + (valueDeg + 90 + config.startAngle) + 'deg)'); //目前數值 circle.selectAll('svg').append('text').attr('class', 'pointer-value') .attr('transform', 'translate(' + (config.radius + config.padding_left) + ', ' + (config.radius + config.padding_top) + ')') .style('font-size', config.value_font_size + 'px') .style('font-weight', '600') .attr('text-anchor', 'middle') .style('text-shadow', '0px 0px 10px #fff, 0px 0px 10px #fff, 0px 0px 10px #fff, 0px 0px 10px #fff, 0px 0px 10px #fff, 0px 0px 10px #fff, 0px 0px 10px #fff') .text(new Number(data.param_value)); //label d3.select(element[0]).select('.mdl-dashboard-bottom').style('background', nowRangeColor(data.param_result)).text(data.param_name); d3.select(element[0]).classed('is-warn', (data.need_alert == 'Y')); } return { restrict: 'A', scope: { 'datas': '=', 'config': '=' }, link: function (scope, element, attrs) { angular.extend(config, defualt_config); if (scope.config) angular.extend(config, scope.config); scope.$watch('datas', function (newVals, oldVals) { initDashboard(element, newVals); //繪圖初始化 }, true); } }; }) .directive('mdlPiechart', function () { var config = { radius: 50, innerRadiusRate: 0, padding: 10, colorType: { '1': ['black', 'green', 'yellow', 'red'],//綠黃紅 '2': ['black', 'red', 'yellow', 'green'],//紅黃綠 '3': ['black', 'red', 'green', 'red']//紅綠紅 }, isShowLabel: true }; var pie, arc, arcs; function prepareColor(datas) { var colors = []; datas.forEach(function (data) { colors.push(data.color); }); return colors; } function initPiechart(element, data) { d3.select(element[0]).attr('class', 'mdl-piechart'); var pi = Math.PI; var color = d3.scaleOrdinal(prepareColor(data)); //清空directive下的svg d3.select(element[0]).selectAll('svg').remove(); var vis = d3.select(element[0]).append('svg').data([data])//設定資料 .attr('width', config.radius * 2 + config.padding * 2).attr('height', config.radius * 2 + config.padding * 2)//設定長寬 .append('svg:g').attr('transform', 'translate(' + (config.radius + config.padding) + ',' + (config.radius + config.padding) + ')'); arc = d3.arc().outerRadius(function (d, i) { var padding = d.data.focus ? 6 : 0; return config.radius + padding; }) .innerRadius(config.radius * config.innerRadiusRate); /* .innerRadius(function(d, i) { var padding = d.data.focus?4:0; return (config.radius*config.innerRadiusRate) + padding; }); */ pie = d3.pie().value(function (d) { return d.value; }) .sort(null); //取消排序 arcs = vis.selectAll('g.slice').data(pie).enter().append('svg:g').attr('class', 'slice'); arcs.append('svg:path').attr('fill', function (d, i) { return color(i); }).attr('d', arc) if (config.isShowLabel) { arcs.append('text').attr('transform', function (d) { var angle = (d.endAngle - d.startAngle) / 2 + d.startAngle; var x = Math.sin(angle) * (config.radius + 20); var y = 0 - Math.cos(angle) * (config.radius + 20) + 6; return 'translate(' + x + ',' + y + ')'; }) .style('font-size', '12px') .attr('text-anchor', 'middle') .text(function (d, i) { return data[i].label; }); } } return { restrict: 'A', scope: { config: '=', //設定 datas: '=' //雙向data binding }, link: function (scope, element, attrs) { config.radius = new Number(attrs.chartRadius); config.isShowLabel = attrs.isShowLabel == 'true'; if (scope.config) angular.extend(config, scope.config); scope.$watch('datas', function (newVals, oldVals) { initPiechart(element, newVals); //繪圖初始化 }, true); } }; }); })(); (function () { 'use strict'; var kmilistSeq = 0, module = angular .module('material.components.list', []) .directive('kmiList', ['$parse', '$mdDialog', '$filter', '$state', '$window', function ($parse, $mdDialog, $filter, $state, $window) { var temp = {}, sheetTemplate = '', splitTemplate = '
', buttonTemplate = '
'; //更新列表及欄位長度 function columnResizing(event) { //temp.diff = event.pageX-temp.x; var diff = 0; if (window.cordova) diff = event.touches[0].pageX - temp.x; else diff = event.pageX - temp.x; var width = temp.width + diff; if (width >= 0) { temp.diff = diff; if (window.cordova) { temp.content.style.cssText = 'flex:0 0 ' + width + 'px !important;'; } else { temp.cssRule.style.cssText = 'flex:0 0 ' + width + 'px !important;'; } temp.contentCSSRule.style.cssText = 'min-width:' + (+temp.content_width + diff) + 'px !important;'; } } function getColumnInfo(index, headerColumn, headerColumnSave) { //一旦設定為ng-hide的隱藏欄位就不處理 if (headerColumn.className.indexOf('ng-hide') == -1) { var columnObject = { index: index };//紀錄標題資訊的物件 //顯示及順序 if (headerColumn.className.indexOf('require') != -1) { columnObject.disabled = true; columnObject.isSelect = true; } else { columnObject.disabled = false; if (headerColumnSave) { columnObject.isSelect = headerColumnSave.isSelect; } else if (headerColumn.className.indexOf('hide') != -1) { columnObject.isSelect = false; } else { columnObject.isSelect = true; } } if (headerColumn.className.indexOf('width-fixed') != -1) { columnObject.widthFixed = true; } else { columnObject.widthFixed = false; } if (headerColumnSave) { columnObject.order = headerColumnSave.order; if (headerColumnSave.width !== null) columnObject.width = headerColumnSave.width; else columnObject.width = headerColumn.offsetWidth; } else { var order = headerColumn.getAttribute('order'); if (order && order != '') { columnObject.order = order; } else { columnObject.order = columnObject.index; } columnObject.width = headerColumn.offsetWidth; } //如果有設定最小寬度則不可小於最小寬度 var minWith = isNaN(+headerColumn.style.minWidth.replace('px')); if (columnObject.width < minWith) { columnObject.width = minWith; } //columnObject.width為0則不處理 if (columnObject.width == 0) { columnObject.width = undefined; } return columnObject; } } //根據header組出列表 function getColumnList(headerColumns, headerColumnList) { for (var index = 0; index < headerColumns.length; index++) { var headerColumn = headerColumns[index]; var columnObject = headerColumnList[index]; if (headerColumn.className.indexOf('ng-hide') == -1) { //取出標題資訊 if (headerColumn.className.indexOf('head-controls') != -1) { columnObject.display = $(headerColumn).find('label').html(); } else if (headerColumn.innerHTML.indexOf('<') == -1) { if (headerColumn.getAttribute('column-name')) { columnObject.display = headerColumn.getAttribute('column-name'); } else if (headerColumn.innerHTML != '') { columnObject.display = headerColumn.innerHTML; } else { columnObject.display = '#'; } } else { if (headerColumn.getAttribute('column-name')) { columnObject.display = headerColumn.getAttribute('column-name'); } else { columnObject.display = '#'; } } } else { columnObject.display = '#'; columnObject.NotVisibility = true;//表示畫面上不可見 } if (columnObject.display == '#') { //columnObject.display = ''; columnObject.isHide = true;//不顯示 } } return $filter('orderBy')(headerColumnList, 'order'); } //將資料從localStorage 取出 function loadColumnList(id) { if (id != undefined) return JSON.parse(localStorage.getItem(id)); else return null; } //將資料存進localStorage function saveColumnList(id, headerColumnList) { if (id != undefined) localStorage.setItem(id, JSON.stringify(headerColumnList)); else return null; } //開啟header選單 function openColumnSelector(scope, sheet, headColumnList, callback) { $mdDialog.dialog('JSplugins/angular-material-lite/template/checkList.tmp.html', function (dialog) { return { title: $filter('translate')('common.msg.plz_select'), beforeShown: function () { var checklist_position = ''; if (!window.cordova) checklist_position = '#column-selector-list .ps-scrollbar-content'; else checklist_position = '#column-selector-list'; sortablejs.create($(checklist_position)[0], { ghostClass: 'ghost', filter: '.undragable', handle: '.mdl-check-list__icon', onEnd: function (evt) { var newIndex = evt.newIndex; var oldIndex = evt.oldIndex; var chooseItem = dialog.itemList.splice(oldIndex, 1)[0]; dialog.itemList.splice(newIndex, 0, chooseItem); dialog.itemList.forEach(function (item, index) { item.order = index + 1; sheet.cssRules[(item.index * 2)].style.order = item.order; }); scope.$apply(); } }); }, order: 'order', label: 'display', code: 'display', back: function () { //setColumnSelectorStatus(attrs.columnSelectorId, dialog.itemList); var temp = dialog.itemList; dialog.hide(); if (callback) callback(temp); }, itemList: headColumnList, itemClick: function (item, event) { item.isSelect = !item.isSelect; if (item.isSelect) { sheet.cssRules[(item.index * 2)].style.display = ''; } else { sheet.cssRules[(item.index * 2)].style.display = 'none'; } }, confirm: function () { dialog.hide(); }, isConfirm: true, isDrag: true }; }); } function ScollbarPost($scope, $elem, $attr, update, isScrollbar, isColumnSelector) { //if($attr.kmiScrollbar == undefined || $attr.kmiScrollbar == ''){ // $attr.kmiScrollbar = $elem[0].offsetWidth + 'px'; //} if (isScrollbar) { var jqWindow = angular.element($window); $elem = $($elem[0]).css('overflow', 'hidden').css('position', 'relative'); var content = $elem.find('.kmiScrollbar-content'); if (isColumnSelector) { if ($attr.kmiScrollbar == undefined || $attr.kmiScrollbar == '') { $attr.kmiScrollbar = $elem[0].offsetWidth + 'px'; } content.css('min-width', $attr.kmiScrollbar); } var rowContent = content.find('.kmi-list__row-content').css('overflow', 'hidden'); var container_y_offset_top = content.find('.kmi-list__header').length > 0 ? 38 : 0; var options = { 'wheelPropagation': true, //If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element. 'minScrollbarLength': 10, 'container_y': rowContent, 'container_y_offset_top': container_y_offset_top }; $scope.$evalAsync(function () { $elem.perfectScrollbar(options); var onScrollHandler = $parse($attr.onScroll); $elem.scroll(function () { var scrollTop = $elem.scrollTop(); var scrollHeight = $elem.prop('scrollHeight') - $elem.height(); $scope.$apply(function () { onScrollHandler($scope, { scrollTop: scrollTop, scrollHeight: scrollHeight }); }); }); }); // This is necessary when you don't watch anything with the scrollbar $elem.bind('mouseenter', function () { update('mouseenter'); }); // Possible future improvement - check the type here and use the appropriate watch for non-arrays if ($attr.refreshOnChange) { $scope.$watchCollection($attr.refreshOnChange, function () { update(); }); } //listent the child's size; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; var MutationObserverConfig = { childList: true, attributes: true, characterData: false }; var observer = new MutationObserver(function (mutations) { update(); }); observer.observe($elem.find('.kmiScrollbar-content')[0], MutationObserverConfig); if ($attr.refreshOnResize) { jqWindow.on('resize', update); } $elem.bind('$destroy', function () { jqWindow.off('resize', update); $elem.perfectScrollbar('destroy'); }); } else { $elem = $elem.css('overflow', 'auto'); if (window.cordova) { if (isColumnSelector) { if ($attr.kmiScrollbar == undefined || $attr.kmiScrollbar == '') { $attr.kmiScrollbar = $elem[0].offsetWidth + 'px'; } $elem.find('.kmi-list__header').css('min-width', $attr.kmiScrollbar); //20190115 modify by Dustdusk for M#: 修正Andorid scrollbar $elem.find('.kmi-list__row-content').css('min-width', $attr.kmiScrollbar).css('overflow', 'auto'); } } } } function compile(tElem, tAttrs) { var isColumnSelector = $(tElem).hasClass('column-selector'), //是否使用欄位調整功能 isColumnSplit = !$(tElem).hasClass('none-column-split'), //是否使用欄位寬度調整 isScrollbar = !$(tElem).hasClass('none-scrollbar') && !window.cordova, //是否使用客制的左右拖拉 hashCode = Date.now() + '' + kmilistSeq;//此list的hashcode註記 //var headerColumnList = []; kmilistSeq++; if (isScrollbar) { tElem.html('
' + tElem.html() + '
'); } //將list 加上上hashCode方便標記,並將其下全部的column加上標註 var row = $(tElem).addClass('list-' + hashCode).find('.kmi-list__row-content .kmi-list__row'); if (isColumnSelector || isColumnSplit) { row.each(function (index, single_row) { single_row = $(single_row); var headerColumns = single_row.find('.kmi-list__column'); if (headerColumns && headerColumns.length > 0) { headerColumns.each(function (index, content_column) { $(content_column).addClass('column' + (index + 2)); }); if (isColumnSelector) //single_row.append('
'); $(single_row[0].firstElementChild).before('
'); } }); } return { post: function (scope, element, attrs) { var list_id = attrs.columnSelectorId ? $state.current.name + '_' + attrs.columnSelectorId : undefined,//取出list id; content_width = 0, //list總寬度 style_text = '', //list css headerColumnsSave = loadColumnList(list_id), header = $(element).find('.kmi-list__header'), headerColumns, headerColumnList = []; var columnResizeEnd = function (event) { if (window.cordova) { document.removeEventListener('touchmove', columnResizing); document.removeEventListener('touchend', columnResizeEnd); } else { document.removeEventListener('mousemove', columnResizing); document.removeEventListener('mouseup', columnResizeEnd); } if (window.cordova) temp.cssRule.style.cssText = 'flex:0 0 ' + (temp.width + temp.diff) + 'px !important;'; headerColumnList[temp.index - 1].width = temp.width + temp.diff; saveColumnList(list_id, headerColumnList);//儲存目前寬度 ScollbarUpdate();//更新Scrollbar }; var ScollbarUpdate = function (event) { if (!window.cordova) { //更新Scollbar scope.$evalAsync(function () { if (attrs.scrollDown == 'true' && event != 'mouseenter') { setTimeout(function () { $(element).scrollTop($(element).prop('scrollHeight')); }, 100); } $(element[0]).perfectScrollbar('update'); }); } }; if (isColumnSelector) { //右上角欄位選擇按鈕 ($(header[0].firstElementChild).before($(buttonTemplate).click(function () { var sheet = $(element).find('style')[0].sheet; openColumnSelector(scope, sheet, getColumnList(headerColumns, headerColumnList), function (itemList) { var real_width = 4;//padding的大小 itemList.forEach(function (item, index) { if (item.isSelect && !item.NotVisibility) { var temp = $(headerColumns[item.index - 1]).removeClass('hide'); if (item.width) { real_width += item.width; } else { real_width += temp[0].offsetWidth; } } }); headerColumnList = $filter('orderBy')(itemList, 'index'); sheet.cssRules[0].style.cssText = 'min-width:' + real_width + 'px !important;'; saveColumnList(list_id, headerColumnList); ScollbarUpdate();//更新Scrollbar }); scope.$apply(); }))); } ScollbarPost(scope, element, attrs, ScollbarUpdate, isScrollbar, isColumnSelector); headerColumns = header.find('.kmi-list__column'); headerColumns.each(function (index, header_column) { index = index + 1; var column_class = 'column' + index, cssText = '', columnObject; if (headerColumnsSave !== null && headerColumnsSave.length === headerColumns.length) { columnObject = getColumnInfo(index, header_column, headerColumnsSave[index - 1]);//將html物件轉換成物件 } else { columnObject = getColumnInfo(index, header_column); } if (columnObject) { $(header_column).addClass(column_class); headerColumnList.push(columnObject); //split 用來調整長度的css style_text += '.list-' + hashCode + ' .kmi-list__column.' + column_class; if (isColumnSplit) { //非行動裝置才有需要設定大小 if (columnObject.width != undefined) style_text += '{flex:0 0 ' + columnObject.width + 'px !important; }'; else style_text += '{}'; var header_columnSplit = $(splitTemplate).addClass(column_class).insertAfter(header_column).first().attr('index', index); var event_name = window.cordova ? 'touchstart' : 'mousedown'; header_columnSplit[0].addEventListener(event_name, function (event) { event.stopPropagation(); event.preventDefault(); if (!columnObject.widthFixed) { var sheet = $(element).find('style')[0].sheet; if (window.cordova) temp.x = event.touches[0].pageX; else temp.x = event.pageX; temp.index = $(this).attr('index'); temp.width = $(header_column).width(); temp.cssRule = sheet.cssRules[((index * 2) - 1)]; temp.content_width = 0; temp.contentCSSRule = sheet.cssRules[0]; temp.content = header_column; //一旦準備寬度就先算出全部的寬度並記錄 var i = headerColumnList.length; while (i--) { var item = headerColumnList[i], dom_item = headerColumns[item.index - 1]; if (item.width == undefined) { item.width = dom_item.offsetWidth; sheet.cssRules[((item.index * 2) - 1)].style.cssText = 'flex:0 0 ' + item.width + 'px !important;'; } if (item.isSelect && dom_item.className.indexOf('ng-hide') == -1) { temp.content_width += item.width; } } if (!window.cordova) { document.addEventListener('mousemove', columnResizing); document.addEventListener('mouseup', columnResizeEnd); } else { document.addEventListener('touchmove', columnResizing); document.addEventListener('touchend', columnResizeEnd); } } }); //20180921 對ng-hide/ng-show 進行資料監控 var ngHide = angular.element(header_column).attr('ng-hide'); if (ngHide != undefined) { scope.$watch(ngHide, function (newVals, oldVals) { if (newVals) header_columnSplit.hide(); else header_columnSplit.show(); }); } var ngShow = angular.element(header_column).attr('ng-show'); if (ngShow != undefined) { scope.$watch(ngShow, function (newVals, oldVals) { if (newVals) header_columnSplit.show(); else header_columnSplit.hide(); }); } if (header_column.className.indexOf('width-fixed') != -1) { header_columnSplit.hide(); } } else { style_text += '{}'; } //console.log(columnObject); if (isColumnSelector) { if (!columnObject.isSelect) { cssText += 'display:none;'; } else if (columnObject.width != undefined) { content_width += (+columnObject.width); } cssText += 'order:' + columnObject.order + ';'; } } //調整順序跟隱藏的css style_text += '.list-' + hashCode + ' .kmi-list__column.' + column_class + ',.list-' + hashCode + ' .kmi-list__column-split.' + column_class + '{' + cssText + '}'; }); var content_style = '.list-' + hashCode + ' .kmiScrollbar-content' + ',.list-' + hashCode + ' .kmi-list__row-content' + ',.list-' + hashCode + ' .kmi-list__header'; //非行動裝置才有需要設定大小 if (content_width != 0) { content_style += '{min-width:' + content_width + 'px !important;} '; } else { content_style += '{} '; } $(sheetTemplate).prependTo(element).html(content_style + style_text);//將該list 所屬的CSS放上去 } }; } return { restrict: 'C', priority: 999, scope: true, compile: compile }; }]); /* 2020/08/31 Grace 暫不使用 if (!window.cordova) { module.directive('kmiListColumn', ['$parse', '$mdDialog', '$filter', function ($parse, $mdDialog, $filter) { return { restrict: 'C', compile: function (tElem, tAttrs) { return { post: function ($scope, $elem, $attr) { $elem.bind('mouseover', function () { if ($attr.tooltip) { tooltip.html($attr.tooltip); tooltip.css('display', 'block'); tooltip.css('top', $(this).offset().top + 30 + 'px'); tooltip.css('left', $(this).offset().left + 'px'); } else if (this.scrollWidth > this.clientWidth || this.scrollHeight > this.clientHeight) { if (this.innerHTML.indexOf(''); var tooltip = angular.element(document.getElementById('kmi-tooltip')); tooltip.bind('mouseleave', function () { this.innerHTML = ''; this.style.display = 'none'; }); }*/ })(); (function () { 'use strict'; angular .module('material.components.toast', []) .provider('$mdlToast', function () { //level : warning/error this.$get = ['$timeout', '$animate', '$filter', function ($timeout, $animate, $filter) { var toastHTML = ''; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += ' report'; toastHTML += ' clear'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; toastHTML += '

'; toastHTML += '
'; toastHTML += '
'; toastHTML += '
'; angular.element(document.body).append(toastHTML); var kmiToast = angular.element(document.getElementById('kmi-toast')); var kmiToastMsg = angular.element(document.getElementById('toast-msg')); var kmiToastPanel = angular.element(document.getElementById('toast-panel')); var default_options = { delay: 5 }, hideToastTimer, isHideToast = true, hideEvent, //hideStact = true, hideToast = function ($event) { kmiToastMsg.html(''); kmiToastPanel.attr('class', '').attr('style', ''); kmiToast.attr('class', 'toast-hide tool-hide stack-hide'); document.getElementById('stack-trace').innerHTML = ''; isHideToast = true; if (hideEvent != undefined) hideEvent(); //20181005 add by Dustdusk for M#: toast 點擊後直接觸發後面的元件 if ($event) { try { var target = document.elementFromPoint($event.pageX, $event.pageY); target.focus(); target.click(); } catch (e) { //prevent mobile exception console.error(e); } } }; kmiToast[0].addEventListener('click', function ($event) { //if(hideStact) hideToast($event); }); /* document.addEventListener('keypress', function($event){ if(!isHideToast) hideToast($event); }); */ document.getElementById('error-info').addEventListener('click', function ($event) { $event.stopPropagation(); if (kmiToast.hasClass('stack-hide')) { kmiToast.removeClass('stack-hide'); //hideStact = false; } else { kmiToast.addClass('stack-hide'); //hideStact = true; } }); return { show: function (msg, options) { options = angular.extend(angular.extend({}, default_options), options); kmiToastMsg.html(msg); kmiToastPanel.attr('class', options.level);//warning/error if (options.error_detail != undefined) { kmiToast.removeClass('tool-hide'); document.getElementById('exception-info').innerHTML = $filter('translate')('error.service_msg', options.error_detail) document.getElementById('stack-trace').innerHTML = options.error_detail.StackTrace; } else { kmiToast.addClass('tool-hide'); } //position if (options.left != undefined) kmiToastPanel.css('left', options.left); if (options.top != undefined) { kmiToastPanel.css('top', options.top); kmiToastPanel.css('bottom', 'inherit'); } if (options.right != undefined) kmiToastPanel.css('right', options.right); if (options.bottom != undefined) kmiToastPanel.css('bottom', options.bottom); if (typeof (options.callback) == 'function') hideEvent = options.callback; else hideEvent = undefined; //Show Toast kmiToast.removeClass('toast-hide'); isHideToast = false; if (hideToastTimer) { $timeout.cancel(hideToastTimer); hideToastTimer = undefined; } if (options.delay == -1) { kmiToast.addClass('toast-tooltip'); } else if (options.delay > 0) { hideToastTimer = $timeout(hideToast, options.delay * 1000); } }, hide: hideToast, isHide: function () { return isHideToast; }, setDefault: function (options) { default_options = options; } }; }]; }) .directive('mdlToast', ['$mdlToast', function ($mdlToast) { return { restrict: 'A', compile: function (tElem, tAttrs) { return { post: function ($scope, $elem, $attr) { $elem.bind('mouseover', function () { if ($attr.mdlToast && $attr.mdlToast != '') { $mdlToast.show($attr.mdlToast, { delay: -1, left: $(this).offset().left + 'px', top: $(this).offset().top + 30 + 'px' }); } //$elem.parent().mouseover(); }); $elem.bind('mouseleave', function () { if ($attr.mdlToast && $attr.mdlToast != '') { $mdlToast.hide(); } //$elem.parent().mouseleave(); }); } }; } }; }]); angular .module('material.components.Marquee', []) .provider('$mdlMarquee', function () { this.$get = ['$timeout', function ($timeout) { var kmiMarquee = angular.element('
').appendTo(document.body), hideMarqueeTimer, hideMarquee = function () { kmiMarquee.html(''); kmiMarquee.attr('class', 'kmi-marquee marquee-hide'); }; return { show: function (msg, options) { if (hideMarqueeTimer) { $timeout.cancel(hideMarqueeTimer); hideMarqueeTimer = undefined; } var second = 15 + msg.length / 25 * 2; kmiMarquee.html('
' + msg + '
'); //Show Toast kmiMarquee.addClass(options.level); kmiMarquee.removeClass('marquee-hide'); hideMarqueeTimer = $timeout(hideMarquee, options.delay * 1000); }, hide: hideMarquee }; }]; }); })(); })(window, window.angular, moment, d3, sortablejs);