1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 08:52:15 -05:00

Refactore services code style

This commit is contained in:
Tankred Hase 2014-11-11 21:50:01 +01:00
parent 1d22231e8a
commit 082cbf192b
5 changed files with 30 additions and 31 deletions

View File

@ -36,8 +36,8 @@ var DialogCtrl = require('./controller/dialog'),
ActionBarCtrl = require('./controller/action-bar'),
errorUtil = require('./util/error'),
backButtonUtil = require('./util/backbutton-handler');
require('./directives/common'),
require('./services/mail-config');
require('./directive/common'),
require('./service/mail-config');
// init main angular module including dependencies
var app = angular.module('mail', [

View File

@ -0,0 +1,27 @@
'use strict';
var ngModule = angular.module('woServices', []);
ngModule.service('mailConfig', MailConfig);
var cfg = require('../app-config').config;
function MailConfig($http, $q) {
this._http = $http;
this._q = $q;
}
/**
* Get the mail server IMAP and SMTP configuration for an email address
*/
MailConfig.prototype.get = function(emailAddress) {
if (emailAddress.indexOf('@') < 0) {
return this._q(function(resolve, reject) {
reject(new Error('Invalid email address!'));
});
}
var url = cfg.settingsUrl + emailAddress.split('@')[1];
return this._http.get(url).then(function(res) {
return res.data;
});
};

View File

@ -1,27 +0,0 @@
'use strict';
var cfg = require('../app-config').config;
var ngModule = angular.module('woServices', []);
ngModule.service('mailConfig', function($http, $q) {
/**
* Get the mail server IMAP and SMTP configuration for an email address
*/
this.get = function(emailAddress) {
if (emailAddress.indexOf('@') < 0) {
return $q(function(resolve, reject) {
reject(new Error('Invalid email address!'));
});
}
var url = cfg.settingsUrl + emailAddress.split('@')[1];
return $http.get(url).then(function(res) {
return res.data;
});
};
});
module.exports = ngModule;

View File

@ -2,7 +2,7 @@
var mocks = angular.mock,
cfg = require('../../src/js/app-config').config;
require('../../src/js/services/mail-config');
require('../../src/js/service/mail-config');
describe('Mail Config Service unit test', function() {
var mailConfig, httpBackend;

View File

@ -5,7 +5,6 @@ var mocks = angular.mock,
Auth = require('../../src/js/bo/auth'),
AdminDao = require('../../src/js/dao/admin-dao'),
appController = require('../../src/js/app-controller');
require('../../src/js/services/mail-config');
describe('Validate Phone Controller unit test', function() {
var scope, location, mailConfigMock, ctrl, authStub, origAuth, adminStub;