Skip to content

Commit

Permalink
format & remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 26, 2016
1 parent a1c7be4 commit db409e1
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions www/js/controllers/CommunityCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ angular.module('starter.controllers')
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
}).then(function (modal) {
$scope.modal = modal;
});

// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.closeLogin = function () {
$scope.modal.hide();
};

// Open the login modal
$scope.login = function() {
$scope.login = function () {
$scope.modal.show();
};

$scope.doLogin = function(user) {
$scope.doLogin = function (user) {
var payload = {
identification: user.username,
password: user.password
};

$http.post('http://forum.growth.ren/' + 'api/token', payload)
.success(function(data) {
.success(function (data) {
$scope.isLogin = true;
$rootScope.userId = data.userId;
TokenHandler.set(data.token);

$scope.closeLogin();
})
.error(function(data, status) {
.error(function (data, status) {
console.log(data);
});
};
Expand All @@ -64,35 +64,23 @@ angular.module('starter.controllers')
$scope.user = $filter('filter')(response.included, {type: "users"})[0];

$scope.discussion = response;
$scope.getUsername = function(user) {
$scope.getUsername = function (user) {
var included = $scope.discussion.included;
for(var i=0; i < included.length; ++i) {
if(included[i].type === 'users' && included[i].id === user.data.id) {
for (var i = 0; i < included.length; ++i) {
if (included[i].type === 'users' && included[i].id === user.data.id) {
return included[i].attributes.username;
}
}
return 'A user';
;}
};

$scope.getAvatar = function(user) {
$scope.getAvatar = function (user) {
var included = $scope.discussion.included;
for(var i=0; i < included.length; ++i) {
if(included[i].type === 'users' && included[i].id === user.data.id && included[i].attributes.avatarUrl) {
for (var i = 0; i < included.length; ++i) {
if (included[i].type === 'users' && included[i].id === user.data.id && included[i].attributes.avatarUrl) {
return included[i].attributes.avatarUrl;
}
}
};

$scope.getUrl = function() {
var txtSrc = discussion.data.id + ' ' + discussion.data.attributes.title;
var output = txtSrc.replace(/[^a-zA-Z0-9]/g,' ').replace(/\s+/g,"-").toLowerCase();
/* remove first dash */
if(output.charAt(0) == '-') output = output.substring(1);
/* remove last dash */
var last = output.length-1;
if(output.charAt(last) == '-') output = output.substring(0, last);

return CONFIG.URL + 'd/' + output;
}
});
});

0 comments on commit db409e1

Please sign in to comment.