// console workaround /* if (!console) { var console = function() { this.log = function(msg) { // } } } */ function toObject(arr) { var rv = {}; for (var i = 0; i < arr.length; ++i) if (arr[i] !== undefined) rv[i] = arr[i]; return rv; } function SystemCore() { } /** elements = { "img#x123":"http://path-spre-imagine.com/img.jpg", "img#x345":"http://path-spre-alta-imagine.com/img.jpg" }; */ SystemCore.lazyLoad = function(elements) { // } SystemCore.randomColor = function(_alpha) { _alpha = _alpha ? _alpha : 1; var r = SystemCore.random(255); var g = SystemCore.random(255); var b = SystemCore.random(255); return 'rgba(' + r + ',' + g + ',' + b + ', ' + _alpha + ')'; } SystemCore.monthNames = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]; SystemCore.getMonthName = function(month) { if (!month || month.length < 1) { return ""; } month = parseInt(month) - 1; return SystemCore.monthNames[month]; } SystemCore.getNicerDate = function(date, displayHoursMinutes) { if (!date || date.length < 1) { return ""; } if (date.indexOf("T") > -1) { date = date.split("T").join(" "); } var tmpExpld = date.split(" "); var yearMonthDay = tmpExpld[0].split("-"); var hourMinutes = tmpExpld[1].split(":"); var year = yearMonthDay[0]; var month = SystemCore.getMonthName(yearMonthDay[1]); var day = yearMonthDay[2]; var hour = hourMinutes[0]; var minute = hourMinutes[1]; return day+" "+month+" "+year+(displayHoursMinutes ? (" - "+hour+":"+minute) : ""); } SystemCore.generatePassword = function(length) { if (!length || length < 1) { length = 8; } var charset = "abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", retVal = ""; for (var i = 0, n = charset.length; i < length; ++i) { retVal += charset.charAt(Math.floor(Math.random() * n)); } return retVal; } SystemCore.addGlobalItem = function(key, object) { if (!SystemCore.globalItems) { SystemCore.globalItems = {}; } SystemCore.globalItems[key] = object; } SystemCore.getGlobalItem = function(key, object) { return SystemCore.globalItems ? SystemCore.globalItems[key] : null; } SystemCore.isOnline = function(handler) { if (MobileInterface.exists()) { var isOnline = MobileInterface.call("System", "isOnline", [], handler); } else { // return true; // not working on mobile... if (!navigator) { handler(true); return; } var online = navigator.onLine; handler(true); //online; } } SystemCore.setLocal = function(key, object) { if(!localStorage) { return false; } localStorage[key] = JSON.stringify(object); localStorage[key + "_date"] = SystemCore.now(true); return true; } SystemCore.getLocalDate = function(key) { if(!localStorage) { return false; } return localStorage[key + "_date"]; } SystemCore.getLocal = function(key) { if(!localStorage) { return false; } if(localStorage[key]) { return JSON.parse(localStorage[key]); } return false; } SystemCore.friendlyName = function( str, replacer_,range_) { var range = range_ ? range_ : "abcdefghijklmnopqrstuvwxyz0123456789_"; var replacer = replacer_ ? replacer_ : '_'; var tmpRange = range; var tmpStr = ''; var consecutive = false; for (i=0; i"; } SystemCore.TITAN_GATEWAY = "http://www.klaus-union.ro/galileo/Application ERP2/jqueryGateway.php"; /** * headerFields has name/value: name for header and value for fieldKey(in collection) */ SystemCore.isNumber = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); } SystemCore.measureTextWidth = function(str, style) { var rnd = parseInt(Math.random() * 100000); $("body").append(""+str+""); if (style) { for (var key in style) { if (key == "width" || key == "min-width") continue; $(".dummyContainerForTextMeasurement"+rnd).css(key, style[key]); } } var width = $(".dummyContainerForTextMeasurement"+rnd).width(); if ($(".dummyContainerForTextMeasurement"+rnd)) { $(".dummyContainerForTextMeasurement"+rnd).remove(); } return width; } SystemCore.csvToExcel = function(columns, headerLabels, collection, fileName) { SystemRequest.load("CSV","csvToExcel",[columns, headerLabels, collection, fileName], function(response){ document.location = SystemCore.MODULES_GATEWAY + "?module=CSV&method=downloadExcel¶ms="+response.data.toString()+","+fileName; }); } SystemCore.createCSV = function(headerFields,rows) { var csv = ""; var fldKey; for(var key in headerFields) { csv += '"'+headerFields[key]['name']+'",'; } csv += "\r\n"; for(var i in rows) { for(var key in headerFields) { fldKey = headerFields[key]['value']; if (rows[i][fldKey]) { rows[i][fldKey] = (rows[i][fldKey]).toString().split('"').join("'"); } else { rows[i][fldKey] = ""; } csv += '"'+rows[i][fldKey]+'",'; } csv += "\r\n"; } return csv; } SystemCore.getObjectLength = function(obj) { var size = 0; var key = null; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; } SystemCore.geoMeasure = function(lat1, lon1, lat2, lon2) { var R = 6378.137; // Radius of earth in KM var dLat = (lat2 - lat1) * Math.PI / 180; var dLon = (lon2 - lon1) * Math.PI / 180; var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c; return d * 1000; // meters } SystemCore.currentLocation; SystemCore.getCurrentLocation = function(handler, errorHandler) { if (navigator.geolocation) { // console.log(navigator.geolocation) navigator.geolocation.getCurrentPosition(function(position){ SystemCore.currentLocation = [position.coords.latitude.toString(), position.coords.longitude.toString()]; SystemCore.oldLocation = SystemCore.currentLocation; // folosit pentru verificare deplasare handler(SystemCore.currentLocation); }, errorHandler, {enableHighAccuracy: true}); } } SystemCore.oldLocation; SystemCore.minimMeters = 0; SystemCore.positionWatcherId; SystemCore.locationChanged = function(handler, minMeters, errorLocation, extraParams) { if (!handler) { navigator.geolocation.clearWatch(SystemCore.positionWatcherId); return; } SystemCore.minimMeters = minMeters; SystemCore.positionWatcherId = navigator.geolocation.watchPosition(function(position){ SystemCore.currentLocation = [position.coords.latitude.toString(), position.coords.longitude.toString()]; console.log(SystemCore.currentLocation); // dispatch difference only when current location > minMeters handler(SystemCore.currentLocation, locDif); return; var locDif = SystemCore.getLocationDifference(); if(locDif > SystemCore.minimMeters) { SystemCore.oldLocation = SystemCore.currentLocation; handler(SystemCore.currentLocation, locDif); //console.log("Locatie schimbata .. diferenta >>>> " + SystemCore.minimMeters); } //else { //console.log("Locatie neschimbata .. diferenta <= " + SystemCore.minimMeters); } },errorLocation , extraParams); } SystemCore.getLocationDifference = function() { // SystemCore.currentLocation vs SystemCore.oldLocation return SystemCore.geoMeasure(SystemCore.currentLocation[0], SystemCore.currentLocation[1], SystemCore.oldLocation[0], SystemCore.oldLocation[1]); } /* * remove event from jqelement */ SystemCore.off = function(jqelement, handler, type) { type = type === undefined ? "click" : type; try { if (handler !== undefined) { $(jqelement).die(type, handler); } else { $(jqelement).die(type); } }catch(err){} } SystemCore.onClick = function(jqelement, handler, type) { type = !type ? "click" : type; try { $(jqelement).die(type); }catch(err){} $(jqelement).live(type, handler) } SystemCore.renderTemplate = function(element, templateCode, data) { var tplid = "tpl_" + SystemCore.random(100,10000) + "_" + SystemCore.random(100,10000); $.template( tplid, templateCode ); $.tmpl( tplid, data ).appendTo( element ); } SystemCore.markKeywordInContent = function(content, searchTexts) { var lastPos = 0; var searchTextLen = 0; if (!searchTexts || searchTexts.length < 1) { return content; } var span = ""; var searchText = null; for (var i=0;i 0) { span = ''+searchText+''; content = content.replace(new RegExp(searchText+'(?!([^<]+)?>)','gi'), span); } } return content; } SystemCore.getIdsFromCollection = function(collection, idField) { idField = idField ? idField : "id"; if (collection && collection.length > 0) { var i = 0; var ids = []; for (i=0;i 0) { var i = 0; for (i=0;i 0) { var i = 0; for (i=0;i 0) { var first = value[0]; var j = 0; if (first.hasOwnProperty("name")) { self.children().remove(); for (j=0;j'+value[j]['name']+''); selfChanged = true; } } } else { self.val(value); selfChanged = true; } break; case 'file': self.attr("value",""); break; case 'checkbox': if (value === true || parseInt(value) > 0) { self.attr("checked","checked"); } else { self.removeAttr("checked"); } break; case 'radio': if (self.attr("value") == value && value && value.length > 0) { if ((parseInt(value) > 0) || (value && value.length > 0)) { self.attr("checked","checked"); } else { self.removeAttr("checked"); } selfChanged = true; } break; case 'hidden': self.val(value); selfChanged = true; if ($("div#container_"+self.attr("id"))[0]) { var gmapValue = value.replace("(", "").replace(")","").split(","); var latLng = new google.maps.LatLng(parseFloat(gmapValue[0]), parseFloat(gmapValue[1])); window["map_"+self.attr("id")].setZoom(parseInt(gmapValue[2])); window["map_"+self.attr("id")].panTo(latLng); if (window["mrkmap_"+self.attr("id")]) { window["mrkmap_"+self.attr("id")].setMap(null); } window["mrkmap_"+self.attr("id")] = new google.maps.Marker({ position: latLng, map: window["map_"+self.attr("id")] }); } break; case 'textarea': try { if (self.hasClass("richText")) { for (var edId in tinymce.editors) { if (tinymce.editors[edId].editorId == self.attr("id")) { tinymce.editors[edId].setContent(value); break; } } }// nu traba` break } catch(e) { } default: self.val(value); selfChanged = true; break; } } if (selfChanged && triggerChange !== false) { self.trigger("keyup"); self.trigger("change"); } } } if (completeHandler != undefined) { completeHandler(); } } function fillFormWithArray_bckp(form, data, completeHandler) { var frmElements = $(form)[0].elements; $.each(data, function(key, value){ for (var i=0;i 0) { var first = value[0]; var j = 0; if (first.hasOwnProperty("name")) { self.children().remove(); for (j=0;j'+value[j]['name']+''); } } } else { self.val(value); } break; case 'file': /* nu trebuie setat */ break; case 'checkbox': case 'radio': if (self.attr("value") == value && value && value.length > 0) { self.attr("checked",(parseInt(value) > 0 || (value && value.length > 0) ? "checked" : null)); } break; default: self.val(value); break; } } self.trigger("keyup"); self.trigger("change"); } }); if (completeHandler != undefined) { completeHandler(); } } function ColorUtils() { } ColorUtils.getFontColorForBackground = function(bgHex) { if (bgHex.indexOf('#') === 0) { bgHex = bgHex.substr(1,10); } res = parseInt(bgHex, 16); if (res < 7368816) { color = "#ffffff"; } else { color = "#000000"; } return color; } /** * Get instances as containers */ SystemCore.instances = {}; SystemCore.getInstances = function() { var rez = $("div[id^=inst_]"); var key = ''; var obj; for(var i=0; i 0 ? parseInt(number) : 10000; return parseInt(Math.random() * number); } SystemCore.registerToggleElement = function() { // TODO -- cipri, mai ai de lucru aici // o sa foloseasca la toggle state-uri pe public ... } SystemCore.removeUserInfo = function() { SystemCore.permissions = []; SystemCore.user = undefined; } SystemCore.getUserInfo = function(handler) { SystemRequest.load("Users","getUserInfo",[{x:0}], function(resp){ if(resp.success) { SystemCore.permissions = resp.data.permissions; SystemCore.user = resp.data.user; } else { SystemCore.removeUserInfo(); } if (handler) { handler(SystemCore.user, SystemCore.permissions); } }); } SystemCore.permissions = {}; SystemCore.getPermissions = function(handler) { SystemRequest.load("Users","getCurrentUserPermissions",[], function(response){ SystemCore.permissions = response.data ? response.data : []; if (handler) { handler(); } }); } SystemCore.hasPermission = function(permission,module) { var len = SystemCore.permissions.length; for(var i in SystemCore.permissions) { if (SystemCore.permissions[i].name == "coreAdministrator") { return true; } if (SystemCore.permissions[i].module == module && (permission==null || SystemCore.permissions[i].name == permission)) { return true; } } return false; } SystemCore.login = function(e,p,handler) { SystemCore.removeUserInfo(); SystemRequest.load("Users","login",[e,p], handler); } SystemCore.logout = function(handler) { SystemCore.removeUserInfo(); SystemRequest.load("Users","logout",[], handler); } SystemCore.getLoginForm = function(loginHandler,loginLabel, cancelLabel, title,description) { var loginForm; title = title ? title : ""; description = description ? description : ""; loginLabel = loginLabel ? loginLabel : "Login"; cancelLabel = cancelLabel ? cancelLabel : ""; loginForm = new UIForm("",{formId:"_coreLoginForm_", title:title, description:description}); var formObj = UIForm.createCustomForm("_coreLoginFormObj_", loginLabel,cancelLabel); UIForm.addField(formObj, "email", "Email", "email", "", true,{}); UIForm.addField(formObj, "password", "Pasword", "password", "", true,{}); loginForm.load(null, formObj); loginForm.onSave(function(){ var fData = loginForm.getData(); SystemCore.login(fData.email, fData.password, loginHandler); }); return loginForm; } SystemCore.getLoginFormJS = function(loginHandler,loginLabel, cancelLabel, title,description) { var loginForm; title = title ? title : ""; description = description ? description : ""; loginLabel = loginLabel ? loginLabel : "Login"; cancelLabel = cancelLabel ? cancelLabel : ""; loginForm = new UIFormJS("_coreLoginForm_", loginLabel,cancelLabel,{title:title, description:description}); loginForm.addField("email", "Email", "email", "", true,{}); loginForm.addField("password", "Pasword", "password", "", true,{}); loginForm.load(); loginForm.onLoad(function(){ loginForm.onSave(function(){ var fData = loginForm.getData(); SystemCore.login(fData.email, fData.password, loginHandler); }); }) return loginForm; } SystemCore.createUIApplication = function(appName, container, appCssClass) { var _app = new UIApplication({name:appName, id:appName+"Id", container:container, appCssClass:appCssClass}); // var _wrapper = _app.wrapper; _app.render(); _wrapper.dispatchResize(); return _app; } Event = function(type, data, currentTarget) { this.type = type; this.currentTarget = currentTarget; this.data = data; this.defaultPrevented = false; this.isDefaultPrevented = function() { this.defaultPrevented = true; } this.preventDefault = function() { this.defaultPrevented = true; } } Event.CHANGE = "change"; Event.CHANGING = "changing"; $(document).ready(function(){ SystemCore.getInstances(); }); SystemCore.listeners = {}; /** * Obiectele care sunt adaugate ca si eventListener trebuie sa aiba * o metoda publica liste(event), unde event are: target(dispatcher),type(string) si data(Object) */ /** * dispatcher -- e optional (daca nu se specifica trebuie tratat in handlerii din listeneri) */ SystemCore.addEventListener = function(listenerObjOrFunct,type,dispather) { if (!SystemCore.listeners[type]) { SystemCore.listeners[type] = []; } SystemCore.listeners[type].push( {object:listenerObjOrFunct,type:type,dispatcher:dispather} ); } SystemCore.removeAllEvents = function(params, type) { if (SystemCore.listeners[type]) { SystemCore.listeners[type] = undefined; } } /** * Remove event listener */ SystemCore.removeEventListener = function(object,type,dispatcher) { if (SystemCore.listeners[type]) { // TODO -- nu am rezolvat sa stearga in context - ci pe type doar //SystemCore.listeners[type] = undefined; //return; for (var i=0; i'; this.tpl; this.activePage = 0; this.tpl = $.template(this.templateName,this.tplWrapper); this.setTotal = function(total,perPage) { this.total = total; this.perPage = perPage ? perPage : 30; this.totalPages = Math.ceil(this.total / this.perPage); } this.clearTemplate = function() { $(this.container).empty(); } this.render = function(activePage) { // tplPaginationPlaceHolder if (!this.tpl) { this.tpl = $.template(this.templateName,this.tplRow); } var pages = []; this.activePage = activePage>=0 ? activePage : 0; var obj = {}; for(var i=0; i'); if (jQuery.browser && jQuery.browser.msie && jQuery.browser.version < 9.0) // muIE 6,7,8 { var containerId = $(this.container).attr("id"); var objBody = document.getElementById(containerId); iframe = document.createElement(''); } } this.registerField = function(name,servicePath,params,encodeToJSON) { var paramsStr = params.join(","); var fieldStr = ''; fieldStr += ''; fieldStr += ''; fieldStr += ''; fieldStr += ''; $(this.container).append(fieldStr); } this.setParams = function(fieldName,params) { var paramsStr = params.join(","); $(this.container + " [name="+fieldName+"Params]").val(paramsStr); } } /** * Service Locator - generated by SystemManager (cipri) */ SystemCore.getModuleService = function(moduleName, handler) { Loader.getScripts([SystemCore.MODULES_PATH + moduleName + "/js/services/"+moduleName+"JSService.js"], function(){ if (handler) { handler( window[moduleName+"JSService"] ); } }); } /** * Load an array of .js and execute the callback function * When all scripts 100% loaded * * @return */ function Includes() { } Includes.scriptStack = {} Includes.loadedCounter = 0; Includes.len = 0; //Includes.handler; Includes.load = function(scripts, handler, errorHandler, forceLoading) { Includes.len = scripts.length; Includes.handler = handler; var scripts = scripts; var concatChar = "?"; Includes.loadedCounter = 0; for (var i=0; i'; $("body").append(wrapper); $("body .PopupUtilsMenu").append(content); PopupUtils.currentPopupMenu = $("body .PopupUtilsMenu"); } /** * PRELOAD EXTENDED CLASSES */ Loader.getScripts([ SystemCore.BASE_URL + "js/core/eobCoreDragDrop.js", SystemCore.BASE_URL + "js/core/eobCoreResize.js" // SystemCore.BASE_URL + "js/core/MobileInterface.js" ], function(){ // extended classes loaded })