/**
 * ...
 * @author DefaultUser
 */

(function() {
	MYNAMESPACE.namespace('modules.ForReleaseNote');
	MYNAMESPACE.modules.ForReleaseNote = function() {
		this.xmlPath = "";
		this.targetId = "";
		this.callback;
		this.initialize.apply(this, arguments);
	};
	MYNAMESPACE.modules.ForReleaseNote.prototype = {
		// コンストラクタ
		initialize: function() {
			var thisObj = this;
		},
		load: function(fileLoader, xmlPath, targetId, retryNum, callback) {
			var thisObj = this;
			thisObj.xmlPath = xmlPath;
			thisObj.targetId = targetId;
			thisObj.callback = callback;
			
			fileLoader.load(xmlPath, retryNum, {method:thisObj.onSuccessHandler, scope:thisObj}, {method:thisObj.onErrorHandler, scope:thisObj});
		},
		
		onSuccessHandler: function(data, dataType) {
			var thisObj = this;
			/*
			var maxMessageNum = Number($(data).find("maxMessageNum").text());
			if (!isNaN(maxMessageNum)) {
				thisObj.maxMessageNum = (0 < maxMessageNum) ? maxMessageNum : 0;
			}
			*/
			
			var template = $("#" + thisObj.targetId + " > div.wrapper > table > tbody > tr");
			var master = $(template).clone();
			var message = "";
			
			$("infos > info", data).each(
				function() {
					var clone = $(master).clone();
					if ($(this).attr("isNew") === "1") {
						$(".new", clone).addClass("enabled");
					}
					$(".date", clone).html($("date", this).text());
					$(".message > a", clone).attr("href", $("url", this).text());
					if ($("url", this).text().indexOf("javascript:") !== -1) {
						$(".message > a", clone).attr("target", "");
					}
					message = $("message", this).text();
					/*
					if (maxMessageNum < message.length) {
						message = message.substr(0, maxMessageNum) + "...";
					}
					*/
					$(".message > a", clone).html(message);
					$("#" + thisObj.targetId + " > div.wrapper > table > tbody").append(clone);
				}
			);
			$("#" + thisObj.targetId + " > div.wrapper > table > tbody > tr").eq(0).remove();
			
			if (thisObj.callback) {
				thisObj.callback();
			}
		},
		
		onErrorHandler: function(data, dataType) {
			var thisObj = this;
			alert(thisObj.xmlPath + "のファイルのロード失敗");
		}
	};
})();

