newsfeedApp.controller('newsfeedCtrl', function($scope, $ionicLoading, $ionicScrollDelegate, $timeout, $interval, //
    $cordovaToast, Newfeeds, Newfeedtypes, Users, Settings, dataHtml,Feedtiltles,Login) {
    ionicLoading = $ionicLoading;
    $scope.tier = tier;
    $scope.currentIdLogin = currentIdLogin;
    $scope.currentPage = 1;
    var pager = localStorage.getItem('newfeeds_pagesize');
    $scope.itemsPerPage = 50;
    $scope.entryLimit = $scope.itemsPerPage;
    $scope.searchNewfeeds = {
        rowspin: 0,
        rowsunpin: 0,
        current_page: $scope.currentPage,
        search: ""
    };
    $scope.Loading_data = false;
    $scope.Loading_data_star = true;
    $scope.dataComment = {};
    $scope.userLikeList = {};
    $scope.roleName = role;
    $scope.isAdmin = isAdmin;
    $scope.isManager = isManager;
    $scope.isReporter = isReporter;
    $scope.isScheduler = isScheduler;
    $scope.isFieldinstaller = isFieldinstaller;
    $scope.isSalesman = isSalesman;
    $scope.isWarehouse = isWarehouse;
    $scope.check_init_newfeed = false;
    $scope.tabNewsfeedsActive = 'Feeds';
    $scope.feedTitleVal = '';
    $scope.idRestore = [];
    $scope.dataHtml = {};
    $scope.renderTemplateData = function() {
        dataHtml.getTemplate('templates/dashboard/newsfeeds/newsfeedsHeadermodal.tpl').success(function(results) {
            $scope.dataHtml.menuHeader = results;
            dataHtml.getTemplate('templates/dashboard/newsfeeds/newsfeedsTabMenumodal.tpl').success(function(results) {
                $scope.dataHtml.tabMenu = results;
                dataHtml.getTemplate('templates/dashboard/newsfeeds/tabs/newsfeedsTabsFeedPinnedmodal.tpl').success(function(results) {
                    $scope.dataHtml.newsfeedPinned = results;
                    dataHtml.getTemplate('templates/dashboard/newsfeeds/tabs/newsfeedsTabsFeedmodal.tpl').success(function(results) {
                        $scope.dataHtml.newsfeedUnpin = results;
                        dataHtml.getTemplate('templates/dashboard/newsfeeds/popups/newsfeedsPopupSearchmodal.tpl').success(function(results) {
                            $scope.dataHtml.searchNewsfeeds = results;
                            $scope.getUserLogin();
                        });
                    })
                })
            })
        });
    }
    $scope.openByGetTemplate = function(style) {
        $ionicLoading.show({ template: templateLoading });
        $timeout(function() {
            switch (style) {
                case 'formAddNewsFeeds':
                dataHtml.getTemplate('templates/dashboard/newsfeeds/forms/newsfeedsFormAddmodal.tpl').success(function(results) {
                    $scope.dataHtml.formAddNewsFeeds = results;
                    $scope.showTarget('#formAddNewsFeeds');
                    $ionicLoading.hide();
                });
                break;
            }
        });
    }
    $scope.redirectTo = function(url) {
        $ionicLoading.show({ template: templateLoading });
        $timeout(function() {
            redirectTo(url);
        }, 1000)
    }
    $scope.redirectToChat = function(id) {
        if (parseInt(id) != parseInt($scope.currentIdLogin)) {
            $ionicLoading.show({ template: templateLoading });
            $timeout(function() {
                redirectTo('chat.html#/board/chat/'+id+'_');
            }, 1000)
        }
    }
    $scope.setTabNewsfeeds = function(tab) {
        $scope.tabNewsfeedsActive = tab;
    }
    $scope.getNewfeedtypes = function() {
        $ionicLoading.show({ template: templateLoading });
        Newfeedtypes.getSelect().success(function(data) {
            if (!startpage) $ionicLoading.hide();
            $scope.newfeedtypes = data;
            $scope.getFeedtitles();
        });
    }
    searchNewsfeedHandle();

    function searchNewsfeedHandle() {
        toggleDelegateHandle('#newsfeedpage', '.link-newsfeed-search', '.newsfeed-search');
        toggleDelegateHandle('#newsfeedpage', '.newsfeed-search .search-type .btn-close', '.newsfeed-search');
        toggleDelegateHandle('#newsfeedpage', '.newsfeed-search .search-content .btn-close', '.newsfeed-search');
        closeOutsideHandle('.link-newsfeed-search, .newsfeed-search', '.newsfeed-search');
    }
    

    $scope.clearSearch = function() {
        $scope.searchNewfeeds.search = '';
        $scope.getNewfeeds();
    }

    $scope.$on('$stateChangeSuccess', function() {
        if (!startpage) $scope.getNewfeeds();
        startpage = false;
    });

    $scope.getNewfeeds = function() {
        $ionicLoading.show({
            template: templateLoading
        });
        Newfeeds.getPaging(currentIdLogin, $scope.searchNewfeeds).success(function(data) {  
            if(data.status == false){
                $cordovaToast.showLongCenter(data.msg);
            }
            else{
                $scope.newfeeds = data.data;
                $scope.newfeedpin = data.pin;
                $scope.searchNewfeeds.rowspin = data.rowspin;
                $scope.searchNewfeeds.rowsunpin = data.rowsunpin;
                if ($scope.newfeeds.length + $scope.newfeedpin.length < data.total_rows) {
                    $timeout(function() {
                        $scope.Loading_data_star = true;
                        $scope.Loading_data = true;
                    }, 2000);
                }
                $ionicScrollDelegate.$getByHandle('scrollNewsfeeds').scrollTop(true);
                $ionicScrollDelegate.$getByHandle('scrollNewsfeeds').resize;
                $scope.closeTarget(".newsfeed-search");
                $("#searchInput").blur();
                $ionicLoading.hide();
                startpage = false;
            }

        });
    };
    $scope.LoadMoreNewfeed = function() {
        if(!$scope.Loading_data){
            return false;
        }
        $scope.searchNewfeeds.current_page++;
        Newfeeds.getPaging(currentIdLogin, $scope.searchNewfeeds).success(function(data) {
            if(data.data.length == 0){
                $scope.Loading_data_star = false;
                $scope.Loading_data = false;
            }
            $scope.newfeeds = _.union($scope.newfeeds, data.data);
            $scope.newfeedpin = _.union($scope.newfeedpin, data.pin);
            $scope.searchNewfeeds.rowspin = data.rowspin;
            $scope.searchNewfeeds.rowsunpin = data.rowsunpin;
            if ($scope.newfeeds.length + $scope.newfeedpin.length >= data.total_rows) {
                $scope.Loading_data_star = false;
                $scope.Loading_data = false;
            }
        })
        $timeout(function() {
            $scope.$broadcast('scroll.infiniteScrollComplete');
        }, 2000);
    }
    $scope.keypress = function($event) {
        var keysByCode = [9, 16, 17, 18, 20, 27, 32, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 91, 144];
        if ($event.keyCode >= 112 && $event.keyCode <= 123) return;
        if (keysByCode.indexOf($event.keyCode) > -1) return;
        $scope.coundown = 10;
        if ($scope.myTime != null) clearInterval($scope.myTime);
        $scope.downTimer();
    };
    $scope.downTimer = function() {
        $scope.myTime = setInterval(function() {
            $scope.coundown--;
            if ($scope.coundown <= 0) {
                clearInterval($scope.myTime);
                $scope.Loading_data = false;
                $scope.Loading_data_star = true;
                $scope.searchNewfeeds.rowspin = 0;
                $scope.searchNewfeeds.rowsunpin = 0;
                $scope.searchNewfeeds.current_page = 1;
                $scope.newfeeds = [];
                $scope.newfeedpin = [];
                $scope.getNewfeeds();
            }
        }, 100);
    }

    $scope.searchChanged = function() {
        $scope.getNewfeeds();
    }
    $scope.rendernewfeed = function() {
        Newfeeds.rendernewfeed().success(function(data) {
            $scope.getNewfeeds();
        });
    }

    $scope.sizeChanged = function() {
        $scope.searchNewfeeds.rows = $scope.entryLimit;
        newfeeds_pagesize.val($scope.searchNewfeeds.rows);
        localStorage.setItem('newfeeds_pagesize', $scope.searchNewfeeds.rows);
        $scope.searchNewfeeds.current_page = 1;
        $scope.getNewfeeds();
    }
    $scope.pageChanged = function() {
        $scope.searchNewfeeds.current_page = $scope.currentPage;
        $scope.getNewfeeds();
    };
    $scope.setPage = function(pageNo) {
        $scope.currentPage = pageNo;
        console.log('doi page');
    };
    $scope.addNewfeedsData = {};
    $scope.createNewfeeds = function() {
        Newfeeds.save($scope.addNewfeedsData).success(function(data) {
            $scope.addNewfeedsData = {};
            // $scope.getNewfeeds();
            if (data.status) {
                toastr.success(data.msg);
            } else {
                toastr.error(data.msg);
            }
        });
    }
    $scope.editNewfeedsData = {};
    $scope.editNewfeeds = function(id) {
        Newfeeds.show(id).success(function(data) {
            $scope.editNewfeedsData = data;
        });
    }
    $scope.updateNewfeeds = function() {
        var id = $scope.editNewfeedsData.id;
        Newfeeds.update(id, $scope.editNewfeedsData).success(function(data) {

            if (data.status) {
                $scope.editNewfeedsData = {};
                //$('#modal_edit_newfeeds').modal('hide');
                toastr.success(data.msg);
            } else {
                toastr.error(data.msg);
            }
            // $scope.getNewfeeds();
        });
    }
    $scope.pindisable = false;
    $scope.pin_unpin = function(item) {
        if (!$scope.pin_quest) {
            // $scope.pin_quest = true;
            $ionicLoading.show({ template: templateLoading })
            Newfeeds.pin_unpin(item.id, $scope.currentIdLogin, (item.pin == 0 ? "1" : "0")).success(function(data) {
                $ionicLoading.hide();
                if (data.status) {
                    if (item.pin == 0 || item.pin == '0') {
                        item.pin = '1';
                        $scope.newfeedpin.push(item);
                        $scope.newfeeds = _.without($scope.newfeeds, _.findWhere($scope.newfeeds, {
                            id: item.id
                        }));
                        $scope.idRestore.push(item);
                    } else {
                        item.pin = '0';
                        $scope.newfeeds.push(item);
                        $scope.newfeedpin = _.without($scope.newfeedpin, _.findWhere($scope.newfeedpin, {
                            id: item.id
                        }));
                    }
                } else {
                    // toastr.error(data.msg);
                }
                $scope.pin_quest = false;
                //$scope.getNewfeeds();
            });
        }
    }
    $scope.AddUserNewFeed = {};
    $scope.initialUsers = [];
    $scope.CreateUserNewFeed = function(form) {
        if ($scope.newfeedsvalidate()) {
            $scope.AddUserNewFeed.userSendfeed = arrayUnion($scope.AddUserNewFeed.users, $scope.AddUserNewFeed.usersdepartment, function(item1, item2) {
                return item1.id == item2.id;
            });
            if ($scope.AddUserNewFeed.userSendfeed.length > 0 || $scope.AddUserNewFeed.sendall == true) {
                $ionicLoading.show({ template: templateLoading });
                Settings.saveusernewfeed($scope.AddUserNewFeed, $scope.currentIdLogin).success(function(data) {
                    $ionicLoading.hide();
                    if (data.status) {
                        $scope.AddUserNewFeed = {};
                        $scope.initialDeparment = [];
                        $scope.initialUsers = [];
                        $scope.AddUserNewFeed.users = [];
                        $scope.AddUserNewFeed.usersdepartment = [];
                        $scope.closeTarget('#formAddNewsFeeds');
                        $scope.feedTitleVal = '';
                        $cordovaToast.showLongTop(data.msg);
                        $scope.searchNewfeeds.rowspin = 0;
                        $scope.searchNewfeeds.rowsunpin = 0;
                        $scope.searchNewfeeds.current_page = 1;
                        $scope.getNewfeeds();
                    } else {
                        $cordovaToast.showLongTop(data.msg);
                    }
                });
            } else {
                $cordovaToast.showLongTop('Not Null Send to');
            }
        }
    }

    $scope.newfeedsvalidate = function() {
        if (!$scope.AddUserNewFeed.feed_title) {
            $cordovaToast.showLongTop('Please select Feed Title');
            return false;
        }
        if (!$scope.AddUserNewFeed.message) {
            $cordovaToast.showLongTop('Please fill Message field');
            return false;
        }
        return true;
    }
    $scope.address = {};
    $scope.AddUserNewFeed.users = [];
    $scope.refreshAddresses = function(address) {
        if (address.length > 0) {
            var params = {
                search: address
            };
            Users.searchAssign(params).success(function(data) {
                var diff = differentArray(data, $scope.AddUserNewFeed.users);
                $scope.addresses = diff;
            })
        }
    };
    $scope.Departmentselect = '';
    $scope.getalldepartments = function() {
        $ionicLoading.show({ template: templateLoading })
        Newfeeds.getdepartment().success(function(data) {
            if (!startpage) $ionicLoading.hide();
            $scope.departmentdata = data;
            $scope.getNewfeedtypes();
        });
    }

    $scope.AddUserNewFeed.usersdepartment = [];
    $scope.initialDeparment = [];
    $scope.departments = [];
    $scope.getdataInDepartment = function(department_id) {
        var curr = _.find($scope.departmentdata, { id: department_id });
        if (!curr) {
            $scope.department_name = 'Select Department';
            $scope.initialDeparment = [];
            return;
        } else {
            $scope.department_name = curr.name;
        }
        Newfeeds.getdataInDepartment(department_id).success(function(data) {
            $scope.initialDeparment = _.pluck(data, 'id');
            $scope.departments = data;
        });

    }
    $scope.checksendall = function(all) {
        if (all) {
            $('.select2').hide();
        } else {
            $('.select2').show();
        }
    }
    $scope.deleteNewfeedsData = {};
    $scope.confrimNewfeeds = function(id, title, content) {
        $scope.deleteNewfeedsData = {
            id: id
        };
        var confirm = $.confirm(title, '<div class="text-content baseline">' + content + '</div>', {
            messageType: 'warning',
            titleIcon: 'remove',
            overlayTransparent: .75
        }, function() {
            $scope.deleteNewfeeds(id, confirm);
        });
    }
    $scope.deleteNewfeeds = function(id, confirm) {
        Newfeeds.destroy(id).success(function(data) {
            $scope.deleteNewfeedsData = {};
            if (data.status) {
                $.notification('<div class="text-content">' + data.msg + '</div>', {
                    messageType: 'message-success',
                    autoClose: true
                });
                confirm.switchStateDialog("close");
            } else {
                $.notification('<div class="text-content">' + data.msg + '</div>', {
                    messageType: 'message-success',
                    autoClose: true
                });
                confirm.switchStateDialog("close");
            }
            // $scope.getNewfeeds();
        });
    }
    $scope.getUserLogin = function() {
        return Login.getUserLogin().success(function(data) {
            if (data == false) {
                localStorage.setItem("login_status", "1");
                redirectTo('index.html');
            } else {
                // console.log(data)
                var index = _.findIndex(data.jsondata,{roletree_id:'81'});
                if(data.jsondata[index].check){
                    $scope.viewFeed = data.jsondata[index].child[0].check;
                    $scope.likeComment = data.jsondata[index].child[1].check;
                    $scope.pinUnpinButton = data.jsondata[index].child[2].check;
                    $scope.searchFeeds = data.jsondata[index].child[3].check;
                    $scope.buttonSendnewfeed = data.jsondata[index].child[4].check;
                    $scope.imagePath = pathToPublic + data.image_pic;
                    var displayname = (data.first_name != null ? data.first_name : '') + ' ' + (data.last_name == null ? '' : data.last_name);
                    if ($.trim(displayname) == "") {
                        $scope.displayname = "Hello, " + data.email;
                    } else {
                        $scope.displayname = "Hello, " + displayname;
                    }
                    $scope.getalldepartments();
                }else{
                    localStorage.setItem("login_status", "0");
                    redirectTo('index.html');
                }
            }
        });
    }
    $scope.checkAction = function(data, type, idx) {
        if (data.likeThis) {
            $scope.unLike(data.id, type, idx);
        } else {
            $scope.like(data.id, type, idx);
        }
    }
    $scope.like = function(id, type, idx) {
        $ionicLoading.show({ template: templateLoading })
        Newfeeds.likeNewfeed(id).success(function(data) {
            $ionicLoading.show();
            if (data.status) {
                $scope.countLikeById(id, type, idx);
            } else {
                $cordovaToast.showLongTop(data.msg);
            }
        });
    }
    $scope.unLike = function(id, type, idx) {
        $ionicLoading.show({ template: templateLoading });
        Newfeeds.unLikeNewfeed(id).success(function(data) {
            $ionicLoading.hide();
            if (data.status) {
                $scope.countLikeById(id, type, idx);
            } else {
                $cordovaToast.showLongTop(data.msg);
            }
        });
    }
    $scope.countLikeById = function(id, type, idx) {
        $ionicLoading.show({ template: templateLoading })
        Newfeeds.countLikeById(id).success(function(data) {
            $ionicLoading.hide();
            if (type == 'pin') {
                $scope.newfeedpin[idx].likeThis = data.meLiKeThis;
                $scope.newfeedpin[idx].countLike = data.count;
            } else {
                $scope.newfeeds[idx].likeThis = data.meLiKeThis;
                $scope.newfeeds[idx].countLike = data.count;
            }
            if ($scope.userLikeList) {
                $scope.showliker(idx, type);
            }
        });
    }
    $scope.showliker = function(idx, type) {
        if (type == 'pin') {
            var id = $scope.newfeedpin[idx].id;
            $scope.userLikeList.title = $scope.newfeedpin[idx].title;
            $scope.userLikeList.likeThis = $scope.newfeedpin[idx].likeThis;
            $scope.userLikeList.id = $scope.newfeedpin[idx].id;
        } else {
            var id = $scope.newfeeds[idx].id;
            $scope.userLikeList.title = $scope.newfeeds[idx].title;
            $scope.userLikeList.likeThis = $scope.newfeeds[idx].likeThis;
            $scope.userLikeList.id = $scope.newfeeds[idx].id;
        }
        $scope.userLikeList.type = type;
        $scope.userLikeList.idx = idx;
        $ionicLoading.show({ template: templateLoading })
        Newfeeds.listLikeById(id).success(function(result) {
            $ionicLoading.hide();
            $scope.userLikeList.data = result.userLikeList;
            // console.log($scope.userLikeList);
        });
    }
    $scope.setEventShowUserLike = function() {
        setTimeout(function() {
            $('#tableNewfeeds .likeArea > .icon').toggleShow('.option-pop-1', {
                effect: 'fade',
                outcollapse: true
            });

        }, 10);
    }

    $scope.comment = function(dataComment, content) {
        if (content) {
            var data = {};
            data.newfeed_id = dataComment.feedID;
            data.contents = content;
            $ionicLoading.show({ template: templateLoading })
            Newfeeds.comment(data).success(function(data) {
                $ionicLoading.hide();
                if (data.status) {
                    $scope.dataComment.data = data.data;
                    if (dataComment.type == 'newfeeds') {
                        $scope.newfeeds[dataComment.idx].dataComment = data.data;
                    } else {
                        $scope.newfeedpin[dataComment.idx].dataComment = data.data;
                    }
                    $scope.contentComment = '';
                    $("#contentComment").val('');
                }
            });
        }
    }

    $scope.logout = function() {
        return Login.logout().success(function(data) {
            $window.location.href = url_login;
        });
    }
    $scope.checkLogin = function() {
        return Login.checkLogin().success(function(data) {
            if (data.status == false) {
                $window.location.href = url_login;
            } else {
                //$scope.getUserLogin();
            }
        });
    }

    // by sinhdang
    // if ((window.location.pathname).substring((window.location.pathname).lastIndexOf('/') + 1) == 'newfeeds.html') {
    //     $scope.limitLoad = true;
    //     $scope.$on('$includeContentLoaded', function() {
    //         if ($scope.limitLoad) {
    //             $scope.getUserLogin();
    //             $scope.limitLoad = false;
    //         }
    //     });
    // }

    /* items-clicked-method="onSelectDepartUser(callback)"
                                items-removed-method="onRemoveDepartUser(callback)"  
                                items-method="filterDepartUser(query)" */

                                $scope.filterDepartUser = function(query) {
                                    var returnValue = {
                                        items: [],
                                        selectedItems: []
                                    };

        // if (!angular.isArray(query) && query.length > 0) {
            if (!angular.isArray(query)) {
                var params = {
                    search: query
                };
                Users.searchAssign(params).success(function(data) {
                    $scope.searchDUsers = data;
                    $scope.searchDUsers.forEach(function(item) {
                        if (_.indexOf($scope.AddUserNewFeed.usersdepartment, item.id) == -1)
                            returnValue.items.push(item);
                    });

                })
            }
            return returnValue;
        }

        $scope.modelToItemMethod = function(modelValue) {
            for (var i = 0; i < $scope.departments.length; i++) {
                if ($scope.departments[i].id == modelValue) {
                    return $scope.departments[i];
                }
            }
        };

        $scope.modelToItemMethodUser = function(modelValue) {};

        $scope.clickedDepartUser = "";
        $scope.removedDepartUser = "";
        $scope.onSelectDepartUser = function(callback) {
            $scope.clickedDepartUser = callback;
        }

        $scope.onRemoveDepartUser = function(callback) {
            $scope.removedDepartUser = callback;
        }

        $scope.filterNewfeedsUser = function(query) {
            var returnValue = {
                items: []
            };
        // if (query.length > 0) {
            var params = {
                search: query
            };
            Users.searchAssign(params).success(function(data) {
                $scope.searchUsers = data;
                $scope.searchUsers.forEach(function(item) {
                    if (_.indexOf($scope.AddUserNewFeed.users, item.id) == -1)
                        returnValue.items.push(item);
                });

            })
            // }
            return returnValue;
        }
        $scope.clickedUser = "";
        $scope.removedUser = "";
        $scope.onNewfeedSelectUser = function(callback) {
            $scope.clickedUser = callback.item;
        }
        $scope.onNewfeedRemoveUser = function(callback) {
            $scope.removedUser = callback;
        }
        $scope.restorePin = function() {
            if ($scope.idRestore.length > 0) {
                $scope.idRestore.forEach(function(item) {
                    $scope.pin_unpin(item);
                });
                $scope.idRestore = [];
            }
        }
        $scope.pinFeed = function(state) {
            switch (state) {
                case "allow":
                $scope.idRestore = [];
                $('.lst-newsfeeds .pin').removeClass('hidden');
                $scope.showTarget('.newsfeed-app-control');
                $scope.closeTarget('.newsfeed-app-create-button');
                break;
                case "prevent":
                $('.lst-newsfeeds .pin').addClass('hidden');
                $scope.closeTarget('.newsfeed-app-control');
                $scope.showTarget('.newsfeed-app-create-button');
                break;
            }
        }

        $scope.displayLiked = function(status, idx, type) {
            switch (status) {
                case "open":
                dataHtml.getTemplate('templates/dashboard/newsfeeds/popups/newsfeedsPopupListLikemodal.tpl').success(function(results) {
                    $scope.dataHtml.popupNewsfeedsLiked = results;
                    $timeout(function() {
                        $scope.showliker(idx, type);
                        $ionicScrollDelegate.$getByHandle('scrollListLike').resize();
                        $scope.showTarget('#popupNewsfeedsLiked');
                    }, 500);
                })
                break;
                case "close":
                $scope.closeTarget('#popupNewsfeedsLiked');
                $scope.pinFeed('prevent');
                break;
            }
        }

        $scope.displayComment = function(status, idx, type) {
            switch (status) {
                case "open":
                if (type == 'newfeeds') {
                    $scope.dataComment.data = $scope.newfeeds[idx].dataComment;
                    $scope.dataComment.feedID = $scope.newfeeds[idx].id;
                    $scope.dataComment.title = $scope.newfeeds[idx].title;
                } else {
                    $scope.dataComment.data = $scope.newfeedpin[idx].dataComment;
                    $scope.dataComment.feedID = $scope.newfeedpin[idx].id;
                    $scope.dataComment.title = $scope.newfeeds[idx].title;
                }
                $scope.dataComment.type = type;
                $scope.dataComment.idx = idx;
                // console.log($scope.dataComment);
                dataHtml.getTemplate('templates/dashboard/newsfeeds/popups/newsfeedsPopupListCommentmodal.tpl').success(function(results) {
                    $scope.dataHtml.popupNewsfeedsComment = results;
                    $timeout(function() {
                        $scope.showTarget('#popupNewsfeedsComment');
                        $ionicScrollDelegate.$getByHandle('scrollListComment').resize();
                    }, 500);
                })
                break;
                case "close":
                $scope.closeTarget('#popupNewsfeedsComment');
                $scope.pinFeed('prevent');
                break;
            }
        }
        $scope.showHideContent = function(className, idx) {
            if ($("." + className + idx).hasClass('text-ellipsis')) {
                $("." + className + idx).removeClass('text-ellipsis');
                $("." + className + "show" + idx).html('Hide');
            } else {
                $("." + className + idx).addClass('text-ellipsis');
                $("." + className + "show" + idx).html('See more');
            }
        }
        $scope.formatTimePaging = function(timeValue) {
            return moment(timeValue).format('dddd MM/DD/YYYY, hh:mm a');
        }

        $scope.getFeedtitles = function() {
            Feedtiltles.getSelect().success(function(data) {
                if(data.status){
                    $scope.feedtitle = data.data;
                }
                else {
                    $scope.feedtitle =[];
                }
                $scope.getNewfeeds();
            });
        }

        $scope.setValueForFeedTitle = function(feedId) {
            if(_.where($scope.feedtitle, {
                id: feedId
            }).length){
                $scope.feedTitleVal = _.where($scope.feedtitle, {
                    id: feedId
                })[0].feedtitle;
            }else{
                $scope.feedTitleVal = '';
            }
            
        }
        // $scope.openAutocomplete = function(className) {
        //     dataHtml.getTemplate('templates/dashboard/newsfeeds/popups/newsfeedsPopupSearchmodal.tpl').success(function(results) { $scope.dataHtml.searchNewsfeeds = results; });
        //     $timeout(function() {
        //         var ionAutocompleteElement = document.getElementsByClassName(className);
        //         angular.element(ionAutocompleteElement).controller('ionAutocomplete').fetchSearchQuery("", true);
        //         angular.element(ionAutocompleteElement).controller('ionAutocomplete').showModal();
        //     }, 500)

    // }
    $scope.renderTemplateData();
})
