<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/SiteMenu.Master" AutoEventWireup="true" CodeBehind="AddTeachingPlan.aspx.cs" Inherits="Project25175.AddTeachingPlan" %>
<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 FilePathName = $('#ContentPlaceHolder1_UpFile_Add').val().trim().toLowerCase();
            var NoTitle = $('#ContentPlaceHolder1_TxtTPTitle_Add').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 < 25) {
                document.getElementById("IpEr").value = "教案内容不得为空";
                //document.getElementById("IpEr").value = edit_text;
                this.AlertWindows();
                return;
            }

            if (FilePathName.length > 3) {
                if (FilePathName.indexOf(".jpg") > 0 || FilePathName.indexOf(".png") > 0 || FilePathName.indexOf(".ppt") > 0 || FilePathName.indexOf(".pptx") > 0 || FilePathName.indexOf(".xls") > 0 || FilePathName.indexOf(".xlsx") > 0 || FilePathName.indexOf(".doc") > 0 || FilePathName.indexOf(".docx") > 0) {
                    //
                }
                else {
                    document.getElementById("IpEr").value = "上传文件格式不正确";
                    this.AlertWindows();
                    return;
                }
            }

            document.getElementById("ContentPlaceHolder1_TxtEditor").value = edit_text;
            document.getElementById("ContentPlaceHolder1_BT_Add").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="<%=PageIcon %>"></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 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 widget-box">
                <asp:Button ID="BtMenuAdd" runat="server" Text="新增教案" CssClass="btn btn-primary btn-sm" />
            </div>
        </div>

        <asp:Panel runat="server" ID="PanelAdd">
            <div class="row clearfix form-actions">
                <div class="form-group col-xs-8" >
                    <div class="col-xs-12">
                        <span class="col-xs-3">当前学期</span>
                        <asp:DropDownList runat="server" ID="DDLSchTimeID_Add"></asp:DropDownList>
                    </div>
                    <div class="col-xs-12 space-8"></div>
                    <div class="col-xs-12">
                        <span class="col-xs-3">选择课程</span>
                        <asp:DropDownList runat="server" ID="DDLSubjectID_Add" AutoPostBack="True"  OnSelectedIndexChanged="DDLSubjectID_Add_Changed"></asp:DropDownList>
                        <asp:DropDownList runat="server" ID="DDLSubNameID_Add"></asp:DropDownList>
                    </div>
                    <div class="col-xs-12 space-8"></div>             
                    <div class="col-xs-12">
					    <label class="col-xs-3 control-label no-padding-right">教案名称</label>
                        <input id="TxtTPTitle_Add" runat="server" class="col-xs-7" type="text" />
                    </div>
                </div>
                <div class="form-group col-xs-4">
                    <input id="UpFile_Add" type="file" runat="server"/>
                </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>

</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/bootstrap-markdown.min.js"></script>
		<script src="../assets/js/jquery.hotkeys.min.js"></script>
		<script src="../assets/js/bootstrap-wysiwyg.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').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();
			    });
		    }
		    */
	    }

        //若添加失败则保留编辑区资料
        $('#editor1').html($('#ContentPlaceHolder1_TxtEditor').val());
        //##        


        $('#ContentPlaceHolder1_UpFile_Add').ace_file_input({
            style: 'well',
            btn_choose: '上传教案文件',
            btn_change: null,
            no_icon: 'icon-cloud-upload',
            droppable: true,
            thumbnail: 'small',
            preview_error: function (filename, error_code) {
            }
        }).on('change', function () {
        });
    });


	</script>
</asp:Content>
