/*
* app.insertAttach 模塊
* 附件插入模塊
*/
Breeze.namespace('app.insertAttach', function (B) {
	//flash控件
	var $ = B.query, index = 1;
	var win = window, doc = document,
		defaultConfig = {
			rspHtmlPath: attachConfig.url,
			callback: function () { }
		},
		tattachSelector = {
			id: 'editor-insertTattach',
			load: function (elem, myeditor) {
				var id = this.id;
				B.require('util.dialog', function (B) {
					B.util.dialog({
						pos: ['leftAlign', 'bottom'],
						id: id,
						data: '<div class="B_menu B_p10B">\
	<div style="width:480px;">\
		<div class="B_h B_cc B_drag_handle">\
			<a href="javascript://" class="B_menu_adel B_close" style="margin-top:2px;">×</a>附件上傳\
		</div>\
		<!--附件列表開始-->\
		<div style="padding-top:5px">\
			<div class="B_mb10 cc">\
				<a id="B_sm_cfg" href="javascript://" class="B_fr">顯示“售密設置”</a>\
				<span id="B_uploader_container"><span id="B_uploader_flash"><span id="uploaderTmpSpan" style="display:none;"><embed style="display:none;" src="images/blank.swf" type="application/x-shockwave-flash" wmode="transparent"/><em class="s2" style="position:relative;top:3px;">該瀏覽器尚未安裝flash插件，<a href="http://www.adobe.com/go/getflashplayer" target="_blank">點擊安裝</a></em></span></span></span>\
			</div>\
			<div class="B_file">\
				<div class="cc">\
					<dl style="background:#f7f7f7;">\
						<dt>附件名&nbsp;<span class="gray">(您還可以上傳<span class="restCount s2"></span>個附件)</span></dt>\
						<dd>附件描述</dd>\
						<dd class="B_file_dd">操作</dd>\
					</dl>\
					<div id="B_qlist"></div>\
					<!--選擇文件後 顯示的列表-->\
				</div>\
			</div>\
			<div class="B_file_tips">\
				<a class="B_helpA" style="float:right;padding:0 0 0 18px;width:auto;" onclick="event&&(event.returnValue=false);">可上傳類型<i id="attach_allow_filetype"></i></a>\
				<label><input name="atc_hideatt" type="checkbox" value="1" style="padding:0;margin:-2px 0 0;"> 隱藏附件（回復可見）<input type="hidden" name="isAttachOpen" value="1" /></label>\
			</div>\
		<!--結束-->\
	</div>\
</div>',
						reuse: true,
						callback: function (popup) {
							B.require('global.uploader',function(){
								uploader.init('uploader',myeditor);
								B.addEvent(B.$('#B_sm_cfg'), 'click', uploader.toggleSelect);
							});
							myeditor.area.appendChild(popup.win);
						}
					}, elem);
				});
			}
		};

    /**
    * @description 圖片選擇器
    * @params {String} 要產生附件選擇器的元素
    * @params {Function} 選擇附件後產生的回調函數
    */
	B.app.insertAttach = function (elem, callback, editor) {
		insertTrigger = callback;
		myeditor = editor;
		if (B.$('#'+tattachSelector.id)){
			B.util.dialog({
				id: tattachSelector.id,
				reuse: true,
				callback:function(){uploader.init('uploader',myeditor);},
				pos: ['leftAlign', 'bottom']
			}, elem);
		} else {
			tattachSelector.load(elem, myeditor);
		}
    }
});

/*
此組件涉及到先通過ajax加載HTML,所以事件處理類InsertAttach在tattachSelector.load()中實例化,這與colorpicker有點不同,分開來html和event為了更容易維護和閱讀
*/