This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
class.EtherpadLauncher.js
160 lines (143 loc) · 5.68 KB
/
class.EtherpadLauncher.js
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
/*
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me>
* This file is part of AjaXplorer.
*
* AjaXplorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AjaXplorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://www.ajaxplorer.info/>.
*/
Class.create("EtherpadLauncher", AbstractEditor, {
padID:null,
sessionID: null,
node: null,
initialize: function($super, oFormObject)
{
$super(oFormObject);
if(!ajaxplorer.user || ajaxplorer.user.canWrite()){
this.canWrite = true;
this.actions.get("saveButton").observe('click', function(){
this.saveFile();
return false;
}.bind(this));
}else{
this.canWrite = false;
this.actions.get("saveButton").hide();
}
this.actions.get("downloadFileButton").observe('click', function(){
if(!this.currentFile) return;
ajaxplorer.triggerDownload(ajxpBootstrap.parameters.get('ajxpServerAccess')+'&action=download&file='+this.currentFile);
return false;
}.bind(this));
},
initEmptyPadPane : function(form){
var selector = form.down('[name="pad_list"]');
var textInput = form.down('[name="new_pad_name"]');
var joinButton = form.down('#join_pad');
fitHeightToBottom(form.down("#ether_frame"), null, null, true);
var con = new Connexion();
con.setParameters(new Hash({
get_action: 'etherpad_proxy_api',
api_action: 'list_pads'
}));
con.onComplete = function(transport){
var pads = $A(transport.responseJSON.padIDs);
var frees = $A();
var files = $A();
pads.each(function(el){
var label = el.split('$').pop();
if(label.startsWith('FREEPAD__')){
frees.push(label);
}else{
files.push(label);
}
});
selector.insert(new Element('optgroup',{label:'Free boards'}));
frees.each(function(e){
selector.insert(new Element('option', {value:e}).update(e.replace('FREEPAD__', '')));
});
selector.insert(new Element('option', {value:-1}).update('Create new pad'));
if(files.size()){
selector.insert(new Element('optgroup', {label:'Files'}));
files.each(function(e){
selector.insert(new Element('option', {value:e}).update(e));
});
}
selector.observe("change", function(){
textInput[(selector.getValue() == -1)?'show':'hide']();
});
textInput[(selector.getValue() == -1)?'show':'hide']();
};
con.sendAsync();
joinButton.observe("click", function(){
var conn = new Connexion();
conn.addParameter("get_action", "etherpad_create");
if(selector.getValue() == -1){
conn.addParameter("pad_name", textInput.getValue());
conn.addParameter("pad_type", 'free');
}else{
conn.addParameter("pad_name", selector.getValue());
}
conn.onComplete = function(transport){
var data = transport.responseJSON;
$("etherpad_container").down("#ether_frame").src = data.url;
}
conn.sendAsync();
});
},
open : function($super, nodeOrNodes){
$super(nodeOrNodes);
this.node = nodeOrNodes;
var fileName = nodeOrNodes.getPath();
var conn = new Connexion();
conn.addParameter("get_action", "etherpad_create");
conn.addParameter("file", fileName);
conn.onComplete = function(transport){
var data = transport.responseJSON;
this.padID = data.padID;
this.sessionID = data.sessionID;
$("ether_box").down("#ether_box_frame").src = data.url;
fitHeightToBottom($("ether_box").down("#ether_box_frame"));
}.bind(this);
conn.sendAsync();
if(window.ajxpMobile){
this.setFullScreen();
attachMobileScroll(this.textarea, "vertical");
}
this.element.observe("editor:enterFSend", function(){
fitHeightToBottom($("ether_box").down("#ether_box_frame"));
});
this.element.observe("editor:resize", function(){
fitHeightToBottom($("ether_box").down("#ether_box_frame"));
});
this.element.observe("editor:exitFSend", function(){
fitHeightToBottom($("ether_box").down("#ether_box_frame"));
});
this.element.observeOnce("editor:close", function(){
var conn = new Connexion();
conn.addParameter("get_action", "etherpad_close");
conn.addParameter("file", this.node.getPath());
conn.addParameter("pad_id", this.padID);
conn.addParameter("session_id", this.sessionID);
conn.sendAsync();
}.bind(this));
},
saveFile : function(){
if(!this.padID || !this.node) return;
var conn = new Connexion();
conn.addParameter("get_action", "etherpad_save");
conn.addParameter("file", this.node.getPath());
conn.addParameter("pad_id", this.padID);
conn.sendAsync();
}
});