Sourcecode in PollMgr/actions.js:
1: function create_action() {
2: // pre-process submitted choices
3: var arr = new Array();
4: if (req.data.title_array) {
5: for (var i=0;i<req.data.title_array.length;i++) {
6: var title = req.data.title_array[i].trim();
7: if (title)
8: arr[arr.length] = new Choice(title);
9: }
10: } else if (req.data.title && req.data.title.trim()) {
11: arr[0] = new Choice(req.data.title.trim());
12: }
13:
14: if (req.data.cancel) {
15: res.redirect(this.href());
16: } else if (req.data.save) {
17: try {
18: res.message = this.evalNewPoll(req.data.question, arr, session.user);
19: res.redirect(this.href());
20: } catch (err) {
21: res.message = err.toString();
22: }
23: } else if (req.data.addchoice)
24: arr.push(new Choice(""));
25:
26: var newPoll = new Poll();
27:
28: res.push();
29: var max = Math.max(2, arr.length);
30: for (var i=0;i<max;i++) {
31: var c = arr[i] ? arr[i] : new Choice("");
32: c.renderSkin("edit", {count: (i+1).toString()});
33: }
34: res.data.choices = res.pop();
35: res.data.action = this.href(req.action);
36: res.data.title = getMessage("Poll.addPoll", {siteTitle: this._parent.title});
37: res.data.body = newPoll.renderSkinAsString("edit");
38: this._parent.renderSkin("page");
39: return;
40: }
|