source upload
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
app.controller('ContactsCtrl', function($scope, $stateParams, EmContacts, EmContactsEL){
|
||||
if ( $stateParams.gid ) {
|
||||
$scope.contacts = new EmContacts({
|
||||
groupId: parseInt($stateParams.gid, 10),
|
||||
placement: $stateParams.placement
|
||||
});
|
||||
}
|
||||
|
||||
if ( $stateParams.gid ) {
|
||||
$scope.contactsExcList = new EmContactsEL({
|
||||
groupId: parseInt($stateParams.gid, 10)
|
||||
});
|
||||
}
|
||||
|
||||
if ( $scope.contacts ) {
|
||||
$scope.contacts.nextPage();
|
||||
}
|
||||
if ( $scope.contactsExcList ) {
|
||||
$scope.contactsExcList.nextPage();
|
||||
}
|
||||
});
|
||||
|
||||
app.factory('EmContacts', function($http, $q, emAuth, synConn, emGroups, emAccounts, EmDrf) {
|
||||
var EmContacts = function(opts) {
|
||||
opts = opts || {};
|
||||
this.items = [];
|
||||
this.busy = false;
|
||||
this.after = '';
|
||||
this.options = {
|
||||
groupId: null
|
||||
};
|
||||
|
||||
this.noMoreData = false;
|
||||
|
||||
angular.extend(this.options, opts);
|
||||
};
|
||||
|
||||
function resolveGroups(drafts, done) {
|
||||
var draftsToProcess = drafts.length;
|
||||
|
||||
for (var i = 0; i < drafts.length; i++) {
|
||||
emGroups.resolve(drafts[i].GroupList, function(err, resolved){
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
try {
|
||||
drafts[this.i].GroupList = JSON.parse(drafts[this.i].GroupList);
|
||||
} catch (e) {
|
||||
drafts[this.i].GroupList = [];
|
||||
}
|
||||
drafts[this.i].GroupListResolved = resolved;
|
||||
//drafts[this.i].GroupList = resolved;
|
||||
|
||||
emAccounts.resolve(drafts[this.i].AccountList, function(err, resolvedAccounts){
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
try {
|
||||
drafts[this.i].AccountList = JSON.parse(drafts[this.i].AccountList) || [];
|
||||
} catch (e) {
|
||||
drafts[this.i].AccountList = [];
|
||||
}
|
||||
drafts[this.i].AccountListResolved = resolvedAccounts;
|
||||
//drafts[this.i].AccountList = resolvedAccounts;
|
||||
|
||||
draftsToProcess -= 1;
|
||||
if ( draftsToProcess === 0 ) {
|
||||
done(drafts);
|
||||
}
|
||||
}.bind({ i: this.i }));
|
||||
}.bind({ i: i }));
|
||||
}
|
||||
}
|
||||
|
||||
function parseFields(fields) {
|
||||
if ( typeof fields === 'string' ) {
|
||||
try {
|
||||
fields = JSON.parse(fields);
|
||||
} catch(e) {
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
var res = {};
|
||||
angular.forEach(fields, function(fd){
|
||||
res[fd.Name] = fd.Value;
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
function reformatResponseObj(o) {
|
||||
var res = {
|
||||
Fields: {}
|
||||
};
|
||||
var directMappingFields = [
|
||||
'Email',
|
||||
'First_Name',
|
||||
'Last_Name',
|
||||
'Recipient_Name',
|
||||
'Subscribed',
|
||||
'Subscribe_Date'
|
||||
];
|
||||
|
||||
function createRX(fieldName) {
|
||||
var rxStr = '^'+fieldName.replace(/W+/, '.*?').toLowerCase()+'$';
|
||||
return new RegExp(rxStr, 'i');
|
||||
}
|
||||
|
||||
angular.forEach(directMappingFields, function(dmf){
|
||||
var rx = createRX(dmf);
|
||||
for ( var p in o ) {
|
||||
if ( rx.exec(p) ) {
|
||||
res[dmf] = o[p];
|
||||
delete o[p];
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
res.Fields = o;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
EmContacts.prototype.getExclusionList = function(done) {
|
||||
done = done || function(){};
|
||||
|
||||
if ( this._exclusionList ) {
|
||||
return done(null, this._exclusionList);
|
||||
} else {
|
||||
var start = 0;
|
||||
var uri = 'wp/{wpId}/group/ExclusionList?SELECT=*&WHERE=GroupID='+this.options.groupId+'&STARTINDEX='+start+'&RESULTS=25';
|
||||
|
||||
//var uri = 'Select Email, Date_Added from ExclusionList WHERE GROUPID=ID LIMIT 25 OFFSET 0"';
|
||||
|
||||
synConn
|
||||
.http({ uri: uri })
|
||||
.success(function(data){
|
||||
done(null, data);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
EmContacts.prototype.nextPage = function() {
|
||||
var that = this,
|
||||
defer = $q.defer();
|
||||
|
||||
if ( that.busy ) return;
|
||||
that.busy = true;
|
||||
|
||||
var start = this.items.length;
|
||||
|
||||
var groupWhere = (typeof this.options.groupId !== 'undefined' && this.options.groupId !== null)
|
||||
? '&where=GroupID='+this.options.groupId
|
||||
: '';
|
||||
var uri,
|
||||
isLocalGroup = this.options.placement == 'local';
|
||||
|
||||
if ( groupWhere ) {
|
||||
this.getExclusionList();
|
||||
}
|
||||
|
||||
if ( isLocalGroup ) {
|
||||
uri = 'wp/{wpId}/group/Emails?SELECT=*'+groupWhere+'&STARTINDEX='+start+'&RESULTS=25';
|
||||
} else { // remote
|
||||
uri = 'wp/{wpId}/settings/ConnectToDB?ID='+this.options.groupId+'&STARTINDEX='+start+'&RESULTS=25';
|
||||
}
|
||||
|
||||
synConn
|
||||
.http({ uri: uri })
|
||||
.success(function(data){
|
||||
|
||||
// console.warn('Got data: '+data.length);
|
||||
// console.log(data);
|
||||
|
||||
// no more emails
|
||||
if ( typeof data.fieldCount !== 'undefined' ) {
|
||||
that.busy = false;
|
||||
that.noMoreData = true;
|
||||
} else {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if ( isLocalGroup ) {
|
||||
if ( data[i].Fields ) {
|
||||
data[i].Fields = parseFields(data[i].Fields);
|
||||
}
|
||||
} else { // remote group
|
||||
data[i] = reformatResponseObj(data[i]);
|
||||
}
|
||||
that.items.push(data[i]);
|
||||
}
|
||||
that.busy = false;
|
||||
defer.resolve();
|
||||
}
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
console.error(err)
|
||||
});
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
return EmContacts;
|
||||
});
|
||||
|
||||
app.factory('EmContactsEL', function($http, $q, emAuth, synConn, emGroups, emAccounts, EmDrf) {
|
||||
var EmContactsEL = function(opts) {
|
||||
opts = opts || {};
|
||||
this.items = [];
|
||||
this.busy = false;
|
||||
this.after = '';
|
||||
this.options = {
|
||||
groupId: null
|
||||
};
|
||||
|
||||
this.noMoreData = false;
|
||||
|
||||
angular.extend(this.options, opts);
|
||||
};
|
||||
|
||||
EmContactsEL.prototype.nextPage = function() {
|
||||
var that = this,
|
||||
defer = $q.defer();
|
||||
|
||||
if ( that.busy ) return;
|
||||
that.busy = true;
|
||||
|
||||
var start = this.items.length;
|
||||
var uri = 'wp/{wpId}/group/ExclusionList?SELECT=*&WHERE=GroupID='+this.options.groupId+'&STARTINDEX='+start+'&RESULTS=25';
|
||||
|
||||
synConn
|
||||
.http({ uri: uri })
|
||||
.success(function(data){
|
||||
|
||||
// console.warn('Got data: '+data.length);
|
||||
// console.log(data);
|
||||
|
||||
// no more items
|
||||
if ( typeof data.fieldCount !== 'undefined' ) {
|
||||
that.busy = false;
|
||||
that.noMoreData = true;
|
||||
} else {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
that.items.push(data[i]);
|
||||
}
|
||||
that.busy = false;
|
||||
defer.resolve();
|
||||
}
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
return EmContactsEL;
|
||||
});
|
||||
|
||||
app.controller('ContactsSidebarMenuCtrl', function($scope, $stateParams, groups){
|
||||
var sortedGroups = {
|
||||
local: [],
|
||||
db: []
|
||||
};
|
||||
|
||||
$scope.wpid = $stateParams.wpid;
|
||||
|
||||
angular.forEach(groups, function(g){
|
||||
sortedGroups[ (g.GroupKind == 1) ? 'local':'db' ].push(g);
|
||||
});
|
||||
|
||||
$scope.groups = sortedGroups;
|
||||
});
|
||||
|
||||
var ContactsSidebarMenuCtrlResolve = {
|
||||
groups: function($q, synConn) {
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({
|
||||
uri: 'wp/{wpId}/settings/Groups?Select=ID,GroupName,GroupKind&WHERE=Hidden=0'
|
||||
})
|
||||
.success(function(data){
|
||||
angular.forEach(data, function(g){
|
||||
console.log(g.GroupKind);
|
||||
switch ( g.GroupKind ) {
|
||||
case 1: // internal
|
||||
g.type = 'My Groups';
|
||||
g.placement = 'local';
|
||||
break;
|
||||
case 0: // external
|
||||
case 2: //wpnewsman
|
||||
g.type = 'My Databases';
|
||||
g.placement = 'remote';
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
defer.resolve(data);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
}
|
||||
};
|
@@ -0,0 +1,549 @@
|
||||
function DraftsCtrl($scope, $http, $stateParams, EmDrafts, emAuth, synConn, emUtils) {
|
||||
|
||||
$scope.drafts = new EmDrafts({ showDeleted: $scope.subSection === 'trash' });
|
||||
|
||||
$scope.drfClick = function(drf) {
|
||||
$scope.drafts.activeItem = drf.ID;
|
||||
$scope.setEmail(drf);
|
||||
|
||||
openPreview(drf);
|
||||
};
|
||||
|
||||
$scope.drfDelete = function(ev, drf){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var delFromTrash = ($scope.subSection === 'trash');
|
||||
if ( delFromTrash && !confirm('Are sure you want to delete this draft?') ) { return; }
|
||||
drf.del(function(err){
|
||||
if ( !err ) {
|
||||
$scope.drafts.del(drf);
|
||||
}
|
||||
}, delFromTrash);
|
||||
};
|
||||
|
||||
$scope.drfRestore = function(ev, drf){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
drf.restore(function(err){
|
||||
if ( !err ) {
|
||||
$scope.drafts.del(drf);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
app.controller('DraftEditorCtrl', function($scope, $controller, $modal, $stateParams, emAuth, synConn, emUtils, emCategories, EmTemplates, EmDrafts, accounts, groups){
|
||||
$controller('CommonEditorController', { $scope: $scope });
|
||||
|
||||
$scope.stateParams = $stateParams;
|
||||
|
||||
var gotScopeItem;
|
||||
|
||||
$scope.itemType = '';
|
||||
$scope.accounts = accounts;
|
||||
$scope.account = [];
|
||||
|
||||
$scope.$watch('account', function(newVal){
|
||||
if ( $scope.item ) {
|
||||
var nv = parseInt(newVal, 10);
|
||||
$scope.item.AccountList = !isNaN(nv) ? [nv] : [];
|
||||
}
|
||||
});
|
||||
|
||||
$scope.groups = groups;
|
||||
$scope.to = [];
|
||||
|
||||
$scope.$watch('item', function(newVal){
|
||||
if ( typeof newVal !== 'undefined' && !newVal.then ) {
|
||||
$scope.to = $scope.item.GroupList;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$watch('to', function(newVal){
|
||||
if ( $scope.item ) {
|
||||
$scope.item.GroupList = newVal
|
||||
}
|
||||
});
|
||||
|
||||
$scope.enableTracking = false;
|
||||
|
||||
$scope.$watch('item', function(item){
|
||||
if ( typeof item !== 'undefined' && !item.then ) {
|
||||
$scope.enableTracking = item.TrackMethod > 0;
|
||||
}
|
||||
});
|
||||
|
||||
if ( $stateParams.draft ) {
|
||||
$scope.itemType = 'draft';
|
||||
|
||||
$scope.setItem( (new EmDrafts()).getDraft($stateParams.draft) );
|
||||
|
||||
var p = { root: 'drafts' };
|
||||
|
||||
gotScopeItem = function(drf) {
|
||||
//p.name = drf.Subject;
|
||||
p.item = drf;
|
||||
$scope.setItemParams(p);
|
||||
//$scope.item = drf;
|
||||
$scope.setItem(drf);
|
||||
|
||||
$scope.account = drf.AccountList[0];
|
||||
window.drf = drf;
|
||||
};
|
||||
}
|
||||
|
||||
// ----------
|
||||
|
||||
if ( $scope.item.then ) {
|
||||
$scope.item.then(
|
||||
gotScopeItem,
|
||||
function(err){
|
||||
console.error(err+'');
|
||||
}
|
||||
);
|
||||
} else {
|
||||
gotScopeItem($scope.item);
|
||||
}
|
||||
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.item.save(function(err){
|
||||
console.log(arguments);
|
||||
if ( !err ) {
|
||||
$scope.alert({ type:'success', msg: 'Successfully saved' });
|
||||
} else {
|
||||
$scope.alert({ type:'danger', msg: err+'' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.sendNow = function(){
|
||||
$scope.item.save(function(err){
|
||||
if ( !err ) {
|
||||
$scope.item.startSending(function(err, outboxEmlID){
|
||||
if ( !err ) {
|
||||
window.location.hash = '#/workplaces/'+emAuth.get('workplace').ID+'/outbox/'+outboxEmlID+'/preview';
|
||||
} else {
|
||||
$scope.alert({
|
||||
type:'danger',
|
||||
msg: err+''
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$scope.alert({
|
||||
type:'danger',
|
||||
msg: 'Error while saving draft: '+err
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.removeAttachment = function(fileName) {
|
||||
$scope.item.removeAttachment(fileName, function(err){
|
||||
if ( err ) { return console.error(err); }
|
||||
for (var i = $scope.item.AttachList.length - 1; i >= 0; i--) {
|
||||
if ( $scope.item.AttachList[i] == fileName ) {
|
||||
$scope.item.AttachList.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$scope.item.save();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
var DraftEditorResolve = {
|
||||
accounts: function($q, synConn) {
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({
|
||||
uri: 'wp/{wpId}/settings/Account?Select=AccountName,ID'
|
||||
})
|
||||
.success(function(data){
|
||||
defer.resolve(data);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
},
|
||||
groups: function($q, synConn) {
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({
|
||||
uri: 'wp/{wpId}/settings/Groups?Select=ID,GroupName,GroupKind&WHERE=Hidden=0'
|
||||
})
|
||||
.success(function(data){
|
||||
angular.forEach(data, function(g){
|
||||
g.type = (g.GroupKind == 1) ? 'My Groups' : 'My Databases';
|
||||
});
|
||||
defer.resolve(data);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
}
|
||||
};
|
||||
|
||||
app.factory('EmDrf', function($http, $q, synConn, emUtils, emAuth){
|
||||
var EmDrf = function(data){
|
||||
var defaults = {
|
||||
AccountList: [],
|
||||
PersonalAttachList: [],
|
||||
CID: 0,
|
||||
CName: "",
|
||||
CharSet: "UTF-8",
|
||||
ConfirmRead: 0,
|
||||
Deleted: 0,
|
||||
GroupList: [],
|
||||
Guid: '{'+emUtils.UUID()+'}',
|
||||
ID: 0,
|
||||
MailTo: "",
|
||||
MessageFormat: 0, // 1 - html, 0 - plain
|
||||
ModTime: (new Date()).getTime(),
|
||||
Priority: 3,
|
||||
Subject: "Please Enter Subject Here",
|
||||
TrackMethod: 0,
|
||||
TrackName: "",
|
||||
UseAnalytics: 0,
|
||||
};
|
||||
|
||||
angular.extend(this, defaults);
|
||||
|
||||
if ( typeof data !== 'undefined' ) {
|
||||
angular.extend(this, data);
|
||||
}
|
||||
|
||||
this.ModTime = emUtils.timeLogToDate(this.ModTime);
|
||||
|
||||
this.GroupList = this._map(this.GroupList, function(itm){ return parseInt(itm, 10); });
|
||||
this.AccountList = this._map(this.AccountList, function(itm){ return parseInt(itm, 10); });
|
||||
};
|
||||
var p = EmDrf.prototype;
|
||||
|
||||
p.getBaseURL = function() {
|
||||
return '/wps/drafts/'+emAuth.get('workplace').ID+'/'+this.Guid+'/';
|
||||
};
|
||||
|
||||
p._map = function(arr, mapper) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
arr[i] = mapper(arr[i], i);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
p.del = function(done, forever) {
|
||||
var req;
|
||||
if ( forever ) {
|
||||
req = {
|
||||
method: 'DELETE',
|
||||
uri: 'wp/{wpId}/settings/drafts/'+this.ID
|
||||
};
|
||||
} else {
|
||||
req = {
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/drafts/'+this.ID,
|
||||
data: {
|
||||
deleted: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
synConn
|
||||
.http(req)
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
p.restore = function(done) {
|
||||
synConn
|
||||
.http({
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/drafts/'+this.ID,
|
||||
data: {
|
||||
deleted: 0
|
||||
}
|
||||
})
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
p.save = function(done) {
|
||||
var _this = this;
|
||||
done = done || function(){};
|
||||
|
||||
var obj = {
|
||||
'ID': this.ID,
|
||||
'CharSet': 'UTF-8',
|
||||
'Subject': this.Subject,
|
||||
|
||||
'MessageFormat': 0, // 0 - html, 1 - plain
|
||||
'Guid': this.Guid,
|
||||
'EmailSource': emUtils.shrinkAssetURLs(this.EmailSource, this.getBaseURL()),
|
||||
'Name': this.TemplateName,
|
||||
|
||||
'TrackMethod': parseInt(this.TrackMethod, 10), // - numeric, values (0: not used; 1: google; 2: piwik)
|
||||
'TrackName': this.TrackName, // - string, tracking campaign name
|
||||
|
||||
'AccountList': this._map(this.AccountList, function(itm){ return itm+''; }), // converting array of nums into arr of strings
|
||||
'GroupList': this._map(this.GroupList, function(itm){ return itm+''; }), // ~
|
||||
'AttachList': this.AttachList,
|
||||
'PersonalAttachList': this.PersonalAttachList
|
||||
};
|
||||
|
||||
synConn
|
||||
.http({
|
||||
method: 'POST',
|
||||
uri: 'wp/{wpId}/settings/SetDraftMessage',
|
||||
data: obj
|
||||
})
|
||||
.success(function(data){
|
||||
_this.ID = data.ID;
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
p.setBody = function(body) {
|
||||
this.EmailSource = body;
|
||||
}
|
||||
|
||||
p.getBody = function() {
|
||||
var _this = this;
|
||||
if ( typeof this._data !== 'undefined' ) {
|
||||
return this.EmailSource;
|
||||
}
|
||||
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/GetDraftMessage?ID='+this.ID })
|
||||
.success(function(data){
|
||||
_this._data = data;
|
||||
|
||||
data.EmailSource = emUtils.unpackEmailSource(data.EmailSource);
|
||||
|
||||
//data.BaseURL = emUtils.supplant('/wps/drafts/{wpid}/{guid}/',{ guid: data.Guid, wpid: emAuth.get('workplace').ID });
|
||||
_this.EmailSource = emUtils.expandAssetURLs(data.EmailSource, _this.getBaseURL());
|
||||
defer.resolve(_this.EmailSource);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
p.startSending = function(done) {
|
||||
done = done || function(){};
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/SendDraftMessage?ID='+this.ID })
|
||||
.success(function(data){
|
||||
|
||||
console.warn('SendDraftMessage');
|
||||
console.log(data);
|
||||
done(null, data.ID);
|
||||
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
// SendDraftMessage
|
||||
// param - ID
|
||||
// StopSending - ID
|
||||
// SendMessage - ID
|
||||
};
|
||||
|
||||
p.removeAttachment = function(fileName, done) {
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/RemoveContent?GUID='+this.Guid+'&type=drafts&Folder=attachment&FileName='+fileName })
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
p.addAttachment = function(fileName) {
|
||||
var idx = this.AttachList.indexOf(fileName);
|
||||
if ( idx === -1 ) {
|
||||
this.AttachList.push(fileName);
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
||||
return EmDrf;
|
||||
});
|
||||
|
||||
app.factory('EmDrafts', function($http, $q, emAuth, synConn, emGroups, emAccounts, EmDrf) {
|
||||
var EmDrafts = function(opts) {
|
||||
opts = opts || {};
|
||||
this.items = [];
|
||||
this.busy = false;
|
||||
this.after = '';
|
||||
this.options = {
|
||||
showDeleted: false
|
||||
};
|
||||
|
||||
this.noMoreData = false;
|
||||
|
||||
angular.extend(this.options, opts);
|
||||
};
|
||||
|
||||
function resolveGroups(drafts, done) {
|
||||
var draftsToProcess = drafts.length;
|
||||
|
||||
for (var i = 0; i < drafts.length; i++) {
|
||||
emGroups.resolve(drafts[i].GroupList, function(err, resolved){
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
try {
|
||||
drafts[this.i].GroupList = JSON.parse(drafts[this.i].GroupList);
|
||||
} catch (e) {
|
||||
drafts[this.i].GroupList = [];
|
||||
}
|
||||
drafts[this.i].GroupListResolved = resolved;
|
||||
//drafts[this.i].GroupList = resolved;
|
||||
|
||||
emAccounts.resolve(drafts[this.i].AccountList, function(err, resolvedAccounts){
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
try {
|
||||
drafts[this.i].AccountList = JSON.parse(drafts[this.i].AccountList) || [];
|
||||
} catch (e) {
|
||||
drafts[this.i].AccountList = [];
|
||||
}
|
||||
drafts[this.i].AccountListResolved = resolvedAccounts;
|
||||
//drafts[this.i].AccountList = resolvedAccounts;
|
||||
|
||||
draftsToProcess -= 1;
|
||||
if ( draftsToProcess === 0 ) {
|
||||
done(drafts);
|
||||
}
|
||||
}.bind({ i: this.i }));
|
||||
}.bind({ i: i }));
|
||||
}
|
||||
}
|
||||
|
||||
EmDrafts.prototype.nextPage = function() {
|
||||
var that = this,
|
||||
defer = $q.defer();
|
||||
|
||||
if ( that.busy ) return;
|
||||
that.busy = true;
|
||||
|
||||
//var sql = 'ID, Subject, MailTo, Total, Processed, Sent, Excluded, Failed, Status, StatusMessage, CreateTime, UseAnalytics, CID, AccountList, GroupList, Deleted, Log From Outbox Order by CreateTime DESC LIMIT 10';
|
||||
var sql = '*';
|
||||
|
||||
var start = this.items.length;
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/Drafts?Select=*&where=deleted='+(this.options.showDeleted ? '1' : '0')+'&STARTINDEX='+start+'&RESULTS=10&SORT=ModTime&DIR=DESC' })
|
||||
.success(function(data){
|
||||
|
||||
// no more emails
|
||||
if ( typeof data.fieldCount !== 'undefined' ) {
|
||||
that.busy = false;
|
||||
that.noMoreData = true;
|
||||
} else {
|
||||
resolveGroups(data, function(drafts){
|
||||
for (var i = 0; i < drafts.length; i++) {
|
||||
that.items.push(new EmDrf(drafts[i]));
|
||||
}
|
||||
that.busy = false;
|
||||
defer.resolve();
|
||||
});
|
||||
}
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
console.error(err)
|
||||
});
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
EmDrafts.prototype.getDraft = function(id) {
|
||||
var tpl;
|
||||
|
||||
if ( this.items ) {
|
||||
angular.forEach(this.items, function(t, i){
|
||||
if ( t.ID == id ) {
|
||||
tpl = t;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if ( tpl ) {
|
||||
return tpl;
|
||||
}
|
||||
}
|
||||
|
||||
var defer = $q.defer();
|
||||
synConn
|
||||
//.http({ uri: 'wp/{wpId}/settings/Drafts?Select=*&where=ID='+id+'&RESULTS=1' })
|
||||
.http({ uri: 'wp/{wpId}/settings/GetDraftMessage?ID='+id })
|
||||
.success(function(data){
|
||||
defer.resolve( new EmDrf(data) );
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
});
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
EmDrafts.prototype.createDraft = function(done) {
|
||||
var _this = this;
|
||||
synConn
|
||||
.http({
|
||||
method: 'GET',
|
||||
uri: 'wp/{wpId}/settings/CreateNewMessage'
|
||||
})
|
||||
.success(function(draft){
|
||||
console.log('createDraft results:');
|
||||
console.log(draft);
|
||||
var drf = new EmDrf(draft)
|
||||
_this.items.push(drf);
|
||||
done(drf);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
EmDrafts.prototype.del = function(drf) {
|
||||
for (var i = 0; i < this.items.length; i++) {
|
||||
if ( this.items[i] === drf ) {
|
||||
this.items.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return EmDrafts;
|
||||
});
|
||||
|
@@ -0,0 +1,109 @@
|
||||
app.controller('ModalUploadAttachmentCtrl', function($scope, $modalInstance, emAuth, grfFiles, editItem, itemType, synConn){
|
||||
|
||||
$scope.files = grfFiles.items;
|
||||
|
||||
var uploadType;
|
||||
switch ( itemType ) {
|
||||
case 'template':
|
||||
uploadType = 'templates';
|
||||
break;
|
||||
case 'draft':
|
||||
uploadType = 'drafts';
|
||||
break;
|
||||
};
|
||||
|
||||
|
||||
grfFiles.attrs.action = synConn.getBaseURL()+'wp/'+emAuth.get('workplace').ID+'/settings/UploadContent?'+[
|
||||
'GUID='+editItem.Guid,
|
||||
'type='+uploadType,
|
||||
'folder=attachment'
|
||||
].join('&');
|
||||
|
||||
$scope.close = function () {
|
||||
var fileNames = [];
|
||||
angular.forEach($scope.files, function(f){
|
||||
fileNames.push(f.fileName);
|
||||
})
|
||||
$modalInstance.dismiss(fileNames);
|
||||
};
|
||||
|
||||
$scope.setFiles = function(element) {
|
||||
$scope.$apply(function($scope) {
|
||||
// Turn the FileList object into Array
|
||||
$scope.files = [];
|
||||
for (var i = 0; i < element.files.length; i++) {
|
||||
$scope.files.push(element.files[i])
|
||||
}
|
||||
$scope.progressVisible = false
|
||||
});
|
||||
};
|
||||
|
||||
$scope.uploadFile = function() {
|
||||
var fd = new FormData()
|
||||
for (var i in $scope.files) {
|
||||
fd.append("uploadedFile", $scope.files[i])
|
||||
}
|
||||
fd.append('path', $scope.upload.path);
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.upload.addEventListener("progress", uploadProgress, false)
|
||||
xhr.addEventListener("load", uploadComplete, false)
|
||||
xhr.addEventListener("error", uploadFailed, false)
|
||||
xhr.addEventListener("abort", uploadCanceled, false)
|
||||
xhr.open('PUT', '/wp/'+emAuth.workplace.ID+'/settings/UploadContent')
|
||||
$scope.progressVisible = true
|
||||
xhr.send(fd)
|
||||
}
|
||||
|
||||
function uploadProgress(evt) {
|
||||
$scope.$apply(function(){
|
||||
if (evt.lengthComputable) {
|
||||
$scope.progress = Math.round(evt.loaded * 100 / evt.total)
|
||||
} else {
|
||||
$scope.progress = 'unable to compute'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function uploadComplete(evt) {
|
||||
/* This event is raised when the server send back a response */
|
||||
$modalInstance.close(evt.target.responseText);
|
||||
}
|
||||
|
||||
function uploadFailed(evt) {
|
||||
alert("There was an error attempting to upload the file.")
|
||||
}
|
||||
|
||||
function uploadCanceled(evt) {
|
||||
$scope.$apply(function(){
|
||||
$scope.progressVisible = false
|
||||
})
|
||||
alert("The upload has been canceled by the user or the browser dropped the connection.")
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
app.controller('CommonEditorController', function($scope, $modal){
|
||||
$scope.addCommonAtt = function() {
|
||||
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'partials/modal-upload-attachment.html',
|
||||
controller: 'ModalUploadAttachmentCtrl',
|
||||
resolve: {
|
||||
itemType: function(){
|
||||
return $scope.itemType;
|
||||
},
|
||||
editItem: function(){
|
||||
return $scope.item;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
modalInstance.result.then(function (rel) {
|
||||
var r = angular.copy(rel);
|
||||
}, function (uploadedFiles) {
|
||||
angular.forEach(uploadedFiles, function(fn){
|
||||
$scope.item.addAttachment(fn);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@@ -0,0 +1,678 @@
|
||||
/*
|
||||
Setn log
|
||||
/wp/1/settings/GetSentItems?MessageID=6&SQL=Select+*+from+SentItems&LIMIT=10
|
||||
|
||||
Plain Log
|
||||
/wp/1/settings/Outbox/6/Log
|
||||
|
||||
*/
|
||||
|
||||
function EmailsCtrl($scope, $http, $stateParams, EmEmails, emAuth, synConn, emUtils, EmSentLog) {
|
||||
|
||||
$scope.emails = new EmEmails($scope, {
|
||||
showDeleted: $scope.subSection === 'trash'
|
||||
});
|
||||
|
||||
$scope.log = null;
|
||||
|
||||
$scope.activateEmail = function(eml) {
|
||||
$scope.log = null;
|
||||
|
||||
$scope.emails.activeItem = eml.ID;
|
||||
$scope.setEmail(eml);
|
||||
|
||||
if ( $scope.item && $scope.item.stopPolling ) {
|
||||
$scope.item.stopPolling();
|
||||
}
|
||||
|
||||
$scope.setItem(eml);
|
||||
|
||||
if ( eml.Status != 2 && eml.startPolling ) {
|
||||
eml.startPolling();
|
||||
}
|
||||
openPreview(eml);
|
||||
};
|
||||
|
||||
$scope.emlClick = function(eml) {
|
||||
window.location.hash = '#/workplaces/'+$scope.wpid+'/outbox/'+eml.ID+'/preview';
|
||||
};
|
||||
|
||||
$scope.startSending = function($scope, $http) {
|
||||
$http({ method: 'GET', url: '' })
|
||||
};
|
||||
|
||||
$scope.setPreview = function(){
|
||||
$scope.log = null;
|
||||
|
||||
$http({ method: 'GET', url: 'http://blog.dev/wp-admin/admin.php?page=newsman-templates&action=edit&id=16&tpl-source=1' })
|
||||
.success(function(data, status, headers, config) {
|
||||
|
||||
var zoomStyle = ['<style>',
|
||||
'html { ',
|
||||
'-ms-zoom: 0.65;',
|
||||
'-moz-transform:scale(0.65);',
|
||||
'-moz-tansform-origin: 0 0;',
|
||||
'-o-transform: scale(0.65);',
|
||||
'-o-transform-origin: 0 0;',
|
||||
'-webkit-transform: scale(0.65);',
|
||||
'-webkit-transform-origin: 0 0;',
|
||||
'}</style>'].join('');
|
||||
|
||||
data = data.replace('</head>', zoomStyle+'</head>');
|
||||
openPreview(data);
|
||||
// this callback will be called asynchronously
|
||||
// when the response is available
|
||||
})
|
||||
.error(function(data, status, headers, config) {
|
||||
// called asynchronously if an error occurs
|
||||
// or server returns response with an error status.
|
||||
});
|
||||
};
|
||||
|
||||
$scope.viewLog = function(emailId) {
|
||||
$scope.log = null;
|
||||
|
||||
var htmlWrapper = [
|
||||
'<html><head><style>',
|
||||
'pre {',
|
||||
'font-size: 12px;',
|
||||
'font-family: sans-serif;',
|
||||
'}',
|
||||
'</style></head><body><pre>{body}</pre></body></html>'].join('');
|
||||
|
||||
synConn
|
||||
.http({
|
||||
method: 'GET',
|
||||
uri: 'wp/{wpId}/settings/Outbox/'+emailId+'/Log'
|
||||
})
|
||||
.success(function(data){
|
||||
setIFrameContent(emUtils.supplant(htmlWrapper, { body: data }));
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.emDelete = function(eml) {
|
||||
var delFromTrash = $scope.subSection === 'trash';
|
||||
|
||||
if ( delFromTrash && !confirm('Are you sure you want to delete this email?') ) { return; }
|
||||
|
||||
eml.del(function(err){
|
||||
if ( err ) { console.log(err); return; }
|
||||
$scope.emails.del(eml);
|
||||
}, delFromTrash);
|
||||
};
|
||||
|
||||
$scope.viewSentLog = function(emailId, type) {
|
||||
$scope.log = new EmSentLog($scope, emailId, type);
|
||||
$scope.log.nextPage();
|
||||
}
|
||||
}
|
||||
|
||||
app.controller('EmailsItemDetailsCtrl', function($scope, $stateParams){
|
||||
|
||||
var subView = ( typeof $stateParams.subview === 'undefined' ) ? 'preview' : $stateParams.subview;
|
||||
|
||||
switch ( subView ) {
|
||||
case 'preview':
|
||||
$scope.emails.getEmail($stateParams.id, function(err, eml){
|
||||
if ( err ) { return console.error(err); }
|
||||
$scope.activateEmail(eml);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'log':
|
||||
$scope.viewLog($stateParams.id);
|
||||
break;
|
||||
|
||||
case 'processed':
|
||||
$scope.viewSentLog($stateParams.id, 'processed');
|
||||
break;
|
||||
|
||||
case 'sent':
|
||||
$scope.viewSentLog($stateParams.id, 'sent');
|
||||
break;
|
||||
|
||||
case 'failed':
|
||||
$scope.viewSentLog($stateParams.id, 'failed');
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
app.factory('EmEml', function($http, $q, synConn, emUtils, emAuth, $timeout, $interval){
|
||||
|
||||
var EmEml = function(data){
|
||||
var defaults = {
|
||||
AccountList: [],
|
||||
AttachList: [],
|
||||
Attempt: 0,
|
||||
Bounced: 0,
|
||||
CID: 0,
|
||||
CName: "",
|
||||
CharSet: "WINDOWS-1252",
|
||||
Complaint: 0,
|
||||
ConfirmRead: 0,
|
||||
CreateTime: 135125718208,
|
||||
Deleted: 0,
|
||||
Excluded: 0,
|
||||
Failed: 0,
|
||||
FinishTime: "",
|
||||
GroupList: [],
|
||||
Guid: '{'+emUtils.UUID()+'}',
|
||||
ID: 0,
|
||||
MailTo: "",
|
||||
MessageFormat: 0,
|
||||
Priority: 3,
|
||||
Processed: 2,
|
||||
ResumeTime: "",
|
||||
SendMode: 0,
|
||||
Sent: 2,
|
||||
StartTime: "",
|
||||
Status: 2, // 0- RedyForSent; 1 - InSent; 2- Sending Finished; 3 - Pending
|
||||
StatusMessage: "Finished [View Log]",
|
||||
Subject: "Pure Papers",
|
||||
Total: 0,
|
||||
Total_Clicks: 0,
|
||||
Total_Opens: 0,
|
||||
TrackMethod: 0,
|
||||
TrackName: "",
|
||||
Unique_Clicks: 0,
|
||||
Unique_Opens: 0,
|
||||
Unsubscribed: 0,
|
||||
UseAnalytics: 0,
|
||||
User: null
|
||||
};
|
||||
|
||||
angular.extend(this, defaults);
|
||||
if ( typeof data !== 'undefined' ) {
|
||||
angular.extend(this, data);
|
||||
}
|
||||
|
||||
this.CreateTime = emUtils.timeLogToDate(this.CreateTime);
|
||||
};
|
||||
|
||||
EmEml.status = {
|
||||
READY_FOR_SENT: 0,
|
||||
SENDING: 1,
|
||||
FINISHED: 2,
|
||||
PENDING: 3
|
||||
//0: RedyForSent; 1 - InSent; 2- Sending Finished; 3 - Pending
|
||||
};
|
||||
|
||||
EmEml.canBeSent = function(o) {
|
||||
var st = (typeof o === 'number') ? o : o.Status;
|
||||
var x =
|
||||
st == EmEml.status.FINISHED ||
|
||||
st == EmEml.status.READY_FOR_SENT;
|
||||
|
||||
return x;
|
||||
};
|
||||
|
||||
EmEml.canBeStopped = function(o) {
|
||||
var st = (typeof o === 'number') ? o : o.Status;
|
||||
var x =
|
||||
st == EmEml.status.PENDING ||
|
||||
st == EmEml.status.SENDING;
|
||||
return x;
|
||||
};
|
||||
|
||||
var p = EmEml.prototype;
|
||||
|
||||
p.getBaseURL = function() {
|
||||
return '/wps/outbox/'+emAuth.get('workplace').ID+'/'+this.Guid+'/';
|
||||
};
|
||||
|
||||
p.save = function(done) {
|
||||
var _this = this;
|
||||
done = done || function(){};
|
||||
|
||||
/*
|
||||
'/wp/1/settings/Drafts?session_signature=004888DF0000838811DF13D9',
|
||||
'POST',
|
||||
|
||||
'Content-Type: application/json; charset=UTF-8'
|
||||
|
||||
{
|
||||
"CharSet":"UTF-8",
|
||||
"Subject":"Test",
|
||||
"MailTo":"",
|
||||
"ModTime":135135803300,"UseAnalytics":false,"CID":0,"CName":"",
|
||||
"TrackMethod":0,"TrackName":"",
|
||||
"Priority":1,
|
||||
"ConfirmRead":false,"Deleted":false,"MessageFormat":0,"AttachList":"[]",
|
||||
"AccountList":"[\"1\"]",
|
||||
"GroupList":"[\"1\"]",
|
||||
"Guid":""
|
||||
}
|
||||
|
||||
//*/
|
||||
|
||||
//'id', 'MessageFormat', 'Guid', 'EmailSource', 'Name', 'Subject', 'AccountList', 'GroupList'
|
||||
|
||||
var obj = {
|
||||
'id': this.ID,
|
||||
'MessageFormat': 0, // 0 - html, 1 - plain
|
||||
'Guid': item.Guid,
|
||||
'EmailSource': emUtils.shrinkAssetURLs(this.EmailSource, this.getBaseURL()),
|
||||
'Subject': this.Subject,
|
||||
'AccountList': [],
|
||||
'GroupList': []
|
||||
};
|
||||
|
||||
synConn
|
||||
.http({
|
||||
method: 'POST',
|
||||
uri: 'wp/{wpId}/settings/SetOutboxMessage',
|
||||
data: obj
|
||||
})
|
||||
.success(function(data){
|
||||
_this.ID = data.ID;
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
p.setBody = function(body) {
|
||||
this.EmailSource = body;
|
||||
}
|
||||
|
||||
p.getBody = function() {
|
||||
var _this = this;
|
||||
if ( typeof this._data !== 'undefined' ) {
|
||||
return this.EmailSource;
|
||||
}
|
||||
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/GetOutboxMessage?ID='+this.ID })
|
||||
.success(function(data){
|
||||
_this._data = data;
|
||||
|
||||
try {
|
||||
data.EmailSource = emUtils.unpackEmailSource(data.EmailSource);
|
||||
} catch(e) {
|
||||
data.EmailSource = 'error';
|
||||
defer.reject(e);
|
||||
}
|
||||
|
||||
|
||||
//data.BaseURL = emUtils.supplant('/wps/outbox/{wpid}/{guid}/',{ guid: data.Guid, wpid: emAuth.get('workplace').ID });
|
||||
_this.EmailSource = emUtils.expandAssetURLs(data.EmailSource, _this.getBaseURL());
|
||||
defer.resolve(_this.EmailSource);
|
||||
|
||||
//this.CreateTime = emUtils.timeLogToDate(this.CreateTime);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
p.reloadData = function(done) {
|
||||
done = done || function(){};
|
||||
var _this = this;
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/GetOutboxMessage?ID='+this.ID })
|
||||
.success(function(data){
|
||||
_this._data = data;
|
||||
|
||||
try {
|
||||
data.EmailSource = emUtils.unpackEmailSource(data.EmailSource);
|
||||
} catch(e) {
|
||||
data.EmailSource = 'error';
|
||||
}
|
||||
|
||||
|
||||
//data.BaseURL = emUtils.supplant('/wps/outbox/{wpid}/{guid}/',{ guid: data.Guid, wpid: emAuth.get('workplace').ID });
|
||||
_this.EmailSource = emUtils.expandAssetURLs(data.EmailSource, _this.getBaseURL());
|
||||
|
||||
// refreshing the rest of data
|
||||
if ( typeof data !== 'undefined' ) {
|
||||
angular.extend(_this, data);
|
||||
}
|
||||
done(null, data);
|
||||
//this.CreateTime = emUtils.timeLogToDate(this.CreateTime);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
p.del = function(done, forever) {
|
||||
var req;
|
||||
|
||||
if ( forever ) {
|
||||
req = {
|
||||
method: 'DELETE',
|
||||
uri: 'wp/{wpId}/settings/outbox/'+this.ID
|
||||
};
|
||||
} else {
|
||||
req = {
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/outbox/'+this.ID,
|
||||
data: {
|
||||
deleted: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
synConn
|
||||
.http(req)
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
p.startPolling = function() {
|
||||
var _this = this;
|
||||
this.pollForUpdates();
|
||||
};
|
||||
|
||||
p.stopPolling = function() {
|
||||
if ( this.pollTO ) {
|
||||
$timeout.cancel(this.pollTO);
|
||||
}
|
||||
};
|
||||
|
||||
p.pollForUpdates = function(){
|
||||
var _this = this;
|
||||
_this.reloadData(function(err, data){
|
||||
if ( !err && data && typeof _this._oldStatus !== 'undefined' && _this._oldStatus !== data.Status ) {
|
||||
// if status changed - stop the polling
|
||||
delete _this._oldStatus;
|
||||
return;
|
||||
}
|
||||
_this.pollTO = $timeout(function(){
|
||||
_this.pollForUpdates();
|
||||
}, 3000);
|
||||
});
|
||||
};
|
||||
|
||||
p.startSending = function() {
|
||||
var _this = this;
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/SendMessage?ID='+this.ID })
|
||||
.success(function(data){
|
||||
|
||||
_this.startPolling();
|
||||
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(data);
|
||||
});
|
||||
};
|
||||
|
||||
p.stopSending = function() {
|
||||
var _this = this;
|
||||
|
||||
this._oldStatus = this.Status;
|
||||
|
||||
// saving old status, then check in poll function for changes and stop
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/StopSending?ID='+this.ID })
|
||||
.success(function(data){
|
||||
|
||||
$timeout(function(){
|
||||
_this.reloadData();
|
||||
}, 3000);
|
||||
|
||||
// if ( typeof data !== 'undefined' ) {
|
||||
// angular.extend(this, data);
|
||||
// }
|
||||
|
||||
// this.CreateTime = emUtils.timeLogToDate(this.CreateTime);
|
||||
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
});
|
||||
// SendDraftMessage
|
||||
// param - ID
|
||||
// StopSending - ID
|
||||
// SendMessage - ID
|
||||
};
|
||||
|
||||
return EmEml;
|
||||
});
|
||||
|
||||
// Reddit constructor function to encapsulate HTTP and pagination logic
|
||||
app.factory('EmEmails', function($http, $q, emAuth, synConn, emGroups, emAccounts, EmEml) {
|
||||
var EmEmails = function($scope, opts) {
|
||||
opts = opts || {};
|
||||
this.$scope = $scope;
|
||||
this.items = [];
|
||||
this.busy = false;
|
||||
this.after = '';
|
||||
this.noMoreData = false;
|
||||
this.options = {
|
||||
showDeleted: false
|
||||
};
|
||||
angular.extend(this.options, opts);
|
||||
this.m = new Emmi();
|
||||
};
|
||||
|
||||
EmEmails.prototype.getEmail = function(id, done) {
|
||||
var _this = this;
|
||||
|
||||
if ( !this.items.length ) {
|
||||
this.m.once('data', function(){
|
||||
_this.getEmail(id, done);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var found = false;
|
||||
angular.forEach(this.items, function(eml){
|
||||
if ( eml.ID == id ) {
|
||||
done(null, eml);
|
||||
found = true;
|
||||
return false; // breaking the loop
|
||||
}
|
||||
});
|
||||
if ( !found ) {
|
||||
done(new Error('Email with id '+id+' is not found.'));
|
||||
}
|
||||
};
|
||||
|
||||
EmEmails.prototype.nextPage = function() {
|
||||
var that = this,
|
||||
defer = $q.defer();
|
||||
|
||||
if ( that.noMoreData ) { return; }
|
||||
if ( that.busy ) return;
|
||||
|
||||
that.busy = true;
|
||||
|
||||
var sql = '*';
|
||||
|
||||
function resolveGroups(emails, done) {
|
||||
|
||||
var emailsToProcess = emails.length;
|
||||
|
||||
for (var i = 0; i < emails.length; i++) {
|
||||
|
||||
emGroups.resolve(emails[i].GroupList, function(err, resolved){
|
||||
if (err) { return console.log(err); }
|
||||
emails[this.i].resGroupList = resolved;
|
||||
|
||||
emAccounts.resolve(emails[this.i].AccountList, function(err, resolvedAccounts){
|
||||
if (err) { return console.log(err); }
|
||||
|
||||
emails[this.i].resAccountList = resolvedAccounts;
|
||||
|
||||
emailsToProcess -= 1;
|
||||
if ( emailsToProcess === 0 ) {
|
||||
done(emails);
|
||||
}
|
||||
|
||||
}.bind({ i: this.i }));
|
||||
|
||||
}.bind({ i: i }));
|
||||
}
|
||||
}
|
||||
|
||||
var start = this.items.length;
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/Outbox?Select=*&where=deleted='+(this.options.showDeleted ? '1' : '0')+'&STARTINDEX='+start+'&RESULTS=10&SORT=CreateTime&DIR=DESC' })
|
||||
.success(function(data){
|
||||
|
||||
// no more emails
|
||||
if ( typeof data.fieldCount !== 'undefined' ) {
|
||||
that.busy = false;
|
||||
that.noMoreData = true;
|
||||
} else {
|
||||
resolveGroups(data, function(emails){
|
||||
for (var i = 0; i < emails.length; i++) {
|
||||
that.items.push(new EmEml(emails[i]));
|
||||
}
|
||||
that.busy = false;
|
||||
that.m.emit('data');
|
||||
defer.resolve();
|
||||
});
|
||||
}
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
console.error(err)
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
EmEmails.prototype.del = function(eml) {
|
||||
for (var i = 0; i < this.items.length; i++) {
|
||||
if ( this.items[i] === eml ) {
|
||||
this.items.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return EmEmails;
|
||||
});
|
||||
|
||||
app.factory('EmSentLog', function($http, $q, emAuth, synConn, emGroups, emAccounts, EmEml) {
|
||||
var EmSentLog = function($scope, msgId, type) {
|
||||
this.$scope = $scope;
|
||||
this.type = type;
|
||||
this.msgId = msgId;
|
||||
this.items = [];
|
||||
this.busy = false;
|
||||
this.noMoreData = false;
|
||||
this.after = '';
|
||||
};
|
||||
|
||||
EmSentLog.prototype.nextPage = function() {
|
||||
var that = this,
|
||||
defer = $q.defer();
|
||||
|
||||
if ( that.busy || that.noMoreData ) return;
|
||||
that.busy = true;
|
||||
|
||||
function resolveGroups(emails, done) {
|
||||
|
||||
var emailsToProcess = emails.length;
|
||||
|
||||
for (var i = 0; i < emails.length; i++) {
|
||||
|
||||
emGroups.resolve(emails[i].GroupList, function(err, resolved){
|
||||
if (err) { throw err; }
|
||||
emails[this.i].GroupList = resolved;
|
||||
|
||||
emAccounts.resolve(emails[this.i].AccountList, function(err, resolvedAccounts){
|
||||
if (err) { throw err; }
|
||||
|
||||
emails[this.i].AccountList = resolvedAccounts;
|
||||
|
||||
emailsToProcess -= 1;
|
||||
if ( emailsToProcess === 0 ) {
|
||||
done(emails);
|
||||
}
|
||||
}.bind({ i: this.i }));
|
||||
}.bind({ i: i }));
|
||||
}
|
||||
}
|
||||
|
||||
var start = this.items.length;
|
||||
|
||||
/*
|
||||
$$hashKey: "01Q"
|
||||
Clicked: 0
|
||||
Email: "sales@cartridgecare.com"
|
||||
GroupName: "Import From SQL Server EasyMail"
|
||||
ID: 1
|
||||
LastResponse: "63"
|
||||
Log: "PFNlbmRSYXdFbWFpbFJlc3BvbnNlIHhtbG5zPSJodHRwOi8vc2VzLmFtYXpvbmF3cy5jb20vZG9jLzIwMTAtMTItMDEvIj4KICA8U2VuZFJhd0VtYWlsUmVzdWx0PgogICAgPE1lc3NhZ2VJZD4wMDAwMDE0MTNiN2RjY2E2LWExMTdhMjllLWIwYzAtNGI0NS05ZTRlLTQ2ZmE1MTlhMThkYy0wMDAwMDA8L01lc3NhZ2VJZD4KICA8L1NlbmRSYXdFbWFpbFJlc3VsdD4KICA8UmVzcG9uc2VNZXRhZGF0YT4KICAgIDxSZXF1ZXN0SWQ+ZjU4NzBmMmItMjFmNS0xMWUzLWEwNWEtMjc4Y2Q5NmI3ZGFmPC9SZXF1ZXN0SWQ+CiAgPC9SZXNwb25zZU1ldGFkYXRhPgo8L1NlbmRSYXdFbWFpbFJlc3BvbnNlPgoNCg0KODg5"
|
||||
Opened: 0
|
||||
RecipientName: "cartridgecare"
|
||||
SendDate: "2013-09-20T13:10:44"
|
||||
Status: 1
|
||||
*/
|
||||
var ipp = 25,
|
||||
sql = '';
|
||||
|
||||
switch (this.type) {
|
||||
case 'processed':
|
||||
sql = 'Select * from SentItems LIMIT '+start+','+ipp;
|
||||
break;
|
||||
case 'sent':
|
||||
sql = 'Select * from SentItems where Status = 1 LIMIT '+start+','+ipp;
|
||||
break;
|
||||
case 'failed':
|
||||
sql = 'Select * from SentItems where Status != 1 LIMIT '+start+','+ipp;
|
||||
break;
|
||||
}
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/GetSentItems?MessageID='+this.msgId+'&SQL='+sql.replace(/\s+/g, '+') })
|
||||
.success(function(data){
|
||||
|
||||
if ( typeof data.fieldCount !== 'undefined' ) {
|
||||
that.busy = false;
|
||||
that.noMoreData = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
data[i].SendDate = new Date(data[i].SendDate);
|
||||
switch ( data[i].Status ) {
|
||||
case 1:
|
||||
data[i].StatusText = 'Successfully delivered';
|
||||
break;
|
||||
case 2:
|
||||
data[i].StatusText = 'Temporary error. Sending attempt will be repeted in a minute';
|
||||
break;
|
||||
case 3:
|
||||
data[i].StatusText = 'Error';
|
||||
break;
|
||||
}
|
||||
that.items.push(data[i]);
|
||||
}
|
||||
that.busy = false;
|
||||
defer.resolve();
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
return EmSentLog;
|
||||
});
|
@@ -0,0 +1,454 @@
|
||||
function TemplatesCtrl($scope, $http, $location, $stateParams, $state, EmTemplates, emAuth, synConn, emUtils) {
|
||||
|
||||
var sub = $stateParams.folder || $scope.subSection;
|
||||
|
||||
$scope.setSub(sub);
|
||||
$scope.templates = new EmTemplates($scope, sub);
|
||||
|
||||
function expandAssetURLs(src, baseURL) {
|
||||
|
||||
function replacer(match, p1, p2, p3, p4) {
|
||||
var url = p3;
|
||||
|
||||
if ( url.match(/^\w+:\/\//) ) {
|
||||
return p1+url+p4;
|
||||
}
|
||||
|
||||
if ( baseURL[baseURL.length-1] !== '/' && url[0] !== '/' ) { baseURL += '/'; }
|
||||
|
||||
url = baseURL+url;
|
||||
return p1+url+p4;
|
||||
}
|
||||
|
||||
return src
|
||||
.replace(/(\b(?:src|url|background)=(\\\'|"))(.*?)(\2)/ig, replacer)
|
||||
.replace(/(\burl\(([\\\'"]{0,1}))(.*?)(\2\))/ig, replacer);
|
||||
}
|
||||
|
||||
$scope.tplClick = function(tpl) {
|
||||
$scope.templates.activeItem = tpl.ID;
|
||||
$scope.item = tpl;
|
||||
|
||||
var tpl = $scope.templates.getTemplate(tpl.ID);
|
||||
openPreview(tpl);
|
||||
};
|
||||
|
||||
$scope.tplDelete = function(e, tpl) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
var delfromTrash = $scope.subSection === 'trash';
|
||||
if ( delfromTrash && !confirm('Are you sure you want to delete this template?') ) { return; }
|
||||
tpl.del(function(err){
|
||||
if ( err ) { console.log(err); return; }
|
||||
$scope.templates.del(tpl);
|
||||
}, delfromTrash);
|
||||
};
|
||||
|
||||
$scope.tplRestore = function(e, tpl) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
tpl.restore(function(err){
|
||||
if ( err ) { console.log(err); return; }
|
||||
$scope.templates.del(tpl);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.tplCreateMsg = function(e, tpl) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
synConn
|
||||
.http({
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/NewMessageFromTemplate?ID='+tpl.ID
|
||||
})
|
||||
.success(function(data){
|
||||
$location.path('/workplaces/'+emAuth.get('workplace').ID+'/drafts/'+data.ID+'/edit');
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.startSending = function($scope, $http) {
|
||||
$http({ method: 'GET', url: '' })
|
||||
};
|
||||
|
||||
$scope.setPreview = function(){
|
||||
|
||||
$http({ method: 'GET', url: 'http://blog.dev/wp-admin/admin.php?page=newsman-templates&action=edit&id=16&tpl-source=1' })
|
||||
.success(function(data, status, headers, config) {
|
||||
|
||||
var zoomStyle = ['<style>',
|
||||
'html { ',
|
||||
'-ms-zoom: 0.65;',
|
||||
'-moz-transform:scale(0.65);',
|
||||
'-moz-tansform-origin: 0 0;',
|
||||
'-o-transform: scale(0.65);',
|
||||
'-o-transform-origin: 0 0;',
|
||||
'-webkit-transform: scale(0.65);',
|
||||
'-webkit-transform-origin: 0 0;',
|
||||
'}</style>'].join('');
|
||||
|
||||
data = data.replace('</head>', zoomStyle+'</head>');
|
||||
openPreview(data);
|
||||
// this callback will be called asynchronously
|
||||
// when the response is available
|
||||
})
|
||||
.error(function(data, status, headers, config) {
|
||||
// called asynchronously if an error occurs
|
||||
// or server returns response with an error status.
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
app.controller('TemplateEditorCtrl', function($scope, $controller, $modal, $stateParams, emAuth, synConn, emUtils, emCategories, EmTemplates, groups){
|
||||
$controller('CommonEditorController', { $scope: $scope });
|
||||
|
||||
$scope.stateParams = $stateParams;
|
||||
|
||||
var gotScopeItem;
|
||||
|
||||
$scope.itemType = '';
|
||||
|
||||
$scope.groups = groups;
|
||||
$scope.to = [];
|
||||
|
||||
$scope.$watch('item', function(newVal){
|
||||
if ( typeof newVal !== 'undefined' && !newVal.then ) {
|
||||
$scope.to = $scope.item.GroupList;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$watch('to', function(newVal){
|
||||
if ( $scope.item ) {
|
||||
$scope.item.GroupList = newVal
|
||||
}
|
||||
});
|
||||
|
||||
$scope.enableTracking = false;
|
||||
|
||||
$scope.$watch('item', function(item){
|
||||
if ( typeof item !== 'undefined' && !item.then ) {
|
||||
$scope.enableTracking = item.TrackMethod > 0;
|
||||
}
|
||||
});
|
||||
|
||||
if ( $stateParams.template ) {
|
||||
$scope.itemType = 'template';
|
||||
|
||||
$scope.setItem( (new EmTemplates()).getTemplate($stateParams.template) );
|
||||
|
||||
var p = { root: 'templates' };
|
||||
|
||||
gotScopeItem = function(tpl) {
|
||||
//p.name = drf.Subject;
|
||||
p.item = tpl;
|
||||
$scope.setItemParams(p);
|
||||
//$scope.item = tpl;
|
||||
$scope.setItem(tpl);
|
||||
window.tpl = tpl;
|
||||
};
|
||||
}
|
||||
|
||||
// ----------
|
||||
|
||||
if ( $scope.item.then ) {
|
||||
$scope.item.then(
|
||||
gotScopeItem,
|
||||
function(err){
|
||||
console.error(err);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
gotScopeItem($scope.item);
|
||||
}
|
||||
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.item.save(function(err){
|
||||
$scope.alert({
|
||||
type:'success',
|
||||
msg: 'Successfully saved'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
var TemplateEditorResolve = {
|
||||
groups: function($q, synConn) {
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({
|
||||
uri: 'wp/{wpId}/settings/Groups?Select=ID,GroupName,GroupKind&WHERE=Hidden=0'
|
||||
})
|
||||
.success(function(data){
|
||||
angular.forEach(data, function(g){
|
||||
g.type = (g.GroupKind == 1) ? 'My Groups' : 'My Databases';
|
||||
});
|
||||
defer.resolve(data);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
}
|
||||
};
|
||||
|
||||
app.factory('EmTpl', function($http, $q, synConn, emUtils, emAuth){
|
||||
var EmTpl = function(data){
|
||||
|
||||
var defaults = {
|
||||
AttachList: "[]",
|
||||
CategoryID: 0,
|
||||
CharSet: "UTF-8",
|
||||
GroupList: [],
|
||||
Guid: "{"+emUtils.UUID()+"}",
|
||||
//ID: 17,
|
||||
MessageFormat: 0,
|
||||
ModTime: (new Date()).getTime(),
|
||||
//StoreID: 6,
|
||||
Subject: "No Subject",
|
||||
TemplateName: "Unnamed",
|
||||
};
|
||||
|
||||
angular.extend(this, defaults);
|
||||
if ( typeof data !== 'undefined' ) {
|
||||
angular.extend(this, data);
|
||||
}
|
||||
this.ModTime = emUtils.timeLogToDate(this.ModTime);
|
||||
|
||||
this.GroupList = this._map(this.GroupList, function(itm){ return (typeof itm === 'string') ? parseInt(itm, 10) : itm; });
|
||||
};
|
||||
var p = EmTpl.prototype;
|
||||
|
||||
p.getBaseURL = function() {
|
||||
return '/wps/templates/'+emAuth.get('workplace').ID+'/'+this.Guid+'/';
|
||||
};
|
||||
|
||||
p._map = function(arr, mapper) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
arr[i] = mapper(arr[i], i);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
p.save = function(done) {
|
||||
done = done || function(){};
|
||||
|
||||
var obj = {
|
||||
ID: this.ID,
|
||||
CharSet : 'UTF-8',
|
||||
CategoryID: 0,
|
||||
TemplateName: this.TemplateName,
|
||||
Subject: this.Subject,
|
||||
MessageFormat: 0, // 0 - html, 1 - plain
|
||||
GroupList: this._map(this.GroupList, function(itm){ return itm+''; }), // ~
|
||||
AttachList: this.AttachList,
|
||||
Guid: item.Guid
|
||||
};
|
||||
|
||||
if ( typeof this._data !== 'undefined' ) {
|
||||
obj.EmailSource = emUtils.shrinkAssetURLs(this.EmailSource, this.getBaseURL());
|
||||
}
|
||||
|
||||
synConn
|
||||
.http({
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/SetTemplateMessage',
|
||||
data: obj
|
||||
})
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
p.setBody = function(body) {
|
||||
this.EmailSource = body;
|
||||
}
|
||||
|
||||
p.getBody = function() {
|
||||
var _this = this;
|
||||
if ( typeof this._data !== 'undefined' ) {
|
||||
return this.EmailSource;
|
||||
}
|
||||
|
||||
var defer = $q.defer();
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/GetTemplateMessage?ID='+this.ID })
|
||||
.success(function(data){
|
||||
_this._data = data;
|
||||
_this.Guid = data.Guid;
|
||||
data.EmailSource = emUtils.unpackEmailSource(data.EmailSource);
|
||||
_this.EmailSource = emUtils.expandAssetURLs(data.EmailSource, _this.getBaseURL());
|
||||
defer.resolve(_this.EmailSource);
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
p.del = function(done, forever) {
|
||||
var req;
|
||||
if ( forever ) {
|
||||
req = {
|
||||
method: 'DELETE',
|
||||
uri: 'wp/{wpId}/settings/templates/'+this.ID
|
||||
};
|
||||
} else {
|
||||
req = {
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/templates/'+this.ID,
|
||||
data: {
|
||||
CategoryID: -1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
synConn
|
||||
.http(req)
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
p.restore = function(done) {
|
||||
synConn
|
||||
.http({
|
||||
method: 'PUT',
|
||||
uri: 'wp/{wpId}/settings/templates/'+this.ID,
|
||||
data: {
|
||||
CategoryID: 0
|
||||
}
|
||||
})
|
||||
.success(function(data){
|
||||
done(null);
|
||||
})
|
||||
.error(function(err){
|
||||
console.error(err);
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
|
||||
return EmTpl;
|
||||
});
|
||||
|
||||
app.factory('EmTemplates', function($http, $q, emAuth, synConn, emGroups, emAccounts, EmTpl) {
|
||||
var EmTemplates = function($scope, cat) {
|
||||
this.$scope = $scope;
|
||||
this.items = [];
|
||||
this.busy = false;
|
||||
this.noMoreData = false;
|
||||
this.after = '';
|
||||
this.category = cat ? cat : 0;
|
||||
|
||||
if ( this.category === 'trash' ) {
|
||||
this.category = -1;
|
||||
}
|
||||
};
|
||||
|
||||
function resolveGroups(templates, done) {
|
||||
var templatesToProcess = templates.length;
|
||||
|
||||
for (var i = 0; i < templates.length; i++) {
|
||||
emGroups.resolve(templates[i].GroupList, function(err, resolved){
|
||||
if (err) { throw err; }
|
||||
templates[this.i].GroupList = resolved;
|
||||
templatesToProcess -= 1;
|
||||
if ( templatesToProcess === 0 ) {
|
||||
done(templates);
|
||||
}
|
||||
}.bind({ i: i }));
|
||||
}
|
||||
}
|
||||
|
||||
EmTemplates.prototype.getTemplate = function(id) {
|
||||
|
||||
var tpl;
|
||||
|
||||
if ( this.items ) {
|
||||
angular.forEach(this.items, function(t, i){
|
||||
if ( t.ID == id ) {
|
||||
tpl = t;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if ( tpl ) {
|
||||
return tpl;
|
||||
}
|
||||
}
|
||||
|
||||
var defer = $q.defer();
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/GetTemplateMessage?ID='+id })
|
||||
.success(function(data){
|
||||
defer.resolve(new EmTpl(data));
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
});
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
EmTemplates.prototype.nextPage = function() {
|
||||
var that = this,
|
||||
defer = $q.defer();
|
||||
|
||||
if ( that.busy ) return;
|
||||
that.busy = true;
|
||||
|
||||
var sql = '*';
|
||||
var start = this.items.length;
|
||||
|
||||
synConn
|
||||
.http({ uri: 'wp/{wpId}/settings/Templates?Select=*&where=CategoryID='+that.category+'&STARTINDEX='+start+'&RESULTS=10&SORT=ModTime&DIR=DESC' })
|
||||
.success(function(data){
|
||||
if ( typeof data.fieldCount !== 'undefined' ) {
|
||||
// no more templates
|
||||
that.busy = false;
|
||||
that.noMoreData = true;
|
||||
} else {
|
||||
resolveGroups(data, function(templates){
|
||||
for (var i = 0; i < templates.length; i++) {
|
||||
that.items.push(new EmTpl(templates[i]));
|
||||
}
|
||||
that.busy = false;
|
||||
defer.resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
.error(function(err){
|
||||
defer.reject(err);
|
||||
console.error(err)
|
||||
});
|
||||
return defer.promise;
|
||||
};
|
||||
|
||||
EmTemplates.prototype.del = function(tpl) {
|
||||
for (var i = 0; i < this.items.length; i++) {
|
||||
if ( this.items[i].id == tpl.id ) {
|
||||
this.items.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return EmTemplates;
|
||||
});
|
Reference in New Issue
Block a user