Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var BASE_URL = 'http://madingbosku.com/schoolapi';
- var SCHOOL_ID = 8;
- angular.module('starter.controllers', [])
- // App Controller
- .controller('AppCtrl', function($scope,$rootScope,$ionicModal, $timeout,$http,$ionicActionSheet,$localStorage,$ionicHistory,$ionicPopup,$cordovaToast,$cordovaClipboard,$state,$ionicPlatform,$ionicSideMenuDelegate) {
- $scope.username = $localStorage.username;
- $scope.loginData = {};
- $scope.reset_state = function(){
- $localStorage.page_state = '';
- $ionicHistory.goBack();
- };
- $scope.doLogout = function(){
- $localStorage.token = undefined;
- var myPopup = $ionicPopup.show({
- title: 'MAGZ',
- subTitle: 'Sign Out is Successfully!',
- buttons: [{
- type: 'button button-outline button-energized',
- text: 'OK'
- }]
- });
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- window.location.href = "#/app/playlists";
- $rootScope.isLogin = false;
- }, 3000);
- }
- $rootScope.fetch_comment = function(){
- $http.get(BASE_URL+'/comments/post/'+$rootScope.current_page)
- .success(function(res){
- $rootScope.current_comment = res;
- console.log(res);
- })
- var dataComment = Object.keys()
- .error(function(err){
- console.log(err);
- });
- }
- if($localStorage.token != undefined){
- $rootScope.isLogin = true;
- } else {
- $rootScope.isLogin = false;
- }
- $scope.main_menu = $localStorage.main_menu;
- // Share Function
- function shareToFB(){
- $cordovaToast.show('paste the message to facebook post', 'long', 'bottom');
- $cordovaClipboard.copy('Kunjungin MadingBosKu di http://www.madingbosku.com');
- window.plugins.socialsharing.shareViaFacebook(
- 'Kunjungi MadingBosKu',
- null /* img */,
- 'http://www.madingbosku.com' /* url */,
- function() {
- console.log('share ok')
- },
- function(errormsg) {
- alert(errormsg)
- }
- );
- }
- function shareToTwitter(){
- window.plugins.socialsharing.shareViaTwitter(
- 'Kunjungi MadingBosKu',
- null /* img */,
- 'http://www.madingbosku.com' /* url */,
- function() {console.log('share ok')},
- function(errormsg){alert(errormsg)}
- );
- }
- function shareToWA(){
- window.plugins.socialsharing.shareViaWhatsApp(
- 'Kunjungi MadingBosKu',
- null /* img */,
- 'http://www.madingbosku.com' /* url */,
- function() {console.log('share ok')},
- function(errormsg){alert(errormsg)}
- );
- }
- // Function Button in Playists
- $scope.showVersion = function() {
- $ionicPopup.show({
- title: 'MAGZ',
- subTitle: 'MAGZ is Version 1.6',
- buttons: [{
- text: 'OK',
- type: 'button-energized button-outline'
- }]
- })
- }
- // Function Button in SinglePost
- $scope.inSinglePost = $state.is('app.singlepost')
- $scope.inPost = function() {
- if ($state.is('app.singlepost')) {
- return true
- } else {
- return false
- }
- }
- $scope.showMenu = function() {
- if($localStorage.page_state == 'post') {
- var hidesheet = $ionicActionSheet.show({
- titleText : 'Social Share',
- buttons: [
- { text: ' Facebook' },
- { text: ' Twitter' },
- { text: ' WhatsApp' }
- ],
- cancelText: 'Cancel',
- cancel: function() {
- return true
- },
- buttonClicked: function(index) {
- if(index == 0){
- shareToFB();
- } else if(index == 1){
- shareToTwitter();
- } else if (index == 2) {
- shareToWA();
- }
- }
- });
- }
- }
- // This Part a Dropdown Menu List
- var menus = $http.get(BASE_URL+'/category/'+SCHOOL_ID)
- .success(function(response){
- $scope.menus = response.data;
- })
- $scope.mySchool = []
- for (var i=0; i < menus.length; i++) {
- $scope.mySchool[i] = {
- name: i,
- items: []
- };
- // for (var j=0; j < 3; j++) {
- // $scope.groups[i].items.push(i + '-' + j);
- // }
- }
- // This Part a ToggleGroup MySchool Dropdown
- $scope.toggleGroup = function(mySchool) {
- if ($scope.isGroupShown(mySchool)) {
- $scope.shownGroup = null;
- } else {
- $scope.shownGroup = mySchool;
- }
- };
- $scope.isGroupShown = function(mySchool) {
- return $scope.shownGroup === mySchool;
- };
- $scope.shownGroup = $scope.mySchool[0];
- // --------------------------------------- // --------------------------------------- //
- $scope.entertainment = []
- for (var i=0; i < menus.length; i++) {
- $scope.entertainment[i] = {
- name: i,
- items: []
- };
- // for (var j=0; j < 3; j++) {
- // $scope.groups[i].items.push(i + '-' + j);
- // }
- }
- // This Part a ToggleGroup Entertainment Dropdown
- $scope.toggleGroup = function(entertainment) {
- if ($scope.isGroupShown(entertainment)) {
- $scope.shownGroup = null;
- } else {
- $scope.shownGroup = entertainment;
- }
- };
- $scope.isGroupShown = function(entertainment) {
- return $scope.shownGroup === entertainment;
- };
- $scope.shownGroup = $scope.entertainment[0];
- // Create the login modal that we will use later
- $ionicModal.fromTemplateUrl('templates/login.html', {
- scope: $scope
- }).then(function(modal) {
- $scope.modal = modal;
- });
- // Triggered in the login modal to close it
- $scope.closeLogin = function() {
- $scope.modal.hide();
- };
- // Open the login modal
- $scope.login = function() {
- $scope.modal.show();
- };
- // Perform the login action when the user submits the login form
- $scope.doLogin = function() {
- console.log('Doing login', $scope.loginData);
- // Simulate a login delay. Remove this and replace with your login
- // code if using a login system
- $timeout(function() {
- $scope.closeLogin();
- }, 900);
- };
- $http.get(BASE_URL+'/category/'+SCHOOL_ID)
- .success(function(response){
- $scope.menus = response.data;
- })
- .error(function(err){
- console.log(err);
- }).then(function(){
- // Add code for continue
- });
- // Sidemenu List
- $scope.toLogin = function() {
- window.location.href = "#/login"
- }
- $scope.toHome = function() {
- $state.go('app.playlists')
- }
- $scope.toIntroduction = function() {
- window.location.href = "#/app/splash"
- }
- $scope.toAbout = function() {
- window.location.href = "#/app/about"
- }
- $scope.toSpecialThanks = function() {
- window.location.href = "#/app/specialThanks"
- }
- $scope.exitAppMobile = function() {
- var confirmPopup = $ionicPopup.show({
- title: 'MAGZ',
- subTitle: 'Are you sure you want to Exit ?',
- buttons: [{
- text: 'Cancel',
- type: 'button-energized button-outline'
- },{
- text: 'Ok',
- type: 'button-energized',
- onTap: function() {
- navigator.app.exitApp()
- }
- }
- ]
- })
- }
- })
- .controller('SplashCtrl',function($scope,$http, $ionicActionSheet, $state, $localStorage, $ionicSlideBoxDelegate){
- $scope.previousPage = function() {
- $ionicSlideBoxDelegate.previous();
- };
- $scope.nextPage = function() {
- $ionicSlideBoxDelegate.next();
- };
- $scope.slideChanged = function(index) {
- $scope.slideIndex = index;
- };
- var toHomepage = function() {
- window.location.href = "#/app/playlists";
- window.localStorage['MadingSMKN2Balikpapan'] = true;
- }
- $scope.toHomepage = function() {
- toHomepage();
- var dataTest = document.getElementById('imageLast');
- }
- if (window.localStorage['MadingSMKN2Balikpapan'] === "true") {
- toHomepage();
- } else {
- setTimeout(function () {
- navigator.splashscreen.hide()
- window.location.href = "#/app/playlists";
- });
- }
- })
- // Login Controller
- .controller('LoginCtrl',function($scope,$rootScope,$http,$localStorage,$ionicPopup,$timeout,$ionicPlatform,$ionicHistory,$location){
- $scope.data = {};
- $scope.attempt_login = function(){
- $http.post(BASE_URL+'/login',{ phone: $scope.data.phone , password: $scope.data.password}).then(function(response){
- if(response.status == 200){
- var loginSuccces = $ionicPopup.show({
- title: 'MAGZ',
- subTitle: 'Sign In is Successfully!',
- buttons: [{
- type: 'button-outline button-energized',
- text: 'OK'
- }]
- })
- console.log(response.data);
- $localStorage.token = response.data.token;
- $localStorage.username = response.data.user.name;
- $localStorage.user_id = response.data.user.id;
- window.location.href="#/app/playlists";
- $rootScope.isLogin = true;
- } else {
- var myPopup = $ionicPopup.show({
- title: 'MAGZ',
- subTitle: 'Please check your username or password.',
- buttons: [{
- type: 'button-outline button-energized',
- text: 'OK'
- }]
- });
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- }, 3000);
- }
- },function(err){
- var myPopup = $ionicPopup.show({
- title: 'MAGZ',
- subTitle: 'Please check your username and password.',
- buttons: [{
- type: 'button-outline button-energized',
- text: 'OK'
- }]
- });
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- }, 2000);
- });
- }
- })
- // Register Controller
- .controller('RegisterCtrl',function($scope,$http,$timeout,$ionicPopup){
- $scope.school_list = [];
- $scope.data = {};
- $http.get(BASE_URL+'/schools')
- .success(function(res){
- $scope.school_list = res;
- })
- .error(function(res){
- console.log(res);
- });
- $scope.registerUser = function() {
- $scope.data.school_id = $scope.data.school_id.id;
- $http.post(BASE_URL+"/register",$scope.data).then(function(res){
- var myPopup = $ionicPopup.show({
- title: 'MAGZ',
- template: 'Register is Successfully',
- buttons: [{
- type: 'button-outline button-energized',
- text: 'OK'
- }]
- })
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- }, 3000);
- window.location.href = "#/login";
- },function(err){
- console.log(err);
- });
- }
- })
- // Rubrik Controller
- .controller('RubrikCtrl',function($scope,$http,$ionicLoading,$rootScope,$localStorage,$stateParams,$state){
- $localStorage.page_state = 'main';
- $scope.posts= [];
- $ionicLoading.show({
- }).then(function(){
- console.log("The loading indicator is now displayed");
- });
- $http.get(BASE_URL+'/category/'+$stateParams.id+'/posts')
- .success(function(response){
- console.log(response.data);
- $scope.posts = response.data;
- $ionicLoading.hide();
- })
- .error(function(err){
- var myPopup = $ionicPopup.alert({
- title: 'Oops!!',
- template: 'Failed Register'
- });
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- }, 3000);
- }).then(function(){
- });
- })
- // Playlists Controller
- .controller('PlaylistsCtrl', function($scope,$http,$ionicLoading,$rootScope,$localStorage,$ionicPopup,$ionicHistory,$ionicPlatform,$location) {
- $scope.logoHeaderBar = "<img src='img/M.png' width='120' height='68' class='logoHeaderBar'>";
- $localStorage.page_state = 'main';
- $localStorage.main_menu = 'Mading Bos Ku';
- // $ionicLoading.show({
- // }).then(function(){
- // // Add code for Optional
- // });
- $scope.posts= [];
- $http.get(BASE_URL+'/mading/'+SCHOOL_ID+'/latest')
- .success(function(response){
- console.log(response.data);
- $scope.posts = response.data;
- $ionicLoading.hide();
- })
- .error(function(err){
- console.log(err);
- }).then(function(){
- // Add code for Continue
- });
- $scope.items = [1,2,3];
- $scope.doRefresh = function() {
- $http.get(BASE_URL+'/mading/'+SCHOOL_ID+'/latest')
- .success(function(response) {
- $scope.posts = response.data;
- console.log(response.data)
- })
- .finally(function() {
- // Stop the ion-refresher from spinning
- $scope.$broadcast('scroll.refreshComplete');
- });
- };
- })
- // About Controller
- .controller('AboutCtrl', function($scope,$rootScope,$stateParams,$http,$ionicLoading,$sce,$ionicActionSheet,$rootScope,$localStorage) {
- $scope.trustedPost = "";
- $scope.reset_state = function(){
- $localStorage.page_state = '';
- $ionicHistory.goBack();
- };
- })
- // Support Controller
- .controller('specialThanksCtrl', function($scope,$rootScope,$stateParams,$http,$ionicLoading,$sce,$ionicActionSheet,$rootScope,$localStorage) {
- $scope.trustedPost = "";
- $scope.reset_state = function(){
- $localStorage.page_state = '';
- $ionicHistory.goBack();
- };
- })
- // Post Controller
- .controller('PostCtrl', function($scope,$rootScope,$stateParams,$http,$ionicLoading,$sce,$ionicActionSheet,$rootScope,$localStorage) {
- $scope.trustedPost = "";
- $localStorage.page_state = "post";
- $ionicLoading.show({
- }).then(function(){
- console.log("The loading indicator is now displayed");
- });
- $scope.post = {};
- $http.get(BASE_URL+'/mading/single/'+$stateParams.postId)
- .success(function(res){
- $ionicLoading.hide();
- $scope.post = res;
- $scope.trustedPost = $sce.trustAsHtml(res.content);
- $rootScope.pagestate = 'view';
- $rootScope.current_page = $stateParams.postId;
- $rootScope.fetch_comment();
- })
- .error(function(err){
- console.log(err);
- });
- if($localStorage.token == undefined){
- $scope.can_comment = false;
- } else {
- $scope.can_comment = true;
- }
- $scope.logoHeaderBar = "<img src='img/1.png' width='60' height='60' class='logoHeaderBar'>";
- // Comment Function
- $scope.data = {};
- $scope.add_comment = function(){
- $http.post(BASE_URL+'/comments/post/'+$stateParams.postId,{ content: $scope.data.content , user_id: $localStorage.user_id }).then(function(response){
- if(response.status == 200){
- console.log(response.data);
- $rootScope.fetch_comment();
- } else {
- var myPopup = $ionicPopup.alert({
- title: 'Oops!!',
- template: 'Failed Post'
- });
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- }, 2000);
- }
- },function(err){
- var myPopup = $ionicPopup.alert({
- title: 'Oops!!',
- template: 'Failed Post'
- });
- $timeout(function() {
- myPopup.close(); //close the popup after 3 seconds for some reason
- }, 2000);
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement