Created
June 11, 2014 10:27
-
-
Save DrMabuse23/461d75895a5ac3946e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* @ngdoc function | |
* @name appApp.controller:DbadminCtrl | |
* @description | |
* # DbadminCtrl | |
* Controller of the app | |
*/ | |
angular.module('app') | |
.controller('DbAdminCtrl', ['$scope','$rootScope', 'dbManager','DbUser', | |
function ($scope,$rootScope, dbManager, DbUser) { | |
var db = $rootScope.db, | |
onUpdate = false; | |
$scope.user = DbUser.get($rootScope.db); | |
$scope.iconSync = 'ion-android-storage'; | |
$scope.syncLabel = 'Sync'; | |
$scope.flash = { | |
'message':'', | |
'type':'' | |
}; | |
/** | |
* get all user | |
*/ | |
$rootScope.db.get('_design/user', function(err, doc) { | |
if(err){ | |
console.error('err on get user',JSON.stringify(err)); | |
return; | |
} | |
$scope.$apply(function(){ | |
$scope.user = doc.user; | |
}); | |
}); | |
db.query('recipes/by_recipe',{},function(err,doc){ | |
if(err){ | |
console.error('err on get design',JSON.stringify(err)); | |
return; | |
} | |
console.log(doc); | |
}); | |
/** | |
* replicate is done | |
*/ | |
$scope.$on('server-replicate-done',function(event,message){ | |
// console.debug('result',JSON.stringify(message)); | |
db.allDocs(function(err,doc){ | |
$scope.$apply(function(){ | |
$scope.iconSync = 'ion-android-storage'; | |
$scope.syncLabel = 'Sync'; | |
$scope.flash = message; | |
}); | |
onUpdate = false; | |
// console.log('after replicate',JSON.stringify(doc)); | |
}) | |
}); | |
/** | |
* click replicate | |
*/ | |
$scope.replicate = function () { | |
if(!onUpdate){ | |
$scope.iconSync = 'ion-looping'; | |
$scope.syncLabel = 'Loading ...'; | |
db.allDocs(function(err,doc){ | |
// console.log('before',JSON.stringify(doc)); | |
}); | |
onUpdate = true; | |
dbManager.replicate(); | |
}else{ | |
$scope.$apply(function(){ | |
$scope.flash.message = 'plz wait is on update'; | |
$scope.flash.type = 'info'; | |
}); | |
} | |
}; | |
/** | |
* getUser again | |
*/ | |
$scope.getUser = function () { | |
DbUser.get(db); | |
$scope.user = DbUser.user; | |
// console.debug(JSON.stringify($scope.user)); | |
}; | |
function tabs(){ | |
$(".js-vertical-tab-content").hide(); | |
$(".js-vertical-tab-content:first").show(); | |
/* if in tab mode */ | |
$(".js-vertical-tab").click(function(event) { | |
event.preventDefault(); | |
$(".js-vertical-tab-content").hide(); | |
var activeTab = $(this).attr("rel"); | |
$("#"+activeTab).show(); | |
$(".js-vertical-tab").removeClass("is-active"); | |
$(this).addClass("is-active"); | |
$(".js-vertical-tab-accordion-heading").removeClass("is-active"); | |
$(".js-vertical-tab-accordion-heading[rel^='"+activeTab+"']").addClass("is-active"); | |
}); | |
/* if in accordion mode */ | |
$(".js-vertical-tab-accordion-heading").click(function(event) { | |
event.preventDefault(); | |
$(".js-vertical-tab-content").hide(); | |
var accordion_activeTab = $(this).attr("rel"); | |
$("#"+accordion_activeTab).show(); | |
$(".js-vertical-tab-accordion-heading").removeClass("is-active"); | |
$(this).addClass("is-active"); | |
$(".js-vertical-tab").removeClass("is-active"); | |
$(".js-vertical-tab[rel^='"+accordion_activeTab+"']").addClass("is-active"); | |
}); | |
} | |
tabs(); | |
// $scope.getUser(); | |
}]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment