/*jslint browser : true, continue : true, devel : true, indent : 2, maxerr : 50, newcap : true, nomen : true, plusplus : true, regexp : true, sloppy : true, vars : false, white : true */ /*global $, app */ app.subnotify = (function () { 'use strict'; //---------------- BEGIN MODULE SCOPE VARIABLES -------------- var stateMap = {}, configModule, initModule, onSend; //----------------- END MODULE SCOPE VARIABLES --------------- //------------------- BEGIN UTILITY METHODS ------------------ //-------------------- END UTILITY METHODS ------------------- //------------------- BEGIN EVENT HANDLERS ------------------- ///////////////////////// //SEND (create draft) of renewal warning notification email // onSend = function (event) { event.preventDefault(); //Gather purchase id's var s = $(this).data("purchaseidlist"); if(s==undefined || s==null){ return false; } //Convert string of comma separate numeric values to numeric array var ids = new Array(); if (typeof s == 'string') { ids = s.split(","); var arrayLength = ids.length; for (var i = 0; i < arrayLength; i++) { ids[i] = parseInt(ids[i], 10); } } else { //it's a number ids[0] = s; } //post to a route that will make the draft emails then tag the purchase as notified app.api.create('subscription/sendnotify', ids, function (res) { if (res.error) { $.gevent.publish('app-show-error',res.msg); } else { page('#!/subnotify'); } }); return false; //prevent default }; //-------------------- END EVENT HANDLERS -------------------- //------------------- BEGIN PUBLIC METHODS ------------------- //CONFIGMODULE // configModule = function (context) { stateMap.context = context.context; }; //INITMODULE // initModule = function ($container) { if (typeof $container === 'undefined') { $container = $('#app-shell-main-content'); } $container.html(Handlebars.templates['app.subnotify']({})); //fetch data app.api.get('subscription/notifylist', function (res) { if (res.error) { $.gevent.publish('app-show-error',res.msg); } else { //get the list ul var $appList = $('#rf-list'); $appList.empty(); var displayedItems = 0; $.each(res, function (i, obj) { $appList.append("