aboutsummaryrefslogtreecommitdiffstats
path: root/etherpad/src/etherpad/control/store/storecontrol.js
blob: 43569e431c160277b54fa54345760360fae78626 (plain) (blame)
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
 * Copyright 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import("dispatch.{Dispatcher,DirMatcher,forward}");
import("fastJSON");
import("funhtml.*");

import('etherpad.globals.*');
import("etherpad.store.eepnet_trial");
import("etherpad.store.eepnet_checkout");
import("etherpad.sessions.getSession");
import("etherpad.utils.*");

import("etherpad.control.store.eepnet_checkout_control");
import("etherpad.control.pro.admin.team_billing_control");

jimport("java.lang.System.out.println");

//----------------------------------------------------------------

function onStartup() {}

function onRequest() {
  var disp = new Dispatcher();
  disp.addLocations([
    [DirMatcher('/ep/store/eepnet-checkout/'), forward(eepnet_checkout_control)],
  ]);
  return disp.dispatch();
}

//----------------------------------------------------------------

function render_main() {
  response.redirect("/ep/about/pricing");
}

//----------------------------------------------------------------
// Flow goes through these 4 pages in order:
//----------------------------------------------------------------

function render_eepnet_eval_signup_get() {
  renderFramed("store/eepnet_eval_signup.ejs", {
    trialDays: eepnet_trial.getTrialDays(),
    oldData: (getSession().pricingContactData || {}),
    sfIndustryList: eepnet_trial.getSalesforceIndustryList()
  });
  delete getSession().errorMsg;
}

// function render_eepnet_eval_signup_post() {
//   response.setContentType("text/plain; charset=utf-8");
//   var data = {};
//   var fields = ['firstName', 'lastName', 'email', 'orgName',
//     'jobTitle', 'phone', 'estUsers', 'industry'];
// 
//   if (!getSession().pricingContactData) {
//     getSession().pricingContactData = {};
//   }
// 
//   function _redirectErr(msg) {
//     response.write(fastJSON.stringify({error: msg}));
//     response.stop();
//   }
// 
//   fields.forEach(function(f) { 
//     getSession().pricingContactData[f] = request.params[f];
//   });
// 
//   fields.forEach(function(f) {
//     data[f] = request.params[f];
//     if (!(data[f] && (data[f].length > 0))) {
//        _redirectErr("All fields are required.");
//     }
//   });
// 
//   // validate email
//   if (!isValidEmail(data.email)) {
//     _redirectErr("That email address doesn't look valid.");
//   }
// 
//   // check that email not already registered.
//   if (eepnet_trial.hasEmailAlreadyDownloaded(data.email)) {
//     _redirectErr("That email has already downloaded a free trial."+
//     ' <a href="/ep/store/eepnet-recover-license">Recover a lost license key here</a>.');
//   }
// 
//   // Looks good!  Create and email license key...
//   eepnet_trial.createAndMailNewLicense(data);
//   getSession().message = "A license key has been sent to "+data.email;
//   
//   // Generate web2lead info and return it
//   var web2leadData = eepnet_trial.getWeb2LeadData(data, request.clientAddr, getSession().initialReferer);
//   response.write(fastJSON.stringify(web2leadData));
// }
// 
// function render_salesforce_web2lead_ok() {
//   renderFramedHtml([
//     '<script>',
//     'top.location.href = "'+request.scheme+'://'+request.host+'/ep/store/eepnet-download";',
//     '</script>'
//   ].join('\n'));
// }
// 
// function render_eepnet_eval_download() {
//   // NOTE: keep this URL around for historical reasons?
//   response.redirect("/ep/store/eepnet-download");
// }
// 
// function render_eepnet_download() {
//   renderFramed("store/eepnet_download.ejs", {
//     message: (getSession().message || null),
//     versionString: (PNE_RELEASE_VERSION+"&nbsp;("+PNE_RELEASE_DATE +")")
//   });
//   delete getSession().message;
// }
// 
// function render_eepnet_download_zip() {
//   response.redirect("/static/zip/pne-release/etherpad-pne-"+PNE_RELEASE_VERSION+".zip");
// }
// 
// function render_eepnet_download_nextsteps() {
//   renderFramed("store/eepnet_eval_nextsteps.ejs");
// }

//----------------------------------------------------------------
// recover a lost license
//----------------------------------------------------------------
function render_eepnet_recover_license_get() {
  var d = DIV({className: "fpcontent"});

  d.push(P("Recover your lost license key."));

  if (getSession().message) {
    d.push(DIV({id: "resultmsg",
		style: "border: 1px solid #333; padding: 0 1em; background: #efe; margin: 1em 0;"}, getSession().message));
    delete getSession().message;
  }
  if (getSession().error) {
    d.push(DIV({id: "errormsg",
		style: "border: 1px solid red; padding: 0 1em; background: #fee; margin: 1em 0;"}, getSession().error));
    delete getSession().error;
  }

  d.push(FORM({style: "border: 1px solid #222; padding: 2em; background: #eee;",
	       action: request.path, method: "post"},
	      LABEL({htmlFor: "email"},
		    "Your email address:"),
	      INPUT({type: "text", name: "email", id: "email"}),
	      INPUT({type: "submit", id: "submit", value: "Submit"})));

  renderFramedHtml(d);
}

function render_eepnet_recover_license_post() {
  var email = request.params.email;
  if (!eepnet_trial.hasEmailAlreadyDownloaded(email) && !eepnet_trialhasEmailAlreadyPurchased(email)) {
    getSession().error = P("License not found for email: \"", email, "\".");
    response.redirect(request.path);
  }
  if (eepnet_checkout.hasEmailAlreadyPurchased(email)) {
    eepnet_checkout.mailLostLicense(email);
  } else if (eepnet_trial.hasEmailAlreadyDownloaded(email)) {
    eepnet_trial.mailLostLicense(email);
  }
  getSession().message = P("Your license information has been sent to ", email, ".");
  response.redirect(request.path);
}

//----------------------------------------------------------------
function render_eepnet_purchase_get() {
  renderFramed("store/eepnet_purchase.ejs", {});
}

//--------------------------------------------------------------------------------
// csc-help page
//--------------------------------------------------------------------------------

function render_csc_help_get() {
  response.write(renderTemplateAsString("store/csc-help.ejs"));
}

//--------------------------------------------------------------------------------
// paypal notifications for pro
//--------------------------------------------------------------------------------

function render_paypalnotify() {
  team_billing_control.handlePaypalNotify();
}