-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailController.js
More file actions
103 lines (92 loc) · 3.31 KB
/
Copy pathemailController.js
File metadata and controls
103 lines (92 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var emailGenApp = angular.module('emailGenApp', ['ui.sortable', 'ngMaterial']);
emailGenApp.controller('EmailGenCtrl', function($scope, $timeout, $mdSidenav, $log) {
$scope.events = [];
$scope.console = console;
$scope.date = new Date();
var reader = new FileReader;
reader.onload = function(e) {
var cleanCSV = reader.result.replace(/\cM/g, "\n"); // Remove pesky ^M chracters
$scope.events = $.grep($.csv.toObjects(cleanCSV), function(e) {
return e['Event Title'] != null;
});
$scope.events = $.map($scope.events, function(e) {
if (e["Event Blurb"].length > 147) {
e["Event Blurb"] = e["Event Blurb"].substring(0, 147) + "...";
}
return e;
});
$scope.$apply()
}
$("#csv-input").on('change', function() {
reader.readAsText($("#csv-input")[0].files[0]);
$scope.selFile = $("#csv-input")[0].files[0].name;
console.log($scope.selFile);
});
$scope.saveHTML = function() {
var blob = new Blob([$("#generated-email").html()], { type: "text/html;charset=utf-8" });
saveAs(blob, "email.html");
}
$scope.deleteEvent = function(event) {
console.log(event)
var removeIndex = $scope.events.indexOf(event);
$scope.events.splice(removeIndex, 1);
}
$scope.newEvent = function() {
if (!$scope.events) $scope.events = [];
var eventModel = { "Timestamp": "/7/16 21:32", "Event Title": "Untitled Event", "DUU Committee(s) Involved with Event": "LDOC", "Event Blurb": "", "Hyperlinks to Include (if multiple, separate by commas)": "" };
$scope.events.unshift(eventModel);
}
/**
* Supplies a function that will continue to operate until the
* time is up.
*/
function debounce(func, wait, context) {
var timer;
return function debounced() {
var context = $scope,
args = Array.prototype.slice.call(arguments);
$timeout.cancel(timer);
timer = $timeout(function() {
timer = undefined;
func.apply(context, args);
}, wait || 10);
};
}
/**
* Build handler to open/close a SideNav; when animation finishes
* report completion in console
*/
function buildDelayedToggler(navID) {
return debounce(function() {
$mdSidenav(navID)
.toggle()
.then(function() {
$log.debug("toggle " + navID + " is done");
});
}, 200);
}
function buildToggler(navID) {
return function() {
$mdSidenav(navID)
.toggle()
.then(function() {
$log.debug("toggle " + navID + " is done");
});
}
}
$scope.close = function() {
$mdSidenav('left').close()
.then(function() {
$log.debug("close LEFT is done");
});
};
$scope.toggleLeft = buildDelayedToggler('left');
});
emailGenApp.controller('LeftCtrl', function($scope, $timeout, $mdSidenav, $log) {
$scope.close = function() {
$mdSidenav('left').close()
.then(function() {
$log.debug("close LEFT is done");
});
};
})