(function(global){ global.assert = function(condition, message) { if (!condition) { message = message || "Assertion failed"; if (typeof Error !== "undefined") { throw new Error(message); } throw message; // Fallback } } global.defaultize = function(invadors, defaults, test){ var target = {}; for( var key in defaults ){ if( invadors == undefined || invadors[key] == undefined ){ target[key] = defaults[key]; }else{ target[key] = invadors[key]; } } for( var key in invadors ){ if( target[key] == undefined && invadors[key] != undefined ){ target[key] = invadors[key]; } } return target; } global.operator = function(alias){ //check passed param if( //check if key is passed alias == undefined ){ //dont return any operator return ""; }else{ //link passed key var thisKey = alias; if( //check if open ends is requested thisKey == "<>" ){ //return open ends return "*"; }else if( //check if starting end is requested thisKey == "<" ){ //return starting end return "$"; }else if( //check if closing end is requested thisKey == ">" ){ //return closing end return "|"; }else{ //dont return any operator as default return ""; } } } global.breakParam = function(string){ var type = string.split("(")[0]; var backing = string.split("(")[1]; if( backing != undefined ){ backing = backing.replace(")", ""); backing = backing.split(","); }else{ backing = []; } var param = {}; if( backing.length > 0 ){ $.each(backing, function(index, backing){ if( backing.split(":")[1] != undefined ){ param[backing.split(":")[0]] = backing.split(":")[1]; }else{ param[index] = backing; } }); } return { type : type, param : param }; } global.handleMessages = function(functionParam){ var result = false; var thisParam = defaultize(functionParam, { response : undefined, assessment : undefined, config : undefined }); thisParam.assessment.content.clear({}); if( thisParam.response != undefined && thisParam.assessment != undefined ){ if( thisParam.response.assessment != undefined ){ $.each(thisParam.response.assessment, function(index, message){ if( message.type != undefined && message.code != undefined && thisParam.config != undefined && thisParam.config[message.type] != undefined && thisParam.config[message.type] == true ){ thisParam.assessment.content.add({ exception : message.code, section : message.type, data : { config : message } }); result = true; } }); } } return result; } global.find = function(selecter, list){ for( var i in list ){ var crit = ""; var thisList = list[i]; for( var n in thisList ){ var thisCrit = thisList[n]; crit += "["; if( thisCrit.key != undefined ){ crit += thisCrit.key; } if( thisCrit.key != undefined && thisCrit.value != undefined ){ crit += "=" + operator(thisCrit.operator) + "\"" + thisCrit.value + "\""; } crit += "]"; } while( crit.indexOf("[]") >= 0 ){ crit = crit.replace("[]",""); } if( crit.length > 0 ){ selecter = $(selecter).has(crit); }else{ selecter = $(selecter); } } return $(selecter); }; }(window)); (function(global){ var objectName = "Surfable"; var Class = function(){ var classObject = this; return classObject; } Class.prototype.log = []; global[objectName] = new Class; }(window)); (function(global){ var objectName = "Surfable"; var className = "Constraint"; var Class = function(methodParam){ } global[objectName][className] = Class; }(window)); (function(global){ var objectName = "Surfable"; var className = "Property"; var Class = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, {}); for( var key in thisParam ){ if( classObject.isProto(key) == false ){ classObject.set({ key : key, value : thisParam[key] }); } } return classObject; } Class.prototype.prepair = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { key : undefined, }); if( thisParam.key == undefined ){ Surfable.log.push("object("+className+") method(sub) key(value) issue(missing)"); return false; }else{ if( classObject[thisParam.key] == undefined ){ classObject[thisParam.key] = new Surfable.Property; } return classObject[thisParam.key]; } } Class.prototype.set = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { key : undefined, value : undefined }); if( thisParam.value == undefined ){ Surfable.log.push("object("+className+") method(set) key(value) issue(missing)"); return false; }else{ var key; if( thisParam.key == undefined ){ key = classObject.key(); }else{ key = thisParam.key; } classObject[key] = thisParam.value; return key; } } Class.prototype.get = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { key : undefined }); if( thisParam.key == undefined ){ return classObject; }else if( thisParam.key != undefined && classObject[thisParam.key] == undefined ){ Surfable.log.push("object("+objectName+") method(get) key(key) value("+thisParam.key+") issue(unknown)"); return false; }else{ var result = {}; result[thisParam.key] = classObject[thisParam.key]; return result; } } Class.prototype.key = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { key : undefined }); var thisKey; if( thisParam.key == undefined ){ var i = 0; while( classObject[i] != undefined ){ i++ } thisKey = i; }else{ thisKey = thisParam.key; } if( classObject != undefined && classObject[thisKey] == undefined ){ return thisKey; }else{ Surfable.log.push("object("+className+") method(key) key(thisKey) issue(ambigious)"); return false; } } Class.prototype.list = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { }); var array = []; $.each(classObject, function(key, object){ if( classObject.isProto(key) == false ){ array.push(object); } }); return array; } Class.prototype.object = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { }); var array = {}; $.each(classObject, function(key, object){ if( classObject.isProto(key) == false ){ array[key] = object; } }); return array; } Class.prototype.apply = function(methodParam){ var classObject = this; var array = {}; for( var key in classObject ){ if( classObject.isProto(key) == false ){ if( classObject != undefined && classObject[key] != undefined ){ if( typeof classObject[key] == "object" && classObject[key].apply != undefined && typeof classObject[key].apply == "function" ){ array[key] = classObject[key].apply(methodParam); }else if( typeof classObject[key] == "function" ){ array[key] = classObject[key](methodParam); } } } } return array; } Class.prototype.find = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, {}); return _.where(classObject, thisParam); } Class.prototype.isProto = function(key){ var classObject = this; if( classObject.__proto__[key] == undefined ){ return false; }else{ return true; } } global[objectName][className] = Class; }(window)); (function(global){ var getCookie = function(name) { var cookies = document.cookie.split(';'); for(var i=0 ; i < cookies.length ; ++i) { var pair = cookies[i].trim().split('='); if(pair[0] == name) return pair[1]; } return null; }; var objectName = "Surfable"; var className = "API"; var utilityIssueList = ["tokenize"]; var momentIssueList = ["before", "error", "success", "timeout", "complete"]; var done = []; var Class = function(methodParam){ var classObject = this; var thisConfig = defaultize(methodParam, { url : undefined, async : true, cache : false, type : "post", dataType : "json", auth : { account : undefined, secret : undefined, group : undefined, }, }); classObject.state = { setup : false, }; classObject.ready = false; watch(classObject, "ready", function(arg){ if( classObject.ready == true ){ $.each(classObject.que.object(), function(key, call){ if( call != undefined ){ classObject.clearCallback({}); classObject.call(call); delete classObject.que[key]; } }); } }); classObject.config = new Surfable.Property(thisConfig); classObject.property = new Surfable.Property({}); classObject.que = new Surfable.Property({}); classObject.initCallback({}); return classObject; } Class.prototype.config = new Surfable.Property({}); Class.prototype.property = new Surfable.Property({}); Class.prototype.callback = new Surfable.Property({}); Class.prototype.applyCallback = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { moment : undefined, callback : classObject.callback, data : undefined, }); if( thisParam.moment != undefined ){ if( thisParam.callback != undefined && thisParam.callback[thisParam.moment] != undefined ){ $.each(thisParam.callback[thisParam.moment], function(key, callbackObject){ if( thisParam.callback[thisParam.moment].isProto(key) == false ){ callbackObject(thisParam.data); } }); } } return true; } Class.prototype.clearCallback = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { // }); classObject.callback = new Surfable.Property(thisParam); $.each(momentIssueList, function(key, moment){ classObject.callback.prepair({ key : moment, }); }); return true; } Class.prototype.initCallback = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { // }); classObject.clearCallback(thisParam); } Class.prototype.mergeCallback = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { callback : {}, }); $.each(momentIssueList, function(issueKey, issue){ if( thisParam.callback[issue] != undefined && classObject.callback[issue] != undefined ){ $.each(thisParam.callback[issue], function(callbackKey, callback){ if( classObject.callback[issue].get()[callbackKey] == undefined ){ classObject.callback[issue].set({ key : callbackKey, value : callback }); }else{ classObject.callback[issue].set({ value : callback }); } }); } }); return classObject.callback; } Class.prototype.checkQue = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { command : undefined, }); if( classObject.ready == false && utilityIssueList.indexOf(thisParam.command) < 0 ){ return false; }else{ return true; } } Class.prototype.addQue = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { param : undefined, }); classObject.que.set({ value: thisParam.param }); } Class.prototype.setup = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { command : "tokenize", callback : undefined }); classObject.initCallback({}); classObject.call(thisParam); return true; } Class.prototype.call = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { token : undefined, session : getCookie("PHPSESSID"), command : undefined, auth : undefined, body : {}, config : classObject.config.object(), callback : {}, }); if( classObject.checkQue({ command : thisParam.command }) == false ){ classObject.addQue({ param : thisParam }); return false; } classObject.callback.before.set({ key : "activateQueing", value : function(arg){ classObject.ready = false; } }); classObject.callback.complete.set({ key : "disableQueing", value : function(arg){ classObject.ready = true; } }); classObject.callback.success.set({ key : "applyUtility", value : function(arg){ if( arg != undefined && arg.response != undefined && arg.response.header != undefined ){ var issues = ["session", "token"]; $.each(issues, function(key, issue){ if( arg.response.header[issue] != undefined ){ classObject.property.set({ key : issue, value : arg.response.header[issue] }); } }); } } }); thisParam.callback = classObject.mergeCallback({ callback : thisParam.callback }); var thisHeader = defaultize({ command : thisParam.command, auth : thisParam.auth, }, { token : classObject.property.get().token, session : classObject.property.get().session, command : undefined, auth : thisParam.config.auth, session : thisParam.session, }); var serviceParam = { url: thisParam.config.url, async: thisParam.config.async, cache: thisParam.config.cache, type: thisParam.config.type, dataType: thisParam.config.dataType, data: { header : thisHeader, body : thisParam.body }, beforeSend: function(data){ classObject.property.set({ key : "processing", callback : thisParam.callback, value : true }); classObject.applyCallback({ moment : "before", callback : thisParam.callback, data : data, }); }, error: function (data){ classObject.applyCallback({ moment : "error", callback : thisParam.callback, data : data, }); }, success: function(data){ classObject.applyCallback({ moment : "success", callback : thisParam.callback, data : data, }); }, complete: function(data){ classObject.property.set({ key : "processing", callback : thisParam.callback, value : false }); classObject.applyCallback({ moment : "complete", callback : thisParam.callback, data : data, }); } }; jQuery.ajax(serviceParam); } global[objectName][className] = Class; }(window)); (function(global){ var objectName = "Surfable"; var className = "Event"; var Class = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { }); classObject.property = new Surfable.Property(thisParam); classObject.onTrigger = new Surfable.Property; classObject.onReady = new Surfable.Property; return classObject; } Class.prototype.add = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { trigger : undefined, onTrigger : undefined, onReady : undefined, key : undefined }); if( thisParam.trigger == undefined ){ Surfable.log.push("object("+className+") method(add) key(trigger) issue(missing)"); return false; }else{ if( typeof thisParam.trigger == "string" ){ var add = function(type, fnc){ if( classObject[type].get({ key : thisParam.trigger }) == false ){ classObject[type].prepair({ key : thisParam.trigger }); } classObject[type].get({ key : thisParam.trigger })[thisParam.trigger].set({ value : fnc, key : thisParam.key, }); } add("onTrigger", thisParam.onTrigger); add("onReady", thisParam.onReady); }else{ for( var key = 0; key < thisParam.trigger.length; key ++ ){ classObject.add({ trigger : thisParam.trigger[key], onTrigger : thisParam.onTrigger, onReady : thisParam.onReady, key : thisParam.key, }); } } } } Class.prototype.deploy = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { element : undefined }); if( thisParam.element == undefined ){ Surfable.log.push("object("+className+") method(deploy) key(element) issue(missing)"); return false; }else{ var onTriggerEventList = classObject.onTrigger.get(); var onReadyEventList = classObject.onReady.get(); for( var key in onTriggerEventList ){ if( onTriggerEventList.__proto__[key] == undefined ){ (function(key){ var apply = function(index, element){ if( typeof classObject[index][key].apply == "function" ){ if( element.element.length == undefined ){ element.element = $(element.element); } if( element.e != undefined ){ element.element.e = element.e; } classObject[index][key].apply(element.element); } } $(thisParam.element)/*.off(key)*/.on(key, function(e){ apply("onTrigger", {element:this, e:e}); }).ready(function(){ apply("onReady", {element:thisParam.element}); }); }(key)); } } return true; } } global[objectName][className] = Class; }(window));(function(global){ var objectName = "Surfable"; var className = "Object"; var Class = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { objectAttribute : "data-cinc-object", objectElement : undefined, paramNameAttr : "name", paramValueAttr : "value", multipleList : [], interfaceObject : {}, }); classObject.property = new Surfable.Property(thisParam); classObject.repository = new Surfable.Property; classObject.multiple = new Surfable.Property; $.each(thisParam.multipleList, function(key, value){ classObject.multiple.set({ key : value, value : true, }); }); classObject.deploy({ element : thisParam.objectElement }); return classObject; } Class.prototype.deploy = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { element : undefined }); //aggregate relevant element(list) var thisElement; if( thisParam.element == undefined ){ thisElement = "[" + classObject.property.get({}).objectAttribute + "]"; }else{ thisElement = thisParam.element; } //define bind method for changes function bind(thisArray){ watch(thisArray, [classObject.property.get({}).paramValueAttr], function(prop, action, difference, oldvalue){ var value; if( typeof thisArray.value == "string" ){ value = thisArray.value; }else{ value = thisArray.value.join(" "); } if( typeof value == "string" ){ $(thisArray.element).attr(classObject.property.get({}).paramValueAttr, value); } }); $(thisArray.element).off("change").on("change", function(){ var value = thisArray.value = $(thisArray.element).attr(classObject.property.get({}).paramValueAttr); var entity = $(thisArray.parent.element).attr(classObject.property.get({}).objectAttribute); if( classObject.property && classObject.property.get({}).interfaceObject && classObject.property.get({}).interfaceObject[entity] != undefined && classObject.property.get({}).interfaceObject[entity].attachment != undefined && classObject.property.get({}).interfaceObject[entity].attachment.gateway != undefined && classObject.property.get({}).interfaceObject[entity].attachment.gateway.element != undefined && $(classObject.property.get({}).interfaceObject[entity].attachment.gateway.element).val() != value ){ $(classObject.property.get({}).interfaceObject[entity].attachment.gateway.element).trigger("sync"); } }); } //define method how to extract data drom dom-objects na how to build js-object function extract(selecter, param, parent){ var array = new Surfable.Property; var elementList = $(selecter); for( var childKey = 0; childKey < elementList.length; childKey ++ ){ var childElement = elementList[childKey]; var elementName; if( param == true ){ elementName = $(childElement).attr(classObject.property.get({}).paramNameAttr); }else{ elementName = $(childElement).attr(classObject.property.get({}).objectAttribute); if( $(childElement).find("[" + classObject.property.get({}).paramNameAttr + "=\"entity\"]").length == 0 ){ var entityParam = new Surfable.Component; entityParam.template.set({ key : "param", status : "ready", template : "" }); entityParam.deploy({ parent : childElement, property : { value : elementName } }); } } var elementValue; var endpoint; var thisArray = { element : $(childElement), event : new Surfable.Property }; if( typeof parent == "object" ){ thisArray.parent = parent; } if( $(childElement).children().length == 0 ){ elementValue = $(childElement).attr(classObject.property.get({}).paramValueAttr); if( classObject.multiple.get({ key : elementName })[elementName] == true ){ elementValueParts = elementValue.split(" "); elementValue = new Surfable.Property(); for( var i = 0; i < elementValueParts.length; i++ ){ elementValue.set({ value : elementValueParts[i] }); } } endpoint = true; }else{ elementValue = extract($(childElement).children(), true, thisArray); endpoint = false; } thisArray.value = elementValue; array.set({ key : elementName, value : thisArray }); if( endpoint == true ){ bind(thisArray); } } return array; } //execute var result = extract(thisElement); classObject.repository = new Surfable.Property(result); return extract; } Class.prototype.get = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { entity : undefined }); return classObject.repository.get({ key : thisParam.entity }); }; Class.prototype.add = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { property : { entity : undefined }, objectEventList : undefined, paramEventList : undefined, }); if( thisParam.property == undefined ){ Surfable.log.push("object("+className+") method(add) key(property) issue(missing)"); return false; }else if( thisParam.property.entity == undefined ){ Surfable.log.push("object("+className+") method(add) key(property.entity) issue(missing)"); return false; }else{ var objectStancil = new Surfable.Component; objectStancil.template.set({ key : "object", status : "ready", template : "" }); var newObject = objectStancil.deploy({ parent : "body", property : thisParam.property, eventList : thisParam.objectEventList }); $.each(thisParam.property, function(key, value){ if( key != "" ){ } var paramStancil = new Surfable.Component; paramStancil.template.set({ key : "param", status : "ready", template : "" }); var newParam = paramStancil.deploy({ parent : newObject, property : { name : key, value : value }, eventList : thisParam.paramEventList }); }); return $(newObject); } } Class.prototype.find = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, []); return find($("[" + classObject.property.get({}).objectAttribute + "]"), thisParam); } global[objectName][className] = Class; }(window));(function(global){ var objectName = "Surfable"; var className = "Template"; var Class = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { }); classObject.property = new Surfable.Property(thisParam); classObject.repository = new Surfable.Property({}); return classObject; } Class.prototype.set = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { key : undefined, status : "failed", template : "" }); classObject.repository.set({ key : thisParam.key, value : { status : thisParam.status, template : thisParam.template, } }); } Class.prototype.load = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { url : undefined, key : undefined }); if( thisParam.url == undefined ){ Surfable.log.push("object("+className+") method(loadTemplate) key(template url) issue(missing)"); return false; }else{ if( thisParam.key == undefined ){ thisParam.key = classObject.repository.key({}); } $.ajax({ url: thisParam.url, type : "POST", beforeSend : function(){ classObject.repository.set({ key : thisParam.key, status : "initialized", template : "", }); }, error : function() { classObject.repository.set({ key : thisParam.key, status : "failed", template : "", }); }, success: function(template) { classObject.repository.set({ key : thisParam.key, status : "ready", template : template, }); }, complete : function(){ }, accepts : undefined, cache : undefined, contents : undefined, contentType : undefined, context : undefined, converters : undefined, crossDomain : undefined, data : undefined, dataFilter : undefined, dataType : undefined, global : undefined, headers : undefined, ifModified : undefined, isLocal : undefined, jsonp : undefined, jsonpCallback : undefined, method : undefined, mimeType : undefined, username : undefined, password : undefined, processData : undefined, scriptCharset : undefined, statusCode : undefined, timeout : undefined, traditional : undefined, xhrFields : undefined, async: true, }); return thisParam.key; } } Class.prototype.build = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { property: {}, key : undefined }); var templateList = classObject.repository.get({ key : thisParam.key }); var markup = ""; for( var key in templateList ){ var thisTemplate = templateList[key]; if( thisTemplate.template == undefined ){ Surfable.log.push("object("+className+") method(build) key(template "+key+") issue(empty)"); return false; }else{ if( thisTemplate.status == undefined || thisTemplate.status != "ready" ){ Surfable.log.push("object("+className+") method(build) key(status) issue(invalid)"); return false; }else{ return Mustache.render(thisTemplate.template, thisParam.property); } } } } global[objectName][className] = Class; }(window)); (function(global){ var objectName = "Surfable"; var className = "Component"; var Class = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { }); classObject.property = new Surfable.Property(thisParam); classObject.event = new Surfable.Event({}); classObject.template = new Surfable.Template({}); return classObject; } Class.prototype.deploy = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { parent : undefined, property : undefined, clone : { avoid : true, selecter : undefined, markup : undefined }, eventList : [] }); if( thisParam.property != undefined ){ $.each(thisParam.property, function(key, value){ classObject.property.set({ key : key, value : value, }); }); } if( thisParam.parent == undefined ){ Surfable.log.push("object("+className+") method(deploy) key(parent) issue(missing)"); return false; }else{ var thisParent = thisParam.parent; var thisMarkup = classObject.template.build({ property : classObject.property }); var replaceAll = function(search, replace, string){ while( string.indexOf(search) >= 0 ){ string = string.replace(search, replace); } return String(string); } thisMarkup = replaceAll("*]", ">", thisMarkup); thisMarkup = replaceAll("*[:", "", thisMarkup); thisMarkup = replaceAll("*[", "<", thisMarkup); thisMarkup = replaceAll("*#", "\"", thisMarkup); var thisElement = $(thisMarkup); var parentMarkup = $(thisParent).html(); var elementMarkup = $(thisElement).html(); if( thisParam.clone.avoid == true && ( parentMarkup.indexOf(elementMarkup) > 0 || parentMarkup.indexOf(thisParam.clone.markup) > 0 || thisMarkup == thisParam.clone.markup || $(thisParent).find(thisParam.clone.selecter).length > 0 ) ){ return false; }else{ thisElement = $(thisMarkup).appendTo(thisParent); thisElement.elementOriginal = thisElement; } if( thisParam.eventList != undefined ){ $.each(thisParam.eventList, function(index, event){ classObject.event.add(event); }); } classObject.event.deploy({ element : thisElement }); classObject.element = $(thisElement); return classObject.element; } } Class.prototype.clear = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { parent : undefined }); if( thisParam.parent == undefined ){ Surfable.log.push("object("+className+") method(method) key(parent) issue(missing)"); return false; }else{ $(thisParam.parent).html(""); return true; } } global[objectName][className] = Class; }(window)); // if object has no reflection/markuppointer dont proceed/or do proceed id service? //set object-param when data.* is set but element missing // still cant precess radiobuttons // custom dropdown items / list // delegate $("[data-cinc-option=\"" + data.entity + "\"]").trigger("check"); to gateway? // delegate $("[data-cinc-option=\"" + data.reference + "\"]").trigger("check").trigger("checkInterfaceConstraint"); check to gateway (function(global){ var objectName = "Surfable"; var className = "Dialog"; var language_message; if( global.language_message == undefined ){ language_message = function(code){ console.log("\"language_message\" is no valid method to pull exceptions in " + objectName + " Object " + className + "Class"); } }else{ language_message = global.language_message; } var Class = function(methodParam){ var classObject = this; classObject.init(methodParam); classObject.setup({}); return classObject; } Class.prototype.init = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { multipleList : ["someParamNameValue"], definitionAttr : "someElementAttribute", interfaceAttr : "someElementAttribute", objectElement : undefined, }); classObject.property = new Surfable.Property(thisParam); classObject.feature = new Surfable.Property; classObject.constraint = new Surfable.Property; classObject.status = { entity : {}, section : {}, }; classObject.defaultConstraint({}); classObject.interface = new Surfable.Property; } Class.prototype.setup = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { objectAttribute : classObject.property.get().objectAttribute, paramNameAttr : "name", paramValueAttr : "value", multipleList : classObject.property.get().multipleList, interfaceObject : classObject.property.get().interface, entity : undefined, }); classObject.definition = new Surfable.Object(thisParam); classObject.getDefinition(thisParam); classObject.stageInterface(thisParam); classObject.defineInterfaceDefault(thisParam); classObject.deployInterface(thisParam); }; Class.prototype.addFeature = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { name : undefined, feature : undefined }); if( thisParam.name == undefined ){ Surfable.log.push("object("+className+") method(addFeature) key(name) issue(missing)"); result = false; }else if( thisParam.feature == undefined ){ Surfable.log.push("object("+className+") method(addFeature) key(feature) issue(missing)"); result = false; }else if( classObject.feature == undefined || classObject.feature.get() == undefined || classObject.feature.get()[thisParam.feature] != undefined ){ Surfable.log.push("object("+className+") method(addFeature) key(invalid)"); result = false; }else{ classObject.feature.set({ key : thisParam.name, value : thisParam.feature }); result = true; } } Class.prototype.triggerFeature = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { name : undefined, argument : undefined }); if( thisParam.name == undefined ){ Surfable.log.push("object("+className+") method(triggerFeature) key(name) issue(missing)"); result = false; }else if( classObject.feature == undefined || classObject.feature.get() == undefined || classObject.feature.get()[thisParam.name] == undefined ){ Surfable.log.push("object("+className+") method(triggerFeature) key(invalid)"); result = false; }else{ result = classObject.feature.get()[thisParam.name](thisParam.argument); } return result; } Class.prototype.defaultConstraint = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, {}); var checkType = function(obj){ if( obj != undefined && obj.interface != undefined && obj.interface.attachment != undefined && obj.interface.attachment.assessment != undefined ){ return obj.interface.attachment.assessment; }else{ return false; } } var addMessage = function(functionParam){ var thisParam = defaultize(functionParam, { exception : undefined, section : undefined, obj : {}, data : {}, }); thisParam.data = thisParam.obj.config; var assessment = checkType(thisParam.obj); if( assessment != false ){ assessment.content.add(thisParam); } } var removeMessage = function(functionParam){ var thisParam = defaultize(functionParam, { exception : undefined, section : undefined, obj : {}, data : {}, }); thisParam.data = thisParam.obj.config; var assessment = checkType(thisParam.obj); if( assessment != false ){ assessment.content.remove(thisParam); } } //mandatory classObject.constraint.set({ key : "mandatory", value : function(obj){ var status = true; $.each(obj, function(type, value){ if( value == false ){ status = false; } }); if( status == false ){ addMessage({ obj : obj, section : "error", exception : "mandatory-unsatisfied", message : language_message("mandatory-unsatisfied"), data : {}, }); }else{ removeMessage({ obj : obj, section : "error", exception : "mandatory-unsatisfied", }); } return status; } }); //isset classObject.constraint.set({ key : "isset", value : function(obj){ var value = $(obj.element).val(); if( value == undefined || value == null || value == false || value == 0 || value.length == 0 || value == "nn" || value == "na" ){ addMessage({ obj : obj, section : "error", exception : "isset-unsatisfied", message : language_message("mandatory-unsatisfied"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "isset-unsatisfied", }); return true; } } }); //checkbox classObject.constraint.set({ key : "checkbox", value : function(obj){ var value = $(obj.element).val(); if( obj.config != undefined && obj.config.reference != undefined && value == obj.config.reference ){ removeMessage({ obj : obj, section : "error", exception : "checkbox-unsatisfied", data : {}, }); return true; }else{ addMessage({ obj : obj, section : "error", exception : "checkbox-unsatisfied", message : language_message("checkbox-unsatisfied"), data : {}, }); return false; } } }); //email classObject.constraint.set({ key : "email", value : function(obj){ var value = $(obj.element).val(); var pattern = new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); if( pattern.test(value) == false ){ addMessage({ obj : obj, section : "error", exception : "email-invalid", message : language_message("email-invalid"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "email-invalid", }); return true; } } }); //clear classObject.constraint.set({ key : "clear", value : function(obj){ if( obj.config.entity == undefined ){ addMessage({ obj : obj, section : "error", exception : "clear-param-missing", message : language_message("clear-param-missing"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "clear-param-missing", }); var data = classObject.getDefinition({ entity : obj.config.entity }); if( data[obj.config.entity] == undefined ){ addMessage({ obj : obj, section : "error", exception : "clear-data-missing", message : language_message("clear-data-missing"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "clear-data-missing", }); $(classObject.interface[obj.config.entity].attachment.gateway.element).val("").trigger("change").trigger("checkInterfaceConstraint"); return true; } } } }); //equal classObject.constraint.set({ key : "equal", value : function(obj){ if( obj.config.entity == undefined ){ addMessage({ obj : obj, section : "error", exception : "equal-param-missing", message : language_message("equal-param-missing"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "equal-param-missing", }); var data = classObject.getDefinition({ entity : obj.config.entity }); if( data[obj.config.entity] == undefined ){ addMessage({ obj : obj, section : "error", exception : "equal-data-missing", message : language_message("equal-data-missing"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "equal-data-missing", }); if( data[obj.config.entity].value != $(obj.element).val() ){ addMessage({ obj : obj, section : "error", exception : "equal-invalid", message : language_message("equal-invalid", {label:data[obj.config.entity].label}), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "equal-invalid", }); return true; } } } } }); //is classObject.constraint.set({ key : "is", value : function(obj){ var result = true; var value = $(obj.element).val(); if( obj.config.value != undefined && obj.config.value != value ){ addMessage({ obj : obj, section : "error", exception : "is-value", message : language_message("is-value", {value:obj.config.value}), data : {}, }); result = false; }else{ removeMessage({ obj : obj, section : "error", exception : "is-value", }); } return result; } }); //int-value classObject.constraint.set({ key : "int-value", value : function(obj){ var result = true; var value = $(obj.element).val(); value = parseInt(value); obj.config.min = parseInt(obj.config.min); obj.config.max = parseInt(obj.config.max); if( obj.config.min != undefined && value.length < obj.config.min ){ addMessage({ obj : obj, section : "error", exception : "int-value-invalid-min", message : language_message("int-value-invalid-min", {min:obj.config.min}), data : {}, }); result = false; }else{ removeMessage({ obj : obj, section : "error", exception : "int-value-invalid-min", }); } if( obj.config.max != undefined && value.length > obj.config.max ){ addMessage({ obj : obj, section : "error", exception : "int-value-invalid-max", message : language_message("int-value-invalid-max", {max:obj.config.max}), data : {}, }); result = false; }else{ removeMessage({ obj : obj, section : "error", exception : "int-value-invalid-max", }); } return result; } }); //string-length classObject.constraint.set({ key : "string-length", value : function(obj){ var result = true; var value = $(obj.element).val(); if( obj.config.min != undefined && value.length < obj.config.min ){ addMessage({ obj : obj, section : "error", exception : "string-length-invalid-min", message : language_message("string-length-invalid-min", {min:obj.config.min}), data : {}, }); result = false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-length-invalid-min", }); } if( obj.config.max != undefined && value.length > obj.config.max ){ addMessage({ obj : obj, section : "error", exception : "string-length-invalid-max", message : language_message("string-length-invalid-max", {max:obj.config.max}), data : {}, }); result = false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-length-invalid-max", }); } return result; } }); //string-has classObject.constraint.set({ key : "string-has", value : function(obj){ var pattern = { number : [new RegExp(/\d+/g), "Zahlen"], uppercased : [new RegExp(/[A-Z]/), "Kleinbuchstaben"], lowercased : [new RegExp(/[a-z]/), "Großbuchstaben"], special : [new RegExp(/[-!$%^#&*()_+|~=`{}\[\]:";'<>?,.\/]/), "Sonderzeichen (-!$%^#&*()_+|={}\[\]:;<>?,.)"], }; var value = $(obj.element).val(); if( obj.config.type == undefined ){ addMessage({ obj : obj, section : "error", exception : "string-has-param", message : language_message("string-has-param"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-has-param", }); if( pattern[obj.config.type] == undefined ){ addMessage({ obj : obj, section : "error", exception : "string-has-pattern", message : language_message("string-has-pattern"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-has-pattern", }); if( pattern[obj.config.type][0].test(value) == true ){ removeMessage({ obj : obj, section : "error", exception : "string-has-failed-" + obj.config.type, }); return true; }else{ addMessage({ obj : obj, section : "error", exception : "string-has-failed-" + obj.config.type, message : language_message("string-has-failed", {type:pattern[obj.config.type][1]}), data : {}, }); return false; } } } } }); //string-only classObject.constraint.set({ key : "string-only", value : function(obj){ var pattern = { number : [new RegExp(/\d+/g), "Zahlen"], }; var value = $(obj.element).val(); if( obj.config.type == undefined ){ addMessage({ obj : obj, section : "error", exception : "string-only-param", message : language_message("string-only-param"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-only-param", }); if( pattern[obj.config.type] == undefined ){ addMessage({ obj : obj, section : "error", exception : "string-only-pattern", message : language_message("string-only-pattern"), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-only-pattern", data : {}, }); if( pattern[obj.config.type][0].test(value) == false ){ addMessage({ obj : obj, section : "error", exception : "string-only-invalid", message : language_message("string-only-invalid",{type:pattern[obj.config.type][1]}), data : {}, }); return false; }else{ removeMessage({ obj : obj, section : "error", exception : "string-only-invalid", data : {}, }); return true; } } } } }); } Class.prototype.getDefinition = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { entity : undefined, callback : undefined }); var definition = new Surfable.Property; $.each( classObject.definition.get({ entity : thisParam.entity }), function(entity, thisObject){ if( thisObject.value != undefined ){ for( var paramName in thisObject.value ){ if( thisObject.value.isProto(paramName) == false ){ definition.prepair({ key : entity }).set({ key : paramName, value : thisObject.value[paramName].value }); } } } }); if( thisParam.entity == undefined ){ return definition; }else{ return definition.get({ entity : thisParam.entity }); } } Class.prototype.setDefinition = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { entity : undefined, key : undefined, value : undefined, add : false }); if( thisParam.entity == undefined ){ Surfable.log.push("object("+className+") method(setDefinition) key(entity) issue(missing)"); return false; }else if( thisParam.key == undefined ){ Surfable.log.push("object("+className+") method(setDefinition) key(key) issue(missing)"); return false; }else{ var definition = classObject.definition.get(); if( definition[thisParam.entity] == undefined ){ Surfable.log.push("object("+className+") method(setDefinition) key(entity) value("+thisParam.entity+") issue(unknown)"); return false; }else if( definition[thisParam.entity].value[thisParam.key] == undefined ){ Surfable.log.push("object("+className+") method(setDefinition) key(key) value("+thisParam.key+") issue(unknown)"); return false; }else{ $(definition[thisParam.entity].value[thisParam.key].element).attr("value", thisParam.value).change(); return thisParam.value; } } } Class.prototype.findDefinition = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, []); var found = classObject.definition.find(thisParam); var result = {}; $.each(found, function(key, value){ var entity = $(value).attr(classObject.property.get().definitionAttr); result[entity] = classObject.getDefinition({ entity : entity })[entity]; }); return result; } Class.prototype.stageInterface = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { entity : undefined, }); if( thisParam.entity == undefined ){ var array = {}; $.each(classObject.findDefinition(), function(entity, entityData){ array[entity] = classObject.stageInterface({ entity : entity }); }); return array; }else{ var interface = classObject.interface.prepair({ key : thisParam.entity }); $("["+classObject.property.get().interfaceAttr+"=\""+thisParam.entity+"\"]").each(function(key, interfaceElement){ interface.prepair({ key : "attachment" }); if( interface.get().element == undefined ){ interface.set({ key : "element", value : interfaceElement }); interface.set({ key : "entity", value : thisParam.entity }); } }); return classObject.interface.get()[thisParam.entity]; } } Class.prototype.deployInterface = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { entity : undefined, }); if( thisParam.entity == undefined ){ $.each(classObject.interface, function(entity, interfaceObject){ if( classObject.interface.isProto(entity) == false ){ classObject.deployInterface({ entity : entity }); } }); return true; }else if( classObject.interface != undefined && classObject.interface[thisParam.entity] != undefined && classObject.interface[thisParam.entity].attachment != undefined ){ var interfaceObject = classObject.interface[thisParam.entity]; $.each(interfaceObject.attachment, function(attachmentKey, componentObject){ if( interfaceObject.attachment.isProto(attachmentKey) == false ){ componentObject.deploy({ parent : interfaceObject.element, }); } }); return true; } } Class.prototype.defineInterface = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { condition : function(param){}, definition : function(param){}, entity : undefined }); var closure = function(entity, interfaceObject){ if( classObject.interface.isProto(entity) == false ){ if( thisParam.condition(interfaceObject) == true ){ thisParam.definition(interfaceObject); } } } if( thisParam.entity == undefined ){ $.each(classObject.interface, function(entity, interfaceObject){ closure(entity, interfaceObject); }); }else if( classObject.interface != undefined && classObject.interface[thisParam.entity] != undefined ){ closure(thisParam.entity, classObject.interface[thisParam.entity]); } } Class.prototype.defineInterfaceDefault = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { entity : undefined }); if( thisParam.entity == undefined ){ $.each(classObject.interface, function(entity, interfaceObject){ classObject.defineInterfaceDefault({ entity : entity }); }); }else{ var thisEntity = thisParam.entity; //assessment classObject.defineInterface({ condition : function(interfaceObject){ var data = classObject.getDefinition({ entity : interfaceObject.entity })[interfaceObject.entity]; if( data == undefined ){ return false; }else{ return true; } }, definition : function(interfaceObject){ var data = classObject.getDefinition({ entity : interfaceObject.entity })[interfaceObject.entity]; var attachment = new Surfable.Component(data); var Assessment = function(classParam){ var classObject = this; var thisParam = defaultize(methodParam, {}); if( data.label != undefined ){ //classObject.title = "\""+data.label+"\"-Info:"; classObject.title = data.label; }else{ classObject.title = "Info"; } classObject.info = new Surfable.Property({}); classObject.info.prepair({ key: "error" }); classObject.info.prepair({ key: "success" }); classObject.info.prepair({ key: "info" }); } Assessment.prototype.info = {}; Assessment.prototype.add = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { exception : undefined, section : undefined, message : undefined, data : {}, }); thisParam.data.message = thisParam.message; if( thisParam.exception == undefined ){ console.debug("Assessment exception \"" + thisParam.exception + "\" missing"); return false; }else if( thisParam.section == undefined ){ $.each(classObject.info, function(section, info){ classObject.add({ section : section, exception : thisParam.exception, message : thisParam.message, data : thisParam.data }); }); return true; }else if( classObject.info.get()[thisParam.section] == undefined ){ console.debug("Assessment cant find section \"" + thisParam.section + "\""); return false; }else{ classObject.info.get()[thisParam.section].set({ key : thisParam.exception, value : thisParam.data, }); return true; } } Assessment.prototype.remove = function(methodParam){ var classObject = this; var thisParam = defaultize(methodParam, { exception : undefined, section : undefined, }); if( thisParam.exception == undefined ){ console.debug("Assessment exception \"" + thisParam.exception + "\" missing"); return false; }else if( thisParam.section == undefined ){ $.each(classObject.info, function(section, info){ classObject.remove({ section : section, exception : thisParam.exception, data : thisParam.data }); }); return true; }else if( classObject.info.get()[thisParam.section] == undefined ){ console.debug("Assessment cant find section \"" + thisParam.section + "\""); return false; }else if( classObject.info.get()[thisParam.section][thisParam.exception] != undefined ){ delete classObject.info[thisParam.section][thisParam.exception]; return true; } } Assessment.prototype.clear = function(methodParam){ var classObject = this; classObject.info = new Surfable.Property({}); classObject.info.prepair({ key: "error" }); classObject.info.prepair({ key: "success" }); classObject.info.prepair({ key: "info" }); } attachment.content = new Assessment({}); var markup = ""; markup += "
" + JSON.stringify(exceptionObject) + "
" + JSON.stringify(pre) + "