-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
184 lines (146 loc) · 6.52 KB
/
index.php
File metadata and controls
184 lines (146 loc) · 6.52 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<html ng-app="app">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="//fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>
<?php @include_once("../../analyticstracking.php") ?>
<header>
<h1><i class="fa fa-lg fa-fw fa-gift"></i> Gift Giving Tool
<span class="tagline">Quickly generate gift-giving lists fairly and squarely</span>
</h1>
</header>
<div id="main" ng-controller="InputController">
<div class="form-group editor-wrapper">
<h2 style="display: inline-block">Groups</h2>
<span class="description">( enter grouped lists of people... just like the example )</span>
<textarea class="editor" ng-change="go()" id="user_input" ng-class="{'unparseable': !parseable}" ng-model="user_input" rows="5" style="width: 100%;" placeholder="">
</textarea>
</div>
<div id="results" ng-if="finished_input.length">
<h2 style="display: inline-block">Giving List</h2>
<!-- Nav tabs -->
( Style:
<a href="#r-text" onclick="return false;" aria-controls="text" role="tab" data-toggle="tab">Text</a> | <a href="#r-table" onclick="return false;" aria-controls="table" role="tab" data-toggle="tab">Table</a> | <a href="#r-seqdia" onclick="return false;"
aria-controls="seqdia" role="tab" data-toggle="tab">Seqdia</a> )
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="r-text">
<div ng-repeat="(key,value) in result">
<b>{{key}}</b> gives to <b>{{value}}</b>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="r-table">
<table>
<tr>
<th>Giver</th>
<th>Recipient</th>
</tr>
<tr ng-repeat="(key,value) in result">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</table>
</div>
<div role="tabpanel" class="tab-pane" id="r-seqdia">
<div ng-repeat="(key,value) in result">
<b>{{key}}</b>--><b>{{value}}</b>: gives to
</div>
</div>
</div>
</div>
<footer>
<span ng-hide="!parseable">
<button class="btn btn-link" ng-click="go()" title="Randomize List"><i class="fa fa-lg fa-refresh"></i> </button>
<button class="btn btn-link" ng-click="download()" title="Download as CSV"><i class="fa fa-lg fa-download"></i> </button>
<span style="font-size: .8em">Gift Giving List Randomly Generated: {{timestamp | date:'M/d/yy h:mm:ss a'}}</span>
</span>
<span class="credit"><a href="http://m.smithworx.com"><i class="fa fa-heart fa-lg fa-fw"></i>Matt Smith</a> <a href="http://github.com/smithworx/givesto-app"><i class="fa fa-lg fa-fw fa-github-square" style="color: #64E986; margin-left: 20px; font-size: 1.8em;"></i></a></span>
</footer>
</div>
<script type="text/javascript">
var myApp = angular.module('app', []);
function sortObject(o) {
var sorted = {},
key, a = [];
for (key in o) {
if (o.hasOwnProperty(key)) {
a.push(key);
}
}
a.sort();
for (key = 0; key < a.length; key++) {
sorted[a[key]] = o[a[key]];
}
return sorted;
}
myApp.controller('InputController', function InputController($scope, $http, $location) {
$scope.finished_input = [];
$scope.submitting = false;
$scope.parseable = true;
$scope.canned_input = 'John, Paul, George, Ringo\nElmo, Oscar, Big Bird, Bert\nLarry, Curly, Moe';
//$scope.canned_input = '["John","Paul","George","Ringo"],\n["Elmo","Oscar","Big Bird","Bert"],\n["Larry","Curly","Moe"]';
$scope.user_input = $scope.canned_input;
$scope.result = {};
$scope.go = function() {
if ($scope.user_input) {
$scope.submitting = true;
$http.get('api.php', {
params: {
'input': $scope.user_input
},
cache: false
}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
if ($scope.canned_input !== $scope.user_input) {
//console.log("change path: "+btoa($scope.user_input));
$location.path(btoa($scope.user_input));
}
$scope.timestamp = new Date();
$scope.result = data;
$scope.finished_input.push(data);
$scope.submitting = false;
$scope.parseable = true;
$('#user_input').focus();
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
//console.log("ERROR");
$scope.submitting = false;
$scope.parseable = false;
});
//$scope.user_input = '';
} else {
alert('Please enter valid input to retrieve results');
$('#user_input').focus();
}
};
if ($location.path().substr(1).length) {
$scope.user_input = atob($location.path().substr(1));
}
$scope.go();
//Allows the user to download a .csv file
$scope.download = function() {
var download_data = sortObject($scope.result);
var csvContent = "data:text/csv;charset=utf-8," + "GIVER, " + "RECIPIENT" + "\n";
for (var i in download_data) {
csvContent += i + ", " + download_data[i] + "\n";
}
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "giving-list.csv");
link.click();
}
});
</script>
</body>
</html>