var API = 'api/'; var Brightery = angular.module('Brightery', ['ngSanitize', 'ngRoute', 'angular.chosen', 'ngCkeditor', 'slugifier', 'base64']); Brightery.run(function ($rootScope, $location, $http, $templateCache) { $rootScope.loggedIn = function () { if ($rootScope.loginStatus) { return $rootScope.loginStatus; } return false; //else { // if ($cookies.email && $cookies.password) { // $rootScope.loginStatus = true; // } //} }; $rootScope.permission = function ($permission) { if (typeof $permission == 'undefined') if (typeof $rootScope.user == 'undefined') return false; else return true; if (typeof $rootScope.user == 'undefined') return false; if ($rootScope.user.permissions.indexOf($permission) != -1) return true; else return false; }; $rootScope.logout = function () { $rootScope.loginStatus = false; $http({ url: API + 'login/logout', method: 'get' }).then(function () { $rootScope.user = undefined; $location.path('login'); }); }; $rootScope.$on('$locationChangeStart', function (event, next, current) { $http({ url: API + 'login/status', method: 'post', data: {location: $location.path()} }).then(function (res) { if (res.data.error == true) { if (res.data.type == 'oauth') { if ($location.path() !== '/login') { $location.path('/login'); } } } }); }); // CACHING $http.get('templates/header.html', {cache: $templateCache}); $http.get('templates/footer.html', {cache: $templateCache}); $http.get('templates/login.html', {cache: $templateCache}); $http.get('templates/main.html', {cache: $templateCache}); $http.get('templates/panel.html', {cache: $templateCache}); $http.get('templates/side.html', {cache: $templateCache}); $http.get('templates/about/brightery.html', {cache: $templateCache}); //$http.get('templates/campaigns/index.html', {cache: $templateCache}); //$http.get('templates/campaigns/manage.html', {cache: $templateCache}); //$http.get('templates/email_templates/index.html', {cache: $templateCache}); //$http.get('templates/email_templates/manage.html', {cache: $templateCache}); //$http.get('templates/smtp_servers/index.html', {cache: $templateCache}); //$http.get('templates/smtp_servers/manage.html', {cache: $templateCache}); $http.get('templates/users/index.html', {cache: $templateCache}); $http.get('templates/users/manage.html', {cache: $templateCache}); $http.get('templates/usergroups/index.html', {cache: $templateCache}); $http.get('templates/usergroups/manage.html', {cache: $templateCache}); $http.get('templates/settings/manage.html', {cache: $templateCache}); $http.get('templates/dashboard/index.html', {cache: $templateCache}); }); Brightery.factory('authHttpResponseInterceptor', function ($q) { return { request: function (config) { $('.spinnerHolder').show(); $('.spinner').show(); return config; }, response: function (response) { $('.spinnerHolder').fadeOut(1000); $('.spinner').fadeOut(3000); return response || $q.when(response); }, responseError: function (reason) { $('.spinnerHolder').fadeOut(1000); $('.spinner').fadeOut(3000); return $q.reject(reason); } }; }); Brightery.service('error', function () { this.fire = function ($errorMessage) { var popup = {}; popup.template = 'message'; popup.SystemMessage = $errorMessage; $('#popup').modal('show'); return popup; }; }); Brightery.filter('nl2br', function () { var span = document.createElement('span'); return function (input) { if (!input) return input; var lines = input.split('\n'); for (var i = 0; i < lines.length; i++) { span.innerText = lines[i]; span.textContent = lines[i]; //for Firefox lines[i] = span.innerHTML; } return lines.join('
'); } }); Brightery.directive('fileModel', ['$parse', function ($parse) { return { restrict: 'A', link: function (scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind('change', function () { scope.$apply(function () { modelSetter(scope, element[0].files[0]); }); }); } }; }]); Brightery.factory('focus', function ($timeout, $window) { return function (id) { // timeout makes sure that is invoked after any other event has been triggered. // e.g. click events that need to run before the focus or // inputs elements that are in a disabled state but are enabled when those events // are triggered. $timeout(function () { var element = $window.document.getElementById(id); if (element) element.focus(); }); }; }); Brightery.directive('eventFocus', function (focus) { return function (scope, elem, attr) { elem.on(attr.eventFocus, function () { focus(attr.eventFocusId); }); // Removes bound events in the element itself // when the scope is destroyed scope.$on('$destroy', function () { element.off(attr.eventFocus); }); }; }); Brightery.directive("ngFileSelect", function () { return { link: function ($scope, el) { el.bind("change", function (e) { $scope.file = (e.srcElement || e.target).files[0]; $scope.getFile(); }); } } }); var popup = { message: function (title, message) { $('body').append('' ); $("#myModal").modal('show'); $('#myModal').on('hidden.bs.modal', function () { $(this).remove(); }) return false; } }; $(window).load(function () { $('.loading-container').fadeOut(1000, function () { $(this).remove(); }); });Brightery.config(function ($routeProvider, $locationProvider, $httpProvider) { $routeProvider .when('/login', { templateUrl: 'templates/login.html', controller: 'loginCtrl' }) .when('/dashboard', { templateUrl: 'templates/dashboard/index.html', controller: 'dashboardCtrl', resolve: {access: CheckLogin} }) // SETTINGS .when('/settings', { templateUrl: 'templates/settings/manage.html', controller: 'settingsCtrl', resolve: {access: CheckLogin} }) // ABOUT .when('/about', { templateUrl: 'templates/about/brightery.html', controller: 'aboutCtrl', resolve: {access: CheckLogin} }) // USERS .when('/users', { templateUrl: 'templates/users/index.html', controller: 'usersCtrl', resolve: {access: CheckLogin} }) .when('/usergroups', { templateUrl: 'templates/usergroups/index.html', controller: 'usergroupsCtrl', resolve: {access: CheckLogin} }) // Accounts .when('/accounts', { templateUrl: 'templates/accounts/index.html', controller: 'accountsCtrl', resolve: {access: CheckLogin} }) // Tweets .when('/tweets', { templateUrl: 'templates/groups/index.html', controller: 'groupsCtrl', resolve: {access: CheckLogin} }) // Bots .when('/bots', { templateUrl: 'templates/bots/index.html', controller: 'botsCtrl', resolve: {access: CheckLogin} }) // Proxies .when('/proxies', { templateUrl: 'templates/proxies/index.html', controller: 'proxiesCtrl', resolve: {access: CheckLogin} }) // Logs .when('/logs', { templateUrl: 'templates/logs/index.html', controller: 'logsCtrl', resolve: {access: CheckLogin} }) .when('/tweets/:Id', { templateUrl: 'templates/tweets/index.html', controller: 'tweetsCtrl', resolve: {access: CheckLogin} }) .otherwise({redirectTo: '/login'}); $locationProvider.html5Mode(true); $httpProvider.interceptors.push('authHttpResponseInterceptor'); }); var CheckLogin = function ($rootScope, $http, $location) { return $http({ url: API + 'login/status', method: 'get', }).then(function (res) { $rootScope.loginStatus = ! res.data.error; if ($rootScope.loginStatus != true) $location.path('login'); $rootScope.user = res.data.data; }); };Brightery.service('CRUD', function ($rootScope, $http, error, $location) { this.grant = function ($scope) { $rootScope.MainTemplate = 'templates/' + $scope.entity + '/list.html'; $scope.currentPage = 1; this.definations($scope); $scope.get(); return $scope; }; this.definations = function ($scope) { $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + $scope.entity : x, method: 'get', }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.search = function () { $http({ url: API + $scope.entity, method: 'get', params: {keyword: $scope.keyword} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; id = ''; if (typeof item != "undefined") id = item[$scope.entityPK]; $http({ url: API + $scope.entity + '/get/' + id, method: 'get', }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); $rootScope.MainTemplate = 'templates/' + $scope.entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + $scope.entity + '/list.html'; }; $scope.save = function () { $http({ url: API + $scope.entity + '/manage', method: 'post', data: $scope.form, }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + $scope.entity + '/delete', method: 'post', data: { items: $scope.data.items.filter(function (x) { return x.checked == true }) } }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; }; }); Brightery.service('RCRUD', function ($rootScope, $http, error, $location) { this.grant = function ($scope) { $rootScope.MainTemplate = 'templates/' + $scope.entity + '/list.html'; $scope.currentPage = 1; this.definations($scope); $scope.get(); return $scope; }; this.definations = function ($scope) { $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + $scope.entity : x, method: 'get', params: {id: $scope.parentId} }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.search = function () { $http({ url: API + $scope.entity, method: 'get', params: {keyword: $scope.keyword, id: $scope.parentId} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; id = ''; if (typeof item != "undefined") id = item[$scope.entityPK]; $http({ url: API + $scope.entity + '/get/' + id, method: 'get', params: {id: $scope.parentId} }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); $rootScope.MainTemplate = 'templates/' + $scope.entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + $scope.entity + '/list.html'; }; $scope.save = function () { $http({ url: API + $scope.entity + '/manage', method: 'post', data: $scope.form, params: {id: $scope.parentId} }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + $scope.entity + '/delete', method: 'post', params: {id: $scope.parentId}, data: { items: $scope.data.items.filter(function (x) { return x.checked == true }) } }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; }; }); Brightery.controller('aboutCtrl', function ($scope, $rootScope, $http, error, $location) { entity = 'about'; $rootScope.MainTemplate = 'templates/' + entity + '/brightery.html'; }); Brightery.controller('accountsCtrl', function ($scope, $rootScope, $http, error, $location) { entity = 'accounts'; entityPK = 'account_id'; $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; $scope.currentPage = 1; $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + entity : x, method: 'get' }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.get(); $scope.search = function () { $http({ url: API + entity, method: 'get', params: {keyword: $scope.keyword} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; $scope.formData = []; id = ''; $scope.formData.connectionTypes = [ {id: 'tls', title: 'Secured connection using TLS'}, {id: 'ssl', title: 'Secured connection using SSL'}, {id: 'us', title: 'Unsecured connection'}, ]; if (typeof item != "undefined") id = item[entityPK]; $http({ url: API + entity + '/get/' + id, method: 'get' }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) { $scope.formData = res.data.data; } $scope.formData.connectionTypes = [ {id: 'tls', title: 'Secured connection using TLS'}, {id: 'ssl', title: 'Secured connection using SSL'}, {id: 'us', title: 'Unsecured connection'}, ]; }); $rootScope.MainTemplate = 'templates/' + entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; }; $scope.save = function () { $http({ url: API + entity + '/manage', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + entity + '/delete', method: 'post', data: { items: $scope.data.items.filter(function (x) { return x.checked == true }) } }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; $scope.test = function (item) { $('.loading-container').show(); $http({ url: API + entity + '/test/' + item[entityPK], method: 'get', }).then(function (res) { if (res.data.error) { return popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { return popup.message('Information', "Your connection test passed, and it works fine."); } } }); }; }); Brightery.controller('botsCtrl', function ($scope, $rootScope, $http, error, $location, CRUD, $compile) { $scope.entity = 'bots'; $scope.entityPK = 'bot_id'; $scope = CRUD.grant($scope); $scope.get(); $scope.searchResult = function() { $http({ url: API + $scope.entity+'/get_result', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { $scope.result = res.data.data; var tpl = $compile(angular.element('

Count: {{ result.items.search_metadata.count }} Completed in: {{ result.items.search_metadata.completed_in}}

' + '

{{item.text}} at {{item.created_at}}

'))($scope); popup.message('Result', '
'); //tpl[0].outerHTML angular.element($('.STATUSES')).append(tpl); } }); }; $scope.getCallOfAction = function() { $http({ url: API + $scope.entity+'/get_lists', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { return $scope.formData.call_to_actions = res.data.data.items; } }); }; }); Brightery.controller('campaignProgressCtrl', function ($scope, $rootScope, $http, error, $location, Slug, CRUD, $routeParams) { var entity = 'campaign_progress'; var entityPK = 'email_id'; $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; $scope.currentPage = 1; $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + entity + '/index/' + $routeParams.Id : x, method: 'get' }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.get(); $scope.search = function () { $http({ url: API + entity + '/index/'+ $routeParams.Id, method: 'get', params: {keyword: $scope.keyword} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; id = ''; if (typeof item != "undefined") id = item[entityPK]; $http({ url: API + entity + '/get/' + id, method: 'get' }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); $rootScope.MainTemplate = 'templates/' + entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; }; $scope.save = function () { $http({ url: API + entity + '/manage/'+$routeParams.Id, method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + entity + '/delete', method: 'post', data: { items: $scope.data.items.filter(function (x) { return x.checked == true }) } }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; $scope.slugify = function (input) { $scope.form.permalink = Slug.slugify(input); }; }); Brightery.controller('campaignsCtrl', function ($scope, $rootScope, $http, error, $location, CRUD) { $scope.entity = 'campaigns'; $scope.entityPK = 'campaign_id'; $scope = CRUD.grant($scope); $scope.start = function (item) { $http({ url: API + $scope.entity + '/start/' + item[$scope.entityPK], method: 'get', }).then(function (res) { return popup.message('Information', "Mission has been started"); $scope.get(); item.status = 'in-progress'; }); }; $scope.test = function (item) { $http({ url: API + $scope.entity + '/test/' + item[$scope.entityPK], method: 'get', }).then(function (res) { return popup.message('Information', "Test has been started"); $scope.get(); }); }; $scope.stop = function (item) { $http({ url: API + $scope.entity + '/stop/' + item[$scope.entityPK], method: 'get', }).then(function (res) { return popup.message('Information', "Mission has been stopped"); $scope.get(); item.status = 'active'; }); }; $scope.addHeader = function () { if (typeof $scope.form.headers == 'undefined' || $scope.form.headers == null) $scope.form.headers = []; $scope.form.headers.push({key: '', value: ''}); }; $scope.removeHeader = function (idx) { $scope.form.headers.splice(idx, 1); }; $scope.progress = function (item) { $http({ url: API + $scope.entity + '/progress/' + item.campaign_id, method: 'get' }).then(function (res) { if (res.data.data.items) $scope.data.logs = res.data.data.items; }); $rootScope.MainTemplate = 'templates/' + $scope.entity + '/progress.html'; }; }); Brightery.controller('dashboardCtrl', function ($scope, $rootScope, $http, error, $location) { entity = 'dashboard'; $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + entity : x, method: 'get' }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.get(); }); Brightery.controller('emailsCtrl', function ($scope, $rootScope, $http, error, $location, Slug, CRUD, $routeParams) { var entity = 'emails'; var entityPK = 'email_id'; $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; $scope.currentPage = 1; $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + entity + '/index/' + $routeParams.Id : x, method: 'get' }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.get(); $scope.search = function () { $http({ url: API + entity + '/index/'+ $routeParams.Id, method: 'get', params: {keyword: $scope.keyword} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; id = ''; if (typeof item != "undefined") id = item[entityPK]; $http({ url: API + entity + '/get/' + id, method: 'get' }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); $rootScope.MainTemplate = 'templates/' + entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; }; $scope.save = function () { $http({ url: API + entity + '/manage/'+$routeParams.Id, method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + entity + '/delete', method: 'post', data: { items: $scope.data.items.filter(function (x) { return x.checked == true }) } }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; $scope.slugify = function (input) { $scope.form.permalink = Slug.slugify(input); }; }); Brightery.controller('groupsCtrl', function ($scope, $rootScope, $http, error, $location, Slug, CRUD) { $scope.API = BASE_URL; $scope.entity = 'groups'; $scope.entityPK = 'group_id'; $scope = CRUD.grant($scope); }); Brightery.controller('loginCtrl', function ($scope, $rootScope, $http, error, $location) { $scope.login = function () { $http({ url: API + 'login', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $location.path('/dashboard'); } } }); }; }); Brightery.controller('logsCtrl', function ($scope, $rootScope, $http, error, $location, CRUD) { $scope.entity = 'logs'; $scope.entityPK = 'log_id'; $scope = CRUD.grant($scope); }); Brightery.controller('proxiesCtrl', function ($scope, $rootScope, $http, error, $location, CRUD) { $scope.entity = 'proxies'; $scope.entityPK = 'proxy_id'; $scope = CRUD.grant($scope); }); Brightery.controller('settingsCtrl', function ($scope, $rootScope, $http, error, $location) { entity = 'settings'; $rootScope.MainTemplate = 'templates/' + entity + '/manage.html'; $scope.get = function () { $scope.form = {}; $http({ url: API + entity + '/index', method: 'get' }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); }; $scope.get(); $scope.save = function () { $http({ url: API + entity + '/manage', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { popup.message('Message', "Your settings has been updated"); } } }); }; $scope.suggest = function (that) { $http({ url: API + entity + '/suggest', method: 'get' }).then(function (res) { if (res.data.data.suggestion) $scope.form.php_path = res.data.data.suggestion; }); }; }); Brightery.controller('tweetsCtrl', function ($scope, $rootScope, $http, error, $location, RCRUD, $routeParams) { $scope.entity = 'tweets'; $scope.entityPK = 'tweet_id'; $scope.parentId = $routeParams.Id; $scope = RCRUD.grant($scope); }); Brightery.controller('usergroupsCtrl', function ($scope, $rootScope, $http, error, $location) { entity = 'usergroups'; entityPK = 'usergroup_id'; $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; $scope.currentPage = 1; $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + entity : x, method: 'get' }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.get(); $scope.search = function () { $http({ url: API + entity, method: 'get', params: {keyword: $scope.keyword} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; id = ''; if (typeof item != "undefined") id = item[entityPK]; $http({ url: API + entity + '/get/' + id, method: 'get' }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); $rootScope.MainTemplate = 'templates/' + entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; }; $scope.save = function () { $scope.form.permissions = $scope.formData.zones; $http({ url: API + entity + '/manage', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + entity + '/delete', method: 'post', data: {items: $scope.data.items.filter(function (x) { return x.checked == true })} }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; $scope.permissionsCheckChange = function (that) { if (that.permissionsMasterChecker == false) { $scope.formData.zones = angular.forEach($scope.formData.zones, function (x, i) { $scope.formData.zones[i].checked = false; }); } else { $scope.formData.zones = angular.forEach($scope.formData.zones, function (x, i) { $scope.formData.zones[i].checked = true; }); } }; }); Brightery.controller('usersCtrl', function ($scope, $rootScope, $http, error, $location) { entity = 'users'; entityPK = 'user_id'; $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; $scope.currentPage = 1; $scope.paging = function (item) { if (typeof item == 'undefined') return; $scope.get(item.url).then(function () { $scope.currentPage = item.title; }); }; $scope.get = function (x) { var promise = $http({ url: typeof(x) == 'undefined' ? API + entity : x, method: 'get' }).then(function (res) { return $scope.data = res.data.data; }); return promise; }; $scope.get(); $scope.search = function () { $http({ url: API + entity, method: 'get', params: {keyword: $scope.keyword} }).then(function (res) { return $scope.data = res.data.data; }); }; $scope.manage = function (item) { $scope.form = {}; id = ''; if (typeof item != "undefined") id = item[entityPK]; $http({ url: API + entity + '/get/' + id, method: 'get' }).then(function (res) { if (res.data.data.item) $scope.form = res.data.data.item; if (res.data.data) $scope.formData = res.data.data; }); $rootScope.MainTemplate = 'templates/' + entity + '/manage.html'; }; $scope.esc = function () { $scope.get(); $rootScope.MainTemplate = 'templates/' + entity + '/list.html'; }; $scope.save = function () { $http({ url: API + entity + '/manage', method: 'post', data: $scope.form }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.esc(); } } }); }; $scope.checkChange = function (that) { if (that.masterChecker == false) { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = false; }); } else { $scope.data.items = angular.forEach($scope.data.items, function (x, i) { $scope.data.items[i].checked = true; }); } }; $scope.applyForAction = function () { if ($scope.data.items.filter(function (x) { return x.checked == true }).length <= 0) return alert('Sorry, You must check one record at least.'); if (!confirm("Are you sure you want to preform this action")) return; if ($scope.applyAction == 'delete') { $http({ url: API + entity + '/delete', method: 'post', data: {items: $scope.data.items.filter(function (x) { return x.checked == true })} }).then(function (res) { if (res.data.error) { popup.message('Error', res.data.message); } else { if (res.data.data.success == true) { $scope.get(); } } }); } }; $scope.guess = function() { if( !$scope.form.email) return popup.message('Error', "You must fill in the email field"); $http({ url: 'http://image.brightery.com/?email='+$scope.form.email, method: 'get' }).then(function(res) { $scope.form['image'] = {base64: res.data, filename: 'image.jpg',filetype: 'image/jpeg' }; }); } });