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

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开发系列(十一)-后记

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
@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 评论

查看所有评论

给个评论吧