<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/SiteMenu.Master" AutoEventWireup="true" CodeBehind="BS_Notice.aspx.cs" Inherits="Project25175.BS_Notice" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <link rel="stylesheet" href="../assets/css/jquery-ui-1.10.3.custom.min.css" />

    <link rel="stylesheet" href="../assets/css/jquery-ui-1.10.3.full.min.css" />

    <script type="text/javascript">
        //警告窗
        function AlertWindows() {
            $("#dialog-alarm").removeClass('hide').dialog(
                {
                    resizable: false,
                    modal: true,
                    title: "<div class='widget-header'><h4 class='smaller'><i class='icon-warning-sign red'></i>提示</h4></div>",
                    title_html: true,
                    buttons: [
						{
						    html: "<i class='icon-remove bigger-110'></i>&nbsp; 确定",
						    "class": "btn btn-xs",
						    click: function () {
						        $(this).dialog("close");
						    }
						}]
                });
        }
        function DoubleAddClick() {
            var edit_text = $('#editor1').html();

            var NoTitle = $('#ContentPlaceHolder1_TxtNoTitle').val().trim();

            if (NoTitle.length <= 0) {
                document.getElementById("IpEr").value = "请输入标题";
                this.AlertWindows();
                return;
            }
            else if (NoTitle.length > 50) {
                document.getElementById("IpEr").value = "标题不能超过50字符";
                this.AlertWindows();
                return;
            }

            if (edit_text.replace("&nbsp;", "").replace(" ","").length < 10) {
                document.getElementById("IpEr").value = "公告内容不得为空";
                this.AlertWindows();
                return;
            }
//            else if (edit_text.length > 500000) {
//                document.getElementById("IpEr").value = "公告内容不得超过500000字符";
//                this.AlertWindows();
//                return;
//            }

//            document.getElementById("IpEr").value = edit_text.length;
//            this.AlertWindows();
//            return;

            document.getElementById("ContentPlaceHolder1_TxtEditor").value = edit_text;
            document.getElementById("ContentPlaceHolder1_BT_Add").click();
        }

        function DoubleEditClick() {
            var edit_text = $('#editor2').html();

            var NoTitle = $('#ContentPlaceHolder1_TxtNoTitle_Edit').val().trim();

            if (NoTitle.length <= 0) {
                document.getElementById("IpEr").value = "请输入标题";
                this.AlertWindows();
                return;
            }
            else if (NoTitle.length > 50) {
                document.getElementById("IpEr").value = "标题不能超过50字符";
                this.AlertWindows();
                return;
            }

            if (edit_text.replace("&nbsp;", "").replace(" ", "").length < 10) {
                document.getElementById("IpEr").value = "公告内容不得为空";
                this.AlertWindows();
                return;
            }
//            else if (edit_text.length > 500000) {
//                document.getElementById("IpEr").value = "公告内容不得超过500000字符";
//                this.AlertWindows();
//                return;
//            }
            document.getElementById("ContentPlaceHolder1_TxtEditorEdit").value = edit_text;
            document.getElementById("ContentPlaceHolder1_BT_Edit").click();
        }
        function DoubleDelClick() {
            document.getElementById("ContentPlaceHolder1_BtMenuDel").click();
        }

        //后台调用,区分提示信息底色
        //Danger,Info
        function ChangeMsgClass(MsgType) {
            if (MsgType == "Danger") {
                DivMsg.className = 'alert alert-danger';
            }
            else {
                DivMsg.className = 'alert alert-info';
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try { ace.settings.check('breadcrumbs', 'fixed') } catch (e) { }
		</script>
		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
                系统公告
			</li>
		</ul>
	</div>

    <div id="dialog-alarm" class="hide">
		<div class="alert alert-warning bigger-110 col-xs-12">
			<input id="IpEr" type="text" class="alert alert-warning col-xs-12" disabled="disabled" >
		</div>
		<div class="space-6"></div>
	</div><!-- #dialog-confirm -->

    <div id="dialog-del" class="hide">
		<div class="alert alert-warning bigger-110">
			当前勾选的数据将被删除。
		</div>
		<div class="space-6"></div>
		<p class="bigger-110 bolder center grey">
			<i class="icon-hand-right blue bigger-120"></i>
			确定删除吗?
		</p>
	</div><!-- #dialog-confirm -->

    <div class="page-content">
        <div class="row col-xs-12">
            <div id="DivMsg" class="alert alert-info">
                <i class="icon-hand-right"></i>
                <asp:Label ID="LabMsg" runat="server" Text=" "></asp:Label>
			    <button class="close" data-dismiss="alert">
                <i class="icon-remove"></i>
                </button>
            </div>
        </div>


        <div class="page-header">
            <div class="col-xs-12">
                <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="公告列表" CssClass="btn btn-info btn-sm" />
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="添加" CssClass="btn btn-primary btn-sm" />
                <asp:Button ID="BtMenuEdit" runat="server" OnClick="BtMenuEdit_Click" Text="修改" CssClass="btn btn-purple btn-sm" />
                <asp:Button ID="BtMenuDel" runat="server" OnClick="BtMenuDel_Click" Text="删除" CssClass="btn btn-info btn-sm hidden" />
                <a href="#" id="id-btn-dialog-del" class="btn btn-danger btn-sm">删除</a> 
            </div>
        </div>

        <asp:Panel runat="server" ID="PanelAdd">
            <div class="row clearfix form-actions">

	            <%--<div class="form-group col-md-offset-2 col-xs-8" >
					<label class="col-sm-3 control-label no-padding-right">标题</label>
                    <div class="space-2"></div>
                    <input id="TxtNoTitle" runat="server" class="col-xs-6" type="text" />
                </div>
                <div class="space-4"></div>
                <div class="form-group col-md-offset-2 col-xs-8">
                    <label class="col-sm-3 control-label no-padding-right">状态</label>
                    <div class="space-2"></div>
                    <asp:DropDownList ID="DDLState" runat="server" CssClass="col-xs-2">
                        <asp:ListItem Value="Y"></asp:ListItem>
                        <asp:ListItem Value="N"></asp:ListItem>
                    </asp:DropDownList>
                </div>--%>

                <div class="space-10"></div>
                <div class="form-group col-xs-12" >
					<label class="col-sm-1 control-label no-padding-right">标题</label>
                    <input id="TxtNoTitle" runat="server" class="col-xs-8" type="text" />
                    <label class="col-sm-1 control-label no-padding-right">状态</label>
                    <asp:DropDownList ID="DDLState" runat="server" CssClass="col-xs-2">
                        <asp:ListItem Value="Y"></asp:ListItem>
                        <asp:ListItem Value="N"></asp:ListItem>
                    </asp:DropDownList>
                </div>
                <div class="space-4"></div>
                <div class="form-group col-xs-12" >
                    <div class="wysiwyg-editor" id="editor1"> 
                    </div>

                    <textarea id="TxtEditor" runat="server" rows="2" cols="20" class="hidden" ></textarea>

                </div>
                <div class="space-6"></div>
				<div class="form-group col-xs-12 center">
                    <asp:Button ID="BT_Add" runat="server" Text="确认" 
                            CssClass="btn btn-info icon-ok bigger-110 hidden " OnClick="BT_Add_Click" />
                    <button id="BtA" class="btn btn-info" type="button" onclick="DoubleAddClick()">
						<i class="icon-ok bigger-110"></i>
						确认
					</button>
                    <Button id="Reset1" type="reset" value="取消"  class="btn" ><i class="icon-undo bigger-110"></i>
					    Reset</Button>
                </div>
            </div>
        </asp:Panel>

        <asp:Panel runat="server" Visible="false" ID="PanelEdit">
            <div id="dialog-edit" class="row clearfix form-actions">
                <div class="form-group col-md-offset-2 col-xs-8" >
				    <label class="col-sm-4 control-label no-padding-right">ID</label>
	                <asp:TextBox runat="server" id="TxtID_Edit"  CssClass="col-xs-8" ReadOnly="true"/>
                </div>
                <div class="space-4"></div>
			    <div class="form-group col-md-offset-2 col-xs-8" >
				    <label class="col-sm-4 control-label no-padding-right">标题</label>
	                <asp:TextBox runat="server" id="TxtNoTitle_Edit"  CssClass="col-xs-8"/>
                </div>
                <div class="space-4"></div>
                <div class="form-group col-md-offset-2 col-xs-8" >
                    <label class="col-sm-4 control-label no-padding-right" onclick="ShowEditBefor()">状态</label>
                    <asp:DropDownList ID="DDLState_Edit" runat="server" CssClass="col-xs-8">
                        <asp:ListItem Value="Y"></asp:ListItem>
                        <asp:ListItem Value="N"></asp:ListItem>
                    </asp:DropDownList>
                </div>
                <div class="space-4"></div>
                <div class="form-group col-xs-12" >
                    <div class="wysiwyg-editor" id="editor2" > 
                    
                    </div>
                    <textarea id="TxtEditorEdit" runat="server" rows="2" cols="20" class="hidden" ></textarea>

                </div>
                <div class="space-6"></div>
				<div class="form-group col-xs-12 center">
                    <asp:Button ID="BT_Edit" runat="server" Text="修改" 
                            CssClass="btn btn-info icon-ok bigger-110 hidden " onclick="BT_Edit_Click"/>
                    <button class="btn btn-info" type="button" onclick="DoubleEditClick()">
						<i class="icon-ok bigger-110"></i>
						修改
					</button>
                    <Button id="Button3" type="reset" value="取消"  class="btn" ><i class="icon-undo bigger-110"></i>
					    Reset
                    </Button>
                    <Button id="Button4" type="reset" value="返回"  class="btn" onclick="javascript:history.go(-1)"><i class="icon-backward bigger-110"></i>
					    Back
                    </Button>
                </div>
		    </div><!-- #dialog-message -->
        </asp:Panel>

        <asp:Panel runat="server" Visible="false" ID="PanelData">
            <div class="row">
	            <div class="col-xs-12">
		            <div class="table-responsive">
                        <asp:GridView ID="GridView1" runat="server" CssClass="table table-striped table-bordered table-hover" AutoGenerateColumns="False" DataKeyNames="ID" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging">
                            <Columns>
                                <asp:TemplateField HeaderText="选取">
                                    <HeaderTemplate>
                                        <asp:CheckBox ID="CheckSelect" runat="server" CssClass="ace"/>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="CheckSelect" runat="server" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <%--<asp:BoundField DataField="Id" HeaderText="ID" ReadOnly="True"/>--%>
                                <asp:TemplateField HeaderText="标题">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TxtNoTitle" runat="server" Text='<%#Bind("NoTitle") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:HyperLink ID="HyperLink1" runat="server" Target="_blank"
                                            NavigateUrl='<%# Eval("ID", "../Public/ViewNotice.aspx?ID={0}") %>' 
                                            Text='<%# Eval("NoTitle") %>'></asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <%--<asp:BoundField DataField="NoTitle" HeaderText="标题" />--%>
                                <asp:BoundField DataField="UserID" HeaderText="发布人" ReadOnly="True"/>
                                <asp:BoundField DataField="NoDate" HeaderText="发布时间" ReadOnly="True"/>
                                <asp:TemplateField HeaderText="状态">
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="DDLState" runat="server" SelectedValue='<%# Bind("state")%>' CssClass ="col-xs-10">
                                            <asp:ListItem Value="Y"></asp:ListItem>
                                            <asp:ListItem Value="N"></asp:ListItem>
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%#Bind("state") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:CommandField ShowEditButton="True" >
                                </asp:CommandField>
                                <asp:CommandField ShowDeleteButton="True" />                        
                            </Columns>
                        </asp:GridView>
		            </div><!-- /.table-responsive -->
	            </div><!-- /span -->
            </div>
        </asp:Panel>

</div>
    
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder_Footer" runat="server">

    <script src="../assets/js/jquery-2.0.3.min.js"></script>

	<script type="text/javascript">
		window.jQuery || document.write("<script src='../assets/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
	</script>

	<script type="text/javascript">
		if ("ontouchend" in document) document.write("<script src='../assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
	</script>
	<script src="../assets/js/bootstrap.min.js"></script>
	<script src="../assets/js/typeahead-bs2.min.js"></script>

	<!-- page specific plugin scripts -->
        <script src="../assets/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="../assets/js/jquery.ui.touch-punch.min.js"></script>
		<%--<script src="../assets/js/markdown/markdown.min.js"></script>--%>
		<script src="../assets/js/markdown/bootstrap-markdown.min.js"></script>
		<script src="../assets/js/jquery.hotkeys.min.js"></script>
		<script src="../assets/js/bootstrap-wysiwyg.min.js"></script>
		<%--<script src="../assets/js/bootbox.min.js"></script>--%>

        <script type="text/javascript" src="../assets/js/jquery-ui-1.10.3.full.min.js"></script>

	<!-- ace scripts -->

	<script src="../assets/js/ace-elements.min.js"></script>
	<script src="../assets/js/ace.min.js"></script>

    <script type="text/javascript">

    jQuery(function($){
	
	function showErrorAlert (reason, detail) {
		var msg='';
		if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
		else {
			console.log("error uploading file", reason, detail);
		}
		$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
		 '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
	}


	//but we want to change a few buttons colors for the third style
	$('#editor1,#editor2').ace_wysiwyg({
		toolbar:
		[
			{name:'font',title:'字体'},
			null,
            {name:'fontSize',title:'字体大小'},
			null,
			{name:'bold', className:'btn-info',title:'粗体'},
			{name:'italic', className:'btn-info',title:'斜体'},
			{name:'strikethrough', className:'btn-info',title:'删除线'},
			{name:'underline', className:'btn-info',title:'下划线'},
			null,
			{name:'insertunorderedlist', className:'btn-success',title:'列表(加点)'},
			{name:'insertorderedlist', className:'btn-success',title:'列表(加数字)'},
			{name:'outdent', className:'btn-purple',title:'减少缩进'},
			{name:'indent', className:'btn-purple',title:'缩进'},
			null,
			{name:'justifyleft', className:'btn-primary',title:'左对齐'},
			{name:'justifycenter', className:'btn-primary',title:'居中'},
			{name:'justifyright', className:'btn-primary',title:'右对齐'},
			{name:'justifyfull', className:'btn-inverse',title:'两端对齐'},
			null,
			{name:'createLink', className:'btn-pink',title:'添加链接'},
			{name:'unlink', className:'btn-pink',title:'取消链接'},
			null,
			{name:'insertImage', className:'btn-success',title:'插入图片'},
			null,
			'foreColor',
			null,
			{name:'undo', className:'btn-grey',title:'撤消'},
			{name:'redo', className:'btn-grey',title:'恢复'}
		],
		'wysiwyg': {
			fileUploadError: showErrorAlert
		}
	}).prev().addClass('wysiwyg-style3');

//	$('[data-toggle="buttons"] .btn').on('click', function(e){
//		var target = $(this).find('input[type=radio]');
//		var which = parseInt(target.val());
//		var toolbar = $('#editor1').prev().get(0);
//		if(which == 1 || which == 2 || which == 3) {
//			toolbar.className = toolbar.className.replace(/wysiwyg\-style(1|2)/g , '');
//			if(which == 1) $(toolbar).addClass('wysiwyg-style1');
//			else if(which == 2) $(toolbar).addClass('wysiwyg-style2');
//		}
//	});



    //对话框全局
    $.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
        _title: function (title) {
            var $title = this.options.title || '&nbsp;'
            if (("title_html" in this.options) && this.options.title_html == true)
                title.html($title);
            else title.text($title);
        }
    }));
           
	

	//Add Image Resize Functionality to Chrome and Safari
	//webkit browsers don't have image resize functionality when content is editable
	//so let's add something using jQuery UI resizable
	//another option would be opening a dialog for user to enter dimensions.
	if ( typeof jQuery.ui !== 'undefined' && /applewebkit/.test(navigator.userAgent.toLowerCase()) ) {
		
		var lastResizableImg = null;
		function destroyResizable() {
			if(lastResizableImg == null) return;
			lastResizableImg.resizable( "destroy" );
			lastResizableImg.removeData('resizable');
			lastResizableImg = null;
		}

		var enableImageResize = function() {
			$('.wysiwyg-editor')
			.on('mousedown', function(e) {
				var target = $(e.target);
				if( e.target instanceof HTMLImageElement ) {
					if( !target.data('resizable') ) {
						target.resizable({
							aspectRatio: e.target.width / e.target.height,
						});
						target.data('resizable', true);
						
						if( lastResizableImg != null ) {//disable previous resizable image
							lastResizableImg.resizable( "destroy" );
							lastResizableImg.removeData('resizable');
						}
						lastResizableImg = target;
					}
				}
			})
			.on('click', function(e) {
				if( lastResizableImg != null && !(e.target instanceof HTMLImageElement) ) {
					destroyResizable();
				}
			})
			.on('keydown', function() {
				destroyResizable();
			});
	    }
		
		enableImageResize();

		/**
		//or we can load the jQuery UI dynamically only if needed
		if (typeof jQuery.ui !== 'undefined') enableImageResize();
		else {//load jQuery UI if not loaded
			$.getScript($path_assets+"/js/jquery-ui-1.10.3.custom.min.js", function(data, textStatus, jqxhr) {
				if('ontouchend' in document) {//also load touch-punch for touch devices
					$.getScript($path_assets+"/js/jquery.ui.touch-punch.min.js", function(data, textStatus, jqxhr) {
						enableImageResize();
					});
				} else	enableImageResize();
			});
		}
		*/
	}

    //删除
    $("#id-btn-dialog-del").on('click', function (e) {
        e.preventDefault();
        $("#dialog-del").removeClass('hide').dialog(
        {
            resizable: false,
            modal: true,
            title: "<div class='widget-header'><h4 class='smaller'><i class='icon-warning-sign red'></i>删除</h4></div>",
            title_html: true,
            buttons: [
				{
					html: "<i class='icon-trash bigger-110'></i>&nbsp; 确定",
					"class": "btn btn-danger btn-xs",
					click: function () {
						DoubleDelClick();
					}
				}
				,
				{
					html: "<i class='icon-remove bigger-110'></i>&nbsp; 取消",
					"class": "btn btn-xs",
					click: function () {
						$(this).dialog("close");
					}
				}]
        });
    });

    //全选确认框
    $('table th input:checkbox').on('click', function () {
        var that = this;
        $(this).closest('table').find('tr > td:first-child input:checkbox')
	    .each(function () {
	        this.checked = that.checked;
	        $(this).closest('tr').toggleClass('selected');
	    });
    });
    
    //##
    //修改前,将后台存放在隐藏域的内容显示到DIV编辑区
    $('#editor2').html($('#ContentPlaceHolder1_TxtEditorEdit').val());
    //##




    });


	</script>
</asp:Content>
