function log(object, msg){ if (typeof console != 'undefined') { console.log(msg); } } var setChangeToNullifyID = function(parentElementID, changeFieldName, idFieldName) { log(this, "set onchange of " + parentElementID + ":" + changeFieldName); $("#" + parentElementID + " input[id=" + changeFieldName + "]").change(function() { log("=nullify field " + idFieldName); $("#" + parentElementID + " input[id=" + idFieldName + "]").val(""); } ); } // EmailLinkWebop class // equivalent to the corresponding java class var EmailLinkWebop = function(id, group, name) { this.wopid = id; // bean id this.WopRegroupement = group; this.WopNam = name; } EmailLinkWebop.prototype.buildFromUI = function(emailLinkElementID) { log(this, "EmailLinkWebop buildFromUI"); log(this, "emailLinkElementID = " + emailLinkElementID); index = emailLinkElementID.substring(emailLinkElementID.lastIndexOf("_")); log(this, "index : " + index); for (field in this) { val = $("#" + emailLinkElementID + " input[id=" + field + index + "]").val(); log(this," => field:" + field + index + " val=" + val); if (val != null) { if (val.length == 0) { this[field] = null; } else { this[field] = val; } } } log(this,"EmailLinkWebop buildFromUI the name:" + this.wopname); } EmailLinkWebop.prototype.setTriggers = function(emailLinkElementID) { setChangeToNullifyID(emailLinkElementID, "wopgroup", "wopid"); setChangeToNullifyID(emailLinkElementID, "wopname", "wopid"); } // static method EmailLinkWebop.display = function(emailLinkElementID, flagDisplay) { log(this,"EmailLinkWebop display"); for (field in new EmailLinkWebop()) { jqElement = $("#" + emailLinkElementID + " input[id=" + field + "]"); if (flagDisplay) { jqElement.show(); } else { jqElement.hide(); } } } //EmailLinkEvent Class var EmailLinkEvent = function(id, name, statusid) { this.evtid = id; this.EvtLabel = name; this.statusid = statusid; } EmailLinkEvent.prototype.buildFromUI = function(emailLinkElementID) { log(this,"EmailLinkEvent buildFromUI"); log(this, "emailLinkElementID = " + emailLinkElementID); index = emailLinkElementID.substring(emailLinkElementID.lastIndexOf("_")); for (field in this) { if (field != 'buildFromUI'){ val = $("#" + emailLinkElementID + " input[id=" + field + index + "]").val(); if (typeof ($("#" + emailLinkElementID + " input[id=" + field + index + "]")).val() != 'undefined') { log(this, "field != 'buildFromUI' ==> val : " + val); log(this, " => field:" + field + " val=" + val + " index=" + index); if (val != null) { if (val.length == 0) { this[field] = null; } else { this[field] = val; } } } else { selected = $("#" + emailLinkElementID + " select[id=evtstatus" + index + "] option:selected"); this['statusid'] = selected.attr('id'); } } } log(this, "EmailLinkWebop buildFromUI the name:" + this.evtname); } //EmailLinkPopulation Class var EmailLinkPopulation = function(id, name) { this.popid = id; this.PopName = name; } EmailLinkPopulation.prototype.buildFromUI = function(emailLinkElementID) { log(this, "EmailLinkPopulation buildFromUI"); log(this, "emailLinkElementID = " + emailLinkElementID); index = emailLinkElementID.substring(emailLinkElementID.lastIndexOf("_")); for (field in this) { val = $("#" + emailLinkElementID + " input[id=" + field + index + "]").val(); log(this, " => field : " + field + index + " val= " + val); if (val != null) { if (val.length == 0) { this[field] = null; } else { this[field] = val; } } } log(this, "EmailLinkWebop buildFromUI the name:" + this.popname); } // Emailink Class var EmailLink = function(id, url, emailid, text, index, msgid, lngmsg, htmlcontent) { this.id = id; this.url = url; this.emailid = emailid; this.text = text; this.index = index; this.msgid = msgid; this.lngmsg = lngmsg; this.htmlcontent = htmlcontent; this.webop = null; // EmailLinkWebop object this.event = null; // EmailLinkEvent object this.population = null; // EmailLinkPopulation object this.boundElementID = null; // html element to bind to } EmailLink.prototype.bindTo = function(htmlElementID) { this.boundElementID = htmlElementID; } EmailLink.prototype.setWebop = function(webop) { this.webop = webop; } EmailLink.prototype.setEvent = function(event) { this.event = event; } EmailLink.prototype.setPopulation = function(population) { this.population = population; } EmailLink.prototype.initializeEmailLinkObjects = function() { this.webop = new EmailLinkWebop(null, null, null); this.event = new EmailLinkEvent(null, null, null, null); this.population = new EmailLinkPopulation(null, null); } EmailLink.prototype.display = function() { // attach the trigger on the check box log(this,"buildFromUI.display for " + this.id); EmailLinkWebop.display(this.boundElementID, (this.webop != null)); if (this.webop != null) { this.webop.setTriggers(this.boundElementID); } } EmailLink.prototype.buildFromUI = function() { log(this, "buildFromUI.buildFromUI for " + this.id); if (this.webop != null) { this.webop.buildFromUI(this.boundElementID); } if (this.event != null) { this.event.buildFromUI(this.boundElementID); } if (this.population != null) { this.population.buildFromUI(this.boundElementID); } } EmailLink.prototype.toJSON = function() { var jsonObj = new Object(); jsonObj["id"] = this.id jsonObj["url"] = this.url; jsonObj["emailid"] = this.emailid; jsonObj["text"] = this.text; jsonObj["index"] = this.index; jsonObj["msgid"] = this.msgid; jsonObj["lngmsg"] = this.lngmsg; jsonObj["htmlcontent"] = this.htmlcontent; jsonObj["webop"] = this.webop; jsonObj["event"] = this.event; jsonObj["population"] = this.population; return jsonObj; }