From 1a5f5bc312b500cc3492604febe4e9730ac2f1ee Mon Sep 17 00:00:00 2001 From: alban Date: Sat, 21 Jun 2014 22:45:03 +0200 Subject: [PATCH] [fix] emails --- models/collections.js | 30 ++++++++++++++++++++++++++++++ models/item.js | 2 +- models/itemsMapper.js | 13 ++++++------- server/main.js | 4 ++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/models/collections.js b/models/collections.js index d26496f..85bf62e 100644 --- a/models/collections.js +++ b/models/collections.js @@ -3,3 +3,33 @@ Items = new Meteor.Collection("items"); Versions = new Meteor.Collection("versions"); Drafts = new Meteor.Collection("drafts"); + +/* + * @todo : build lists when Items collection ready +distinct = function( options ){ + + var field = options["field"], + distinctList = options["distinctList"] || [], + srcList = options["srcList"] || [], + idList = options["idList"] || {} + ; + _.each(srcList,function(a,b){ + var f = a[field] + if ( f && distinctList.indexOf( f ) === -1 ) { + distinctList.push(f); + idList[f] = []; + } + idList[f].push(a.name); + }) +} +var categoryList = [] +var categoryIdList = {} +var itemList = Items.find().fetch() +distinct( { + + field: "category", + srcList: itemList, + distinctList : categoryList, + idList : categoryIdList +}) +*/ \ No newline at end of file diff --git a/models/item.js b/models/item.js index be1b11b..2d478ee 100644 --- a/models/item.js +++ b/models/item.js @@ -35,4 +35,4 @@ Item = function(name){ return addslashes(instance.name); } return instance; -} +} \ No newline at end of file diff --git a/models/itemsMapper.js b/models/itemsMapper.js index 6a6ca3e..9c707d2 100644 --- a/models/itemsMapper.js +++ b/models/itemsMapper.js @@ -88,7 +88,8 @@ ItemsMapper = { newItem = newItem || null, user = Meteor.user(), item_name = currentItem.name, - email + email, + link = Router.url("item",{"name":item_name}) ; // Attempts to retrieve user email if( "emails" in user && user.emails.length && "address" in user.emails[0] ){ @@ -130,9 +131,8 @@ ItemsMapper = { // send email to admin team Meteor.call('sendEmail', email, - 'admin@nsa-observer.net', - 'NSAOBS : '+item_name+' VERSION by '+email, - JSON.stringify(draftVersion) + 'NSAOBS : VERSION '+item_name+' by '+email, + link ); }catch(err){ alert("An error occured : failed to send admin team the notification email."); @@ -156,9 +156,8 @@ ItemsMapper = { // send email to admin team Meteor.call('sendEmail', email, - 'admin@nsa-observer.net', - 'NSAOBS : '+item_name+' DRAFT by '+email, - JSON.stringify(draftVersion) + 'NSAOBS : DRAFT '+item_name+' by '+email, + link ); }catch(err){ alert("An error occured : failed to send admin team the notification email."); diff --git a/server/main.js b/server/main.js index c6c3908..4caa6de 100644 --- a/server/main.js +++ b/server/main.js @@ -1,7 +1,7 @@ // In your server code: define a method that the client can call Meteor.methods({ - sendEmail: function (from, to, subject, text) { - check([from, subject, text], [String]); + sendEmail: function (from, subject, text) { +// check([from, subject, text], [String]); // Let other method calls from the same client start running, // without waiting for the email sending to complete.