link.ctrl.js 14.8 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 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
infrastructureModule.controller('linkController',
    ['$log', '$http', '$q', '$scope', '$translate', '$timeout', 'SweetAlert', '$compile', 'interactionService', '$filter', 'apiInterceptor', 'jqFetch',
        function ($log, $http, $q, $scope, $translate, $timeout, SweetAlert, $compile, interactionService, $filter, apiInterceptor, jqFetch) {

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

            $scope.loadMainData = function () {
                var config = {
                    params: {}
                };
                interactionService.getLinkList(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: "title",
                            caption: $translate.instant('ContentTitle'),
                            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: "url",
                            caption: $translate.instant('LinkChoice'),
                            show: false,
                            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: "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);
                                    });
                                    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.deleteLink(options.data);
                                    });

                                    eventTarget.appendTo(container);
                                    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.addLink = function () {

                $scope.moduleTitle=$translate.instant('addLink');
                $scope.editType = 0;
                $scope.title = '';
                $scope.url = '';
                $('#postMessage').modal();

            }

            //修改
            var editTaxManage = function (item) {
                $scope.moduleTitle=$translate.instant('editLink');
                jqFetch.get(apiInterceptor.webApiHostUrl + '/Link/' + item.id).then(
                    function (data, status, headers) {


                        $scope.title = data.data.title;
                        $scope.url = data.data.url;
                        $scope.editType = 1;
                        $scope.LinkId = data.data.id;
                        $('#postMessage').modal();
                    })


            };

            //新增或者修改
            var postMessageSubmit = function () {
                if ($scope.title == undefined || $scope.title == '') {
                    SweetAlert.info("请输入标题");
                    return false;
                }
                if ($scope.url == undefined || $scope.url == '') {
                    SweetAlert.info("请输入链接");
                    return false;
                }
                var message = {
                    title: $scope.title,
                    url: $scope.url
                }
                if ($scope.editType == 0) {
                    jqFetch.post(apiInterceptor.webApiHostUrl + '/Link/add', message).then(
                        function (data, status, headers) {
                            if (status === 204) {
                                SweetAlert.warning("没有数据");
                                return;
                            }
                            $scope.title = '';
                            $scope.url = '';
                            $scope.loadMainData();
                        })
                }
                else if ($scope.editType == 1) {
                    message.id = $scope.LinkId;
                    jqFetch.post(apiInterceptor.webApiHostUrl + '/Link/edit', message).then(
                        function (data, status, headers) {
                            if (status === 204) {
                                SweetAlert.warning("没有数据");
                                return;
                            }
                            $scope.title = '';
                            $scope.url = '';
                            $scope.loadMainData();
                        })
                }

            };

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

            //删除
            $scope.deleteLink = function (item) {

                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) {
                            var message = {};
                            jqFetch.post(apiInterceptor.webApiHostUrl + '/Link/delete/' + item.id, message).then(
                                function (data, status, headers) {
                                    if (data.code == -1) {
                                        SweetAlert.warning("删除失败");
                                        return;
                                    }
                                    swal.close();
                                    $scope.loadMainData();
                                });
                        } else {
                            swal.close();
                        }
                    });
            }


            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];
                    });
                }


            ;(function initialize() {
                $scope.editTaxManage = editTaxManage;
                $scope.loadMainData();
                checkUserPermission();
                $scope.postMessageSubmit = postMessageSubmit;
                //注册方法
                $scope.openEditPop = editTaxManage;
            })();
        }]);