珂珂的个人博客 - 一个程序猿的个人网站

FYJ.Blogs开发系列(二)-后台文章列表页View

FYJ.Blogs开发系列(一)

FYJ.Blogs开发系列(二)-后台文章列表页View

FYJ.Blogs开发系列(三)-后台文章编辑页View

FYJ.Blogs开发系列(四)-后台文章Controller

FYJ.Blogs开发系列(五)-前台基页Controller

FYJ.Blogs开发系列(六)-前台主页Controller

FYJ.Blogs开发系列(七)-前台文章Controller

FYJ.Blogs开发系列(八)-自定义路由

FYJ.Blogs开发系列(九)-查询文章函数

FYJ.Blogs开发系列(十)-主页查询存储过程

FYJ.Blogs开发系列(十一)-后记

@model Blogs.Entity.blog_tb_article
@{
    ViewBag.Title = "文章管理";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
}
<script src="http://static.fyj.me/js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>

<fieldset>
    <legend>搜索与操作</legend>
    <div>
        <form>
            <table class="searchtable">
                <tr>
                    <td>所属博客:</td>
                    <td>
                        @Html.DropDownList("ddlBlogSelect", ViewData["BlogSelect"] as IEnumerable<SelectListItem>, new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>
                    <td>系统分类:</td>
                    <td>
                        @Html.DropDownList("ddlsiteCategorySelect", ViewData["siteCategorySelect"] as IEnumerable<SelectListItem>, @"---请选择---", new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>
                    <td>个人分类:</td>
                    <td>
                        @Html.DropDownList("ddlcategorySelect", ViewData["categorySelect"] as IEnumerable<SelectListItem>, @"---请选择---", new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>
                    <td>所属主题:</td>
                    <td>
                        @Html.DropDownList("ddlTopicSelect", ViewData["TopicSelect"] as IEnumerable<SelectListItem>, @"---请选择---", new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>
                    <td>是否原创:</td>
                    <td>
                        <select id="ddlarticleIsOriginalSelect" name="ddlarticleIsOriginalSelect" class="easyui-combobox" editable="false" style="width:150px">
                            <option value="" selected="selected">---请选择---</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>标题:</td>
                    <td><input type="text" name="articleTitle" /></td>
                    <td>日期起:</td>
                    <td><input type="text" name="StartDate" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" /></td>
                    <td>日期止:</td>
                    <td><input type="text" name="EndDate" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" /></td>
                    <td>
                        <a href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" id="btnQuery">搜索</a>
                    </td>
                    <td>
                        <input type="checkbox" id="isShowPic" />显示图片
                    </td>
                </tr>
            </table>
        </form>

    </div>

    <div>
        <form>
            <table class="searchtable">
                <tr>
                    <td>博客:</td>
                    <td>
                        @Html.DropDownList("ddlBlogChange", ViewData["BlogSelect"] as IEnumerable<SelectListItem>, new { @style = "width:150px", @editable = "false" })
                    </td>
                    <td>改变个人分类:</td>
                    <td>
                        @Html.DropDownList("ddlcategoryChange", ViewData["categorySelect"] as IEnumerable<SelectListItem>, @"---请选择---", new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>
                    <td>改变主题:</td>
                    <td>
                        @Html.DropDownList("ddlTopicChange", ViewData["TopicSelect"] as IEnumerable<SelectListItem>, @"---请选择---", new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>
                    <td>改变系统分类:</td>
                    <td>
                        @Html.DropDownList("ddlSiteCategoryChange", ViewData["siteCategorySelect"] as IEnumerable<SelectListItem>, new { @class = "easyui-combobox", @style = "width:150px", @editable = "false" })
                    </td>

                </tr>
                <tr>
                    <td>改变:</td>
                    <td>
                        <select id="ddlStateField" style="width:150px">
                            <option value="articleIsTop" selected="selected">是否置顶</option>
                            <option value="articleIsDisabled">是否禁用</option>
                            <option value="articleIsDelete">是否删除</option>
                            <option value="articleIsOriginal">是否原创</option>
                        </select>
                    </td>
                    <td>
                        <input type="button" value="True" id="btnTrue" />
                        <input type="button" value="False" id="btnFalse" />
                    </td>
                </tr>
            </table>
        </form>

    </div>
</fieldset>

<table id="List"></table>
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '/MyBlog/Article/GetList?ddlBlogSelect=' + $('#ddlBlogChange').val(),
            width: $(window).width() - 10,
            methord: 'post',
            height: $(window).height() - 35,
            fitColumns: false,
            sortName: 'ADD_DATE',
            sortOrder: 'desc',
            idField: 'articleID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: false,//单选模式
            rownumbers: false,//行号
            columns: [[
                { field: 'ID', title: '选择', width: 80, checkbox: true },
                { field: 'articleID', title: '文章ID', width: 100 },
                { field: 'siteCategoryDisplay', title: '系统分类', width: 100, sortable: false },
                { field: 'categoryDisplay', title: '个人分类', width: 100, sortable: false },
                { field: 'topicDisplay', title: '主题', width: 100, sortable: false },
                { field: 'articleTitle', title: '标题', width: 200, sortable: true },
                { field: 'articleThemeDisplay', title: '主题', width: 100, sortable: true },
                { field: 'articlePic', title: '图片', width: 150, sortable: true, formatter: formatImage },
                { field: 'articleIsPic', title: '是否图片', width: 80, align: 'center', sortable: true },
                { field: 'articleIsOriginal', title: '是否原创', width: 80, align: 'center', sortable: true },
                { field: 'articleIsDisabled', title: '是否禁用', width: 80, align: 'center', sortable: true },
                { field: 'isVerifyComment', title: '评论需审核', width: 80, align: 'center', sortable: true },
                { field: 'isAllowAnonymousComment', title: '禁止匿名评论', width: 80, align: 'center', sortable: true },
                { field: 'isDisableComment', title: '禁止评论', width: 80, align: 'center', sortable: true },
                { field: 'articleIsTop', title: '是否置顶', width: 80, align: 'center', sortable: true },
                { field: 'articleClickTimes', title: '浏览次数', width: 80, align: 'center', sortable: true },
                { field: 'articleCommentTimes', title: '评论次数', width: 80, align: 'center', sortable: true },
                { field: 'articleDatetime', title: '显示时间', width: 120, align: 'center', sortable: true },
                { field: 'articlePostBy', title: '发表自', width: 100, sortable: true },
                { field: 'ADD_DATE', title: '创建时间', width: 120, align: 'center', sortable: true },
                { field: 'UPDATE_DATE', title: '修改时间', width: 120, align: 'center', sortable: true }
            ]],
            toolbar: [{
                id: 'btnadd',
                text: '添加',
                iconCls: 'icon-add',
                handler: function () {
                    //实现弹出添加信息的层
                    ShowCreateDialog();
                }
            }, '-', {
                id: 'btncut',
                text: '修改',
                iconCls: 'icon-edit',
                handler: function () {

                    //实现弹出修改信息的层
                    ShowUpdateDialog();
                }
            }, '-', {
                id: 'btncut',
                text: '生成目录',
                iconCls: 'icon-edit',
                handler: function () {
                    CreateCatelog();
                }
            }, '-', {
                id: 'btncut',
                text: '使用ueditor编辑正文',
                iconCls: 'icon-edit',
                handler: function () {
                    var row = $('#List').datagrid('getSelections');
                    if (row.length == 0) {
                        alert("请选择要编辑的记录");
                        return false;
                    }
                    else if (row.length > 1) {
                        alert("不能同时编辑多行");
                        return false;
                    }
                    else {
                        window.open("/MyBlog/Article/ueditorEdit/" + row[0].ID);
                    }
                }
            }, '-', {
                id: 'btnsave',
                text: '删除',
                iconCls: 'icon-remove',
                handler: function () {
                    //删除信息
                    DeleteInfoByClick();
                }
            }, '-', {
                id: 'btnview',
                text: '预览',
                iconCls: 'icon-tip',
                handler: function () {
                    var row = $('#List').datagrid('getSelections');
                    if (row.length == 0) {
                        alert("请选择要预览的记录");
                        return false;
                    }
                    else if (row.length > 1) {
                        alert("不能同时预览多行");
                        return false;
                    }
                    else {
                        window.open("/MyBlog/Article/View/" + row[0].ID);
                    }
                }
            }],

            onLoadError: function () {
                alert("加载错误");
            }
        });

        var isShowPic = false;
        function formatImage(value) {
            if (isShowPic) {
                if (value == null || value == "" || value == "&nbsp;") {
                    return "<img src='http://static.fyj.me/images/common/nopic.jpg' style='width:90px;height:50px' />";
                }
                else {
                    return "<img src='" + value + "' style='width:90px;height:50px' />";
                }
            }
            else {
                return value;
            }
        }

        $("#isShowPic").change(function () {
            isShowPic = $(this).attr("checked");
            $("#List").datagrid('reload');
        });


        function doAction(fieldName, state) {
            var row = $('#List').datagrid('getSelections');
            if (row.length == 0) {
                alert("请选择要修改的记录");
                return false;
            }

            var ids = ""; //不能赋值为null
            for (var i = 0; i < row.length; i++) {
                ids += row[i].ID + ",";
            }

            if (confirm("确定要修改选定的记录吗?")) {
                $.ajax({
                    type: "POST",
                    url: "/MyBlog/Article/ChangeState?state=" + state + "&fieldName=" + fieldName,
                    data: "ids=" + ids,
                    dataType: "text",
                    success: function (data) {
                        data = eval("(" + data + ")"); //转换为json对象
                        if (data.code == 1) {
                            //重新加载当前页
                            $("#List").datagrid('reload');
                            //清除所有选定
                            $('#List').datagrid('clearSelections');
                            $.messageBox5s('提示', "操作成功");
                        }
                        else {
                            $.messageBox5s('提示', "操作失败");
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("错误");
                        document.write(XMLHttpRequest.responseText);
                    }
                });
            }
        }

        $('#ddlBlogSelect').combobox({
            onSelect: function (record) {
                var url = '/MyBlog/Article/GetCategoryJson?blogID=' + $(this).combobox('getValue');
                $('#ddlcategorySelect').combobox({
                    valueField: 'categoryID',
                    textField: 'categoryDisplay',
                    url: url,
                    setValue: ''
                });

                $('#ddlTopicSelect').combobox({
                    valueField: 'topicID',
                    textField: 'topicDisplay',
                    url: '/MyBlog/Article/GetTopicJson?blogID=' + $(this).combobox('getValue'),
                    setValue: ''
                });
            }
        });

        $('#ddlBlogChange').combobox({
            onSelect: function (record) {
                var url = '/MyBlog/Article/GetCategoryJson?blogID=' + $(this).combobox('getValue');
                $('#ddlcategoryChange').combobox({
                    valueField: 'categoryID',
                    textField: 'categoryDisplay',
                    url: url,
                    setValue: ''
                });

                $('#ddlTopicChange').combobox({
                    valueField: 'topicID',
                    textField: 'topicDisplay',
                    url: '/MyBlog/Article/GetTopicJson?blogID=' + $(this).combobox('getValue'),
                    setValue: ''
                });
            }
        });

        $('#ddlcategoryChange').combobox({
            onSelect: function (record) {
                if ($(this).combobox('getValue') == "") {
                    alert("必须选择分类");
                    return false;
                }
                var row = $('#List').datagrid('getSelections');
                if (row.length == 0) {
                    alert("请选择要修改的记录");
                    return false;
                }

                var ids = ""; //不能赋值为null
                for (var i = 0; i < row.length; i++) {
                    ids += row[i].ID + ",";
                }

                // doAction("categoryID", $(this).combobox('getValue'));
                if (confirm("确定要修改选定的记录吗?")) {
                    $.ajax({
                        type: "POST",
                        url: "/MyBlog/Article/ChangeArticle?blogID=" + $('#ddlBlogChange').combobox('getValue') + "&categoryID=" + $(this).combobox('getValue'),
                        data: "ids=" + ids,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 1) {
                                //重新加载当前页
                                $("#List").datagrid('reload');
                                //清除所有选定
                                $('#List').datagrid('clearSelections');
                                $.messageBox5s('提示', "操作成功");
                            }
                            else {
                                $.messageBox5s('提示', "操作失败");
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert("错误");
                            document.write(XMLHttpRequest.responseText);
                        }
                    });
                }
            }
        });

        $('#ddlSiteCategoryChange').combobox({
            onSelect: function (record) {
                doAction("siteCategoryID", $(this).combobox('getValue'));
            }
        });

        $('#ddlTopicChange').combobox({
            onSelect: function (record) {
                doAction("topicID", $(this).combobox('getValue'));
            }
        });

        $("#btnTrue").click(function () {
            doAction("" + $("#ddlStateField").val() + "", '1');
        });
        $("#btnFalse").click(function () {
            doAction($("#ddlStateField").val(), '0');
        });
    });


    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    //iframe 返回并刷新
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    //输出信息
    function frameReturnByMes(mes) {
        $.messageBox5s('提示', mes);
    }

    function ShowCreateDialog() {
        window.open("/MyBlog/Article/Edit/0");
        //$("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/MyBlog/Article/Edit/0'></iframe>");
        //$("#modalwindow").window({ title: '新增', width: 700, height: 430, iconCls: 'icon-add' }).window('open');
    }

    function ShowUpdateDialog() {
        var row = $('#List').datagrid('getSelections');
        if (row.length == 0) {
            alert("请选择要删除的记录");
            return false;
        }
        else if (row.length > 1) {
            alert("不能同时编辑多行");
            return false;
        }
        else {
            window.open("/MyBlog/Article/Edit/" + row[0].ID);
            //$("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='/MyBlog/Article/Edit/" + row[0].ID + "'></iframe>");
            //$("#modalwindow").window({ title: '编辑', width: 700, height: 430, iconCls: 'icon-edit' }).window('open');
        }
    }

    function CreateCatelog() {
        var row = $('#List').datagrid('getSelections');
        if (row.length == 0) {
            alert("请选择要生成的文章");
            return false;
        }

        var ids = ""; //不能赋值为null
        for (var i = 0; i < row.length; i++) {
            ids += row[i].ID + ",";
        }

        if (confirm("确定要生成选定的文章目录吗?该目录将根据选定的顺序生成")) {
            $.ajax({
                type: "POST",
                url: "/MyBlog/Article/CreateCatelog",
                data: "ids=" + ids,
                dataType: "json",
                beforeSend: function () {
                    //showOverlay();
                },
                success: function (data) {
                    //hideOverlay();
                    if (data.code == 1) {
                        $.messageBox5s('提示', "生成成功");
                    }
                    else {
                        $.messageBox5s('提示', "生成失败");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //hideOverlay();
                    alert("错误");
                    document.write(XMLHttpRequest.responseText);
                }
            });
        }
    }

    function DeleteInfoByClick() {
        var row = $('#List').datagrid('getSelections');
        if (row.length == 0) {
            alert("请选择要删除的记录");
            return false;
        }

        var ids = ""; //不能赋值为null
        for (var i = 0; i < row.length; i++) {
            ids += row[i].ID + ",";
        }

        if (confirm("确定要删除选定的记录吗?")) {
            $.ajax({
                type: "POST",
                url: "/MyBlog/Article/Delete",
                data: "ids=" + ids,
                dataType: "text",
                beforeSend: function () {
                    //showOverlay();
                },
                success: function (msg) {
                    //hideOverlay();
                    data = eval("(" + msg + ")"); //转换为json对象
                    if (data.code == 1) {
                        //重新加载当前页
                        $("#List").datagrid('reload');
                        //清除所有选定
                        $('#List').datagrid('clearSelections');
                        $.messageBox5s('提示', "删除成功");
                    }
                    else {
                        $.messageBox5s('提示', "删除失败");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //hideOverlay();
                    alert("错误");
                    document.write(XMLHttpRequest.responseText);
                }
            });
        }
    }

    $(function () {
        $("#btnQuery").click(function () {
            $("#List").datagrid('clearChecked');
            $('#List').datagrid({
                url: '/MyBlog/Article/GetList?' + $("form").eq(0).serialize()
            });
        });
    });
</script>



上一篇:wordpress3.6 修改的地方

下一篇:个人代码全部开源


0 评论

查看所有评论

给个评论吧