share-manage.ctrl.js 24.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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
infrastructureModule.controller('shareManageController',
    ['$log', '$http', '$q', '$scope', '$translate', '$timeout', 'SweetAlert', '$compile', 'interactionService', '$filter',
        function ($log, $http, $q, $scope, $translate, $timeout, SweetAlert, $compile, interactionService, $filter) {

            $scope.localData = {};
            $scope.pagingOptions = {
                totalItems: 10,  //总数据
            };
            $scope.loadMainData = function () {

                var config = {
                    params: {}
                };
                interactionService.getMainList(config).then(function (data, status, headers) {
                    if (status === 204) {
                        SweetAlert.warning("没有数据");
                        return;
                    }
                    $scope.dataGridUpdate(data);
                })
            };
            $scope.dataGridUpdate = function (_data) {
                $scope.localData = _data;
                $scope.pagingOptions = {
                    totalItems: $scope.localData.length,  //总数据
                };

                $scope.dataGridOptions = {
                    // dataSource: {
                    //     store: $scope.localData.items,
                    //     reshapeOnPush: true
                    // },
                    bindingOptions: {
                        dataSource: 'localData',
                    },
                    // repaintChangesOnly: true,
                    // twoWayBindingEnabled: true,
                    showBorders: true,
                    paging: {
                        enable: true,
                        pageIndex: 0,
                        pageSize: 10
                    },
                    pager: {
                        allowedPageSizes: 5,
                        infoText: "当前 {0}页 /共 {1}页 ({2} 项)",
                        showInfo: true,
                        showNavigationButtons: true,
                        showPageSizeSelector: true,
                        visible: true
                    },
                    searchPanel: {//查询
                        highlightCaseSensitive: true,
                        highlightSearchText: true,
                        searchVisibleColumnsOnly: false,
                        text: "",
                        width: 518,
                        visible: true,
                        placeholder: $translate.instant('Search'),
                    },
                    sorting: {//排序
                        ascendingText: "Sort Ascending",
                        clearText: "Clear Sorting",
                        descendingText: "Sort Descending",
                        mode: "single"
                    },
                    'export': {
                        allowExportSelectedData: false,//允许选择导出
                        customizeExcelCell: null,
                        enabled: true,//允许导出
                        excelFilterEnabled: false,
                        excelWrapTextEnabled: false,
                        fileName: "shareManage",//名字
                        ignoreExcelErrors: true,

                    },
                    showRowLines: true,
                    columnAutoWidth: true,
                    allowColumnReordering: true,
                    columns: [
                        /*{
                            dataField: "id",
                            caption: $translate.instant('SequenceNumber'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {

                                    var style =  options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    if (options.data.id) {
                                        $('<span ' + style + '>').text(options.data.id).appendTo(container);
                                    } else {
                                        $('<span>').text("").appendTo(container);
                                    }
                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },*/
                        {
                            dataField: "title",
                            caption: $translate.instant('ShareTitle'),
                            show: false,
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {

                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    if (options.data.title) {
                                        $('<span ' + style + '>').text(options.data.title).appendTo(container);
                                    } else {
                                        $('<span>').text("").appendTo(container);
                                    }
                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "type",
                            caption: $translate.instant('ShareType'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {

                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    $('<span ' + style + '>').text($scope.emailType(options.data.type)).appendTo(container);

                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },

                        {
                            dataField: "url",
                            caption: $translate.instant('url'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {

                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    if (options.data.url) {
                                        $('<span ' + style + '>').text(options.data.url).appendTo(container);
                                    } else {
                                        $('<span>').text("").appendTo(container);
                                    }
                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "createBy",
                            caption: $translate.instant('Creator'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {
                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    if (options.data.createBy) {
                                        $('<span ' + style + '>').text(options.data.createBy).appendTo(container);
                                    } else {
                                        $('<span>').text("").appendTo(container);
                                    }
                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "createTime",
                            caption: $translate.instant('CreatedTime'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {

                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    if (options.data.createTime) {
                                        $('<span ' + style + '>').text($filter('date')(options.data.createTime, 'yyyy-MM-dd')).appendTo(container);
                                    } else {
                                        $('<span>').text('').appendTo(container);
                                    }
                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "essenceFlag",
                            caption: $translate.instant('IsEssence'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {
                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';
                                    $('<span ' + style + '>').text($scope.flagType(options.data.essenceFlag)).appendTo(container);

                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "topFlag",
                            caption: $translate.instant('IsTop'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {
                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';

                                    $('<span ' + style + '>').text($scope.flagType(options.data.topFlag)).appendTo(container);

                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "delFlag",
                            caption: $translate.instant('IsDisplay'),
                            allowHeaderFiltering: true,
                            cellTemplate: function (container, options) {
                                try {
                                    var style = options.data.essenceFlag == 1 ? '' : 'style="color:#999"';

                                    $('<span ' + style + '>').text($scope.delType(options.data.delFlag)).appendTo(container);

                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                        {
                            dataField: "operation",
                            caption: $translate.instant('Operation'),
                            allowHeaderFiltering: false,
                            cellTemplate: function (container, options) {
                                try {
                                    var eventTarget = $('<a style="color:#506bf7;" data-id="' + options.data.id + '" href="javascript:void(0)"><span>' + $translate.instant("Edit") + '</span></a><span style="width: 10px;display: inline-block"></span>');
                                    eventTarget.off('click').on('click', function () {
                                        $scope.openEditPop(options.data.id);
                                    });
                                    eventTarget.appendTo(container);
                                    var eventTargetDel = $('<a style="color:#506bf7;" data-id="' + options.data.id + '" href="javascript:void(0)"><span>' + $translate.instant("cellCommentDelete") + '</span></a><span style="width: 10px;display: inline-block"></span>');
                                    eventTargetDel.off('click').on('click', function () {
                                        $scope.deleteShare(options.data.id);
                                    });
                                    eventTargetDel.appendTo(container);
                                } catch (e) {
                                    $log.error(e);
                                }
                            }
                        },
                    ],
                    rowAlternationEnabled: false  //单双行颜色
                };
            };
            $scope.getTableHeight = function () {
                var row_height = $("table").find("tr").height();
                if (row_height) {
                    return {
                        height: (row_height * 12 + 100) + "px"
                    }
                }
            };

            $scope.flagType = function (type) {
                if (type == 1) {
                    return "是";
                } else {
                    return "否";
                }
            };

            $scope.delType = function (type) {
                if (type == 1) {
                    return "不显示";
                } else {
                    return "显示";
                }
            };

            $scope.emailType = function (type) {
                if (type == 0) {
                    return "手动添加";
                } else {
                    return "从邮箱获取";
                }
            };
            //取消
            var cancelDocFileType = function () {
                console.log("cancelDocFileType")
            };

            $scope.editModel = {
                "id": null,//主键id
                "essenceFlag": null,
                "topFlag": null,
                "delFlag": null,

            };
            //----------------------kevin insert -------------------------------
            $scope.operation = {};
            $scope.editor1 = "editor1";
            $scope.addShare = function () {
                endProcess();
                $scope.operation.flag = constant.shareTypeFlag.addShare;
                $scope.operation.type = 0;//新建税享
                if ($scope.$editor == undefined) {
                    $scope.$editor = $scope.editorInit('editor1', 0);
                }
                $('#addShareModal').modal();
311
            };
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
            $scope.openEditPop = function (rowId) {
                endProcess();
                if ($scope.$editor == undefined) {
                    $scope.$editor = $scope.editorInit('editor1', 0);
                }
                $scope.operation.flag = constant.shareTypeFlag.editShare;
                $scope.operation.type = 1;//编辑税享
                interactionService.getShareDataById(rowId).success(function (res) {
                    if (res.data) {
                        $scope.share = res.data;
                        checkboxConvert.come(res.data);
                        $scope.richText.write($scope.share.content);
                    } else {
                        SweetAlert.error(res.resultMsg);
                    }
                    $('#addShareModal').modal();
                });
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

            $scope.submit = function (type) {
                if (!$scope.share.title) {
                    SweetAlert.warning("验证", "标题不能为空");
                    $('#title').focus();

                    return false;
                }
                if ($scope.richText.read().length <= 11) {
                    SweetAlert.info("至少输入5个字");
                    return false;
                }
                if (!$scope.share.tag) {
                    SweetAlert.warning("验证", "标签不能为空");
                    $('#tag').focus();
                    return false;
                }
                SweetAlert.swal({
                        title: '提示',
                        text: '请确认是否包含不允许上传的政策法规或公司涉密信息',
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: $translate.instant('Confirm'),
                        cancelButtonText: $translate.instant('Cancel'),
                        closeOnConfirm: false,
                        closeOnCancel: true
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            $('#addShareModal').modal('hide');
                            if (type == 0) {//新增
                                var share = {
                                    title: $scope.share.title,
                                    tag: $scope.share.tag,
                                    topFlag: $scope.share.topFlag == true ? 1 : 0,
                                    content: $scope.richText.read(),
                                    delFlag: $scope.share.delFlag == true ? 1 : 0,
                                    essenceFlag: $scope.share.essenceFlag == true ? 1 : 0,
                                    type: 1,
                                };
                                interactionService.addShareHandle(share).success(function (res) {
                                    if (res.result == true) {
373
                                        SweetAlert.success(res.data);
374 375 376 377 378 379 380 381 382
                                        swal.close();
                                        $scope.loadMainData();
                                    } else {
                                        SweetAlert.error(res.resultMsg);
                                    }
                                })
                            } else {//编辑
                                $scope.share.content = $scope.richText.read();
                                var copyShare = angular.copy($scope.share);
383
                                checkboxConvert.to(copyShare);
384 385 386 387
                                delete copyShare.createTime;
                                delete copyShare.updateTime;
                                interactionService.editShareHandle(copyShare).success(function (res) {
                                    if (res.result == true) {
388
                                        SweetAlert.success(res.data);
389 390 391 392 393 394 395 396 397 398 399 400
                                        swal.close();
                                        $scope.loadMainData();
                                    } else {
                                        SweetAlert.error(res.resultMsg);
                                    }
                                });
                            }
                        } else {
                            swal.close();
                        }
                    });

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
            //选择框的问题
            var checkboxConvert = {
                come: function (data) {
                    if (data.delFlag == 1) {
                        $scope.share.delFlag = true;
                    } else {
                        $scope.share.delFlag = false;
                    }
                    if (data.essenceFlag == 1) {
                        $scope.share.essenceFlag = true;
                    } else {
                        $scope.share.essenceFlag = false;
                    }
                    if (data.topFlag == 1) {
                        $scope.share.topFlag = true;
                    } else {
                        $scope.share.topFlag = false;
                    }
                },
                to: function (copyShare) {
                    if ($scope.share.delFlag == true) {
                        copyShare.delFlag = 1;
                    } else {
                        copyShare.delFlag = 0;
                    }
                    if ($scope.share.essenceFlag == true) {
                        copyShare.essenceFlag = 1;
                    } else {
                        copyShare.essenceFlag = 0;
                    }
                    if ($scope.share.topFlag == true) {
                        copyShare.topFlag = 1;
                    } else {
                        copyShare.topFlag = 0;
                    }
                }
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

            $scope.deleteShare = function (id) {
                SweetAlert.swal({
                        title: '确定删除吗?',
                        text: '',
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: $translate.instant('Confirm'),
                        cancelButtonText: $translate.instant('Cancel'),
                        closeOnConfirm: false,
                        closeOnCancel: true
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            interactionService.deleteShareDataById(id).success(function (res) {
                                if (res.result == true) {
                                    $scope.loadMainData();
                                    SweetAlert.success($translate.instant('DeleteSuccess'));
                                } else {
                                    SweetAlert.error(res.resultMsg);
                                }
                            });
                        } else {
                            swal.close();
                        }
                    });
466
            };
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

            //标签
            function pwcTag(id, tagname, visible) {
                this.tagname = tagname;
                this.id = id,
                    this.visible = visible != undefined ? visible : false;
            }

            //整合数据
            var endProcess = function () {
                $scope.share = {};
                //加标签数据
                interactionService.getTagList(1).then(function (data, status, headers) {
                    if (data.data != null) {
                        var data = data.data;
                        $scope.shareTag = [];
                        data.forEach(function (value, i) {
                            $scope.shareTag.push(new pwcTag(value.id, value.tagname));
                        });
                    } else {
                        SweetAlert.error("加载标签列表失败");
                    }
489
                });
490 491 492 493 494
                $scope.tagSet = false;
                $scope.tagOperation = "添加标签";
                if ($scope.richText != undefined) {
                    $scope.richText.write('');
                }
495
            };
496 497
            var initModalStyle = function () {
                $('#modalStyle').width(window.screen.width - 300);
498
            };
499 500
            $scope.changeSheet = function (item) {
                $scope.share.tag = item;
501
            };
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
            $scope.share = {};
            $scope.createTag = function () {
                if ($scope.tagSet == false || $scope.tagSet == undefined) {
                    $scope.tagSet = true;
                    $("#tagInput").show();
                    $scope.tagOperation = "确定";
                } else {
                    if ($scope.share.addTag == "" || $scope.share.addTag == null || $scope.share.addTag == undefined) {
                        SweetAlert.info("输入标签不能为空");
                        return false;
                    }
                    interactionService.addTagSubmit($scope.share.addTag, 1).then(function (data, status, headers) {
                        if (data.resultMsg = "success") {
                            $scope.shareTag.push(new pwcTag(new Date().getTime(), $scope.share.addTag));
                            $scope.share.addTag = '';
                        } else {
                            SweetAlert.error("标签添加失败");
                        }
                        $scope.tagSet = false;
                        $scope.tagOperation = "添加标签";
                        $("#tagInput").hide();
                    })
                }
525
            };
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540


            var checkUserPermission = function () {

                var list = [];
                $scope.hasTagPermission = false;
                var temp = constant.InteractionPermission;
                list.push(temp.tagOperate.code);
                $scope.$root.checkUserPermissionList(list).success(function (data) {
                    $scope.hasTagPermission = data[temp.tagOperate.code];
                });
            };


            //----------------------insert end -------------------------------
541
            (function initialize() {
542 543 544 545 546 547 548
                $scope.loadMainData();
                initModalStyle();
                checkUserPermission();
                //注册方法
                $scope.cancelDocFileType = cancelDocFileType;
            })();
        }]);