1
|
package eu.dnetlib.repo.manager.client.datasources.update;
|
2
|
|
3
|
import com.google.gwt.core.client.GWT;
|
4
|
import com.google.gwt.dom.client.Document;
|
5
|
import com.google.gwt.event.dom.client.ClickEvent;
|
6
|
import com.google.gwt.event.dom.client.ClickHandler;
|
7
|
import com.google.gwt.query.client.Function;
|
8
|
import com.google.gwt.user.client.Event;
|
9
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
10
|
import com.google.gwt.user.client.ui.FlowPanel;
|
11
|
import com.google.gwt.user.client.ui.HTML;
|
12
|
import eu.dnetlib.domain.data.Repository;
|
13
|
import eu.dnetlib.gwt.client.help.HelpService;
|
14
|
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
|
15
|
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
|
16
|
import eu.dnetlib.repo.manager.client.HelpCallback;
|
17
|
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
|
18
|
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
19
|
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
|
20
|
import eu.dnetlib.repo.manager.client.widgets.TextBox;
|
21
|
import eu.dnetlib.repo.manager.shared.DatasourceVocabularies;
|
22
|
import org.gwtbootstrap3.client.ui.*;
|
23
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
24
|
import org.gwtbootstrap3.client.ui.constants.ModalBackdrop;
|
25
|
|
26
|
import static com.google.gwt.query.client.GQuery.$;
|
27
|
|
28
|
/**
|
29
|
* Created by stefania on 1/14/16.
|
30
|
*/
|
31
|
public class UpdateRepositoryWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
|
32
|
|
33
|
private String parentToken = "";
|
34
|
private String restToken = "";
|
35
|
|
36
|
private static HTML title = new HTML();
|
37
|
private FlowPanel updateRepositoryBoxContent = new FlowPanel();
|
38
|
|
39
|
private Alert errorAlert = new Alert();
|
40
|
private Alert successAlert = new Alert();
|
41
|
|
42
|
private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
|
43
|
private static HelpServiceAsync helpService = GWT.create(HelpService.class);
|
44
|
|
45
|
public UpdateRepositoryWidget() {
|
46
|
|
47
|
title.addStyleName("uk-margin-medium-bottom");
|
48
|
contentPanel.add(title);
|
49
|
|
50
|
errorAlert.setType(AlertType.DANGER);
|
51
|
errorAlert.setDismissable(false);
|
52
|
errorAlert.setVisible(false);
|
53
|
updateRepositoryBoxContent.add(errorAlert);
|
54
|
|
55
|
successAlert.setType(AlertType.SUCCESS);
|
56
|
successAlert.setDismissable(false);
|
57
|
successAlert.setVisible(false);
|
58
|
updateRepositoryBoxContent.add(successAlert);
|
59
|
|
60
|
contentPanel.add(updateRepositoryBoxContent);
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public void clear() {
|
65
|
updateRepositoryBoxContent.clear();
|
66
|
errorAlert.setVisible(false);
|
67
|
successAlert.setVisible(false);
|
68
|
gridPanel.remove(helpPanel);
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public void reload() {
|
73
|
|
74
|
Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
|
75
|
updateRepositoryBoxContent.add(errorAlert);
|
76
|
updateRepositoryBoxContent.add(successAlert);
|
77
|
|
78
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
|
79
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving repository...</div>" +
|
80
|
"<div class=\"whiteFilm\"></div>");
|
81
|
updateRepositoryBoxContent.addStyleName("loading-big");
|
82
|
updateRepositoryBoxContent.add(loadingWheel);
|
83
|
|
84
|
helpService.getHelpById(parentToken + "_updateRepo", new HelpCallback(helpPanel, gridPanel));
|
85
|
|
86
|
repositoryService.getRepository(restToken, new AsyncCallback<Repository>() {
|
87
|
|
88
|
@Override
|
89
|
public void onFailure(Throwable caught) {
|
90
|
|
91
|
updateRepositoryBoxContent.removeStyleName("loading-big");
|
92
|
updateRepositoryBoxContent.remove(loadingWheel);
|
93
|
|
94
|
errorAlert.setText("System error retrieving repository");
|
95
|
errorAlert.setVisible(true);
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public void onSuccess(final Repository repository) {
|
100
|
|
101
|
String logoURLSource = "";
|
102
|
if(repository.getLogoUrl()==null || repository.getLogoUrl().isEmpty())
|
103
|
logoURLSource = "img/yourLogoHere.jpg";
|
104
|
else
|
105
|
logoURLSource = repository.getLogoUrl();
|
106
|
|
107
|
title.setHTML("<h1 class=\"uk-article-title\">" +
|
108
|
"<a id=\"updateLogoURL\" href=\"javascript:;\">" +
|
109
|
"<img src=\"" + logoURLSource + "\" alt=\"[Repo Logo]\" width=\"60px\" style=\"margin-right: 15px; margin-top:-8px\"></a>" +
|
110
|
repository.getOfficialName() + "</h1>");
|
111
|
|
112
|
// RepositoryManager.pageHeader.clear();
|
113
|
//
|
114
|
// String logoURLSource = "";
|
115
|
// if(repository.getLogoUrl()==null || repository.getLogoUrl().isEmpty())
|
116
|
// logoURLSource = "img/yourLogoHere.jpg";
|
117
|
// else
|
118
|
// logoURLSource = repository.getLogoUrl();
|
119
|
//
|
120
|
// RepositoryManager.pageHeader.add(new HTML("<div class=\"col-sm-9\"><h2><img src=\"" + logoURLSource + "\" alt=[Repo Logo]" +
|
121
|
// "width=\"35px\" height=\"35px\" style=\"margin-right: 15px; margin-top:-2px\">" + repository.getOfficialName() + "</h2>" +
|
122
|
// "<ol class=\"breadcrumb\"><li><a href=\"#dashboard\">Home</a></li><li><a href=\"#" + parentToken +
|
123
|
// "\">Manage Datasources</a></li><li class=\"active\"><strong>" + repository.getOfficialName() +
|
124
|
// "</strong></li></ol></div><div class=\"col-sm-3\"><div class=\"nav navbar-top-links navbar-right\">" +
|
125
|
// "<button id=\"addLogoURL\" style=\"margin-top: 30px; margin-right: 20px\" type=\"button\" " +
|
126
|
// "class=\"btn btn-w-m btn-white\">Update Logo URL</button></div></div>"));
|
127
|
|
128
|
repositoryService.getDatasourceVocabularies(repository.getDatasourceType(),
|
129
|
new AsyncCallback<DatasourceVocabularies>() {
|
130
|
|
131
|
@Override
|
132
|
public void onFailure(Throwable caught) {
|
133
|
|
134
|
updateRepositoryBoxContent.removeStyleName("loading-big");
|
135
|
updateRepositoryBoxContent.remove(loadingWheel);
|
136
|
|
137
|
errorAlert.setText("System error retrieving datasource vocabularies");
|
138
|
errorAlert.setVisible(true);
|
139
|
}
|
140
|
|
141
|
@Override
|
142
|
public void onSuccess(DatasourceVocabularies datasourceVocabularies) {
|
143
|
|
144
|
updateRepositoryBoxContent.removeStyleName("loading-big");
|
145
|
updateRepositoryBoxContent.remove(loadingWheel);
|
146
|
|
147
|
UpdateRepositoryForm updateRepositoryForm =
|
148
|
new UpdateRepositoryForm(repository.getDatasourceType(), datasourceVocabularies, repository);
|
149
|
updateRepositoryBoxContent.add(updateRepositoryForm.asWidget());
|
150
|
|
151
|
addHandlers(repository);
|
152
|
}
|
153
|
});
|
154
|
}
|
155
|
});
|
156
|
}
|
157
|
|
158
|
@Override
|
159
|
public void setToken(String parentToken, String rest) {
|
160
|
this.parentToken = parentToken;
|
161
|
this.restToken = rest;
|
162
|
}
|
163
|
|
164
|
@Override
|
165
|
public void afterAdditionToRootPanel() {
|
166
|
|
167
|
}
|
168
|
|
169
|
private void addHandlers(final Repository repository) {
|
170
|
|
171
|
$("#updateLogoURL").click(new Function() {
|
172
|
|
173
|
public boolean f(Event e) {
|
174
|
|
175
|
errorAlert.setVisible(false);
|
176
|
successAlert.setVisible(false);
|
177
|
|
178
|
openModalToEnterLogoURL(repository);
|
179
|
|
180
|
return true;
|
181
|
}
|
182
|
});
|
183
|
}
|
184
|
|
185
|
private void openModalToEnterLogoURL(final Repository repository) {
|
186
|
|
187
|
final Modal updateLogoURLModal = new Modal();
|
188
|
updateLogoURLModal.setDataBackdrop(ModalBackdrop.STATIC);
|
189
|
|
190
|
FlowPanel modalContent = new FlowPanel();
|
191
|
|
192
|
HTML title = new HTML("<h2 class=\"uk-modal-title\">Update Logo URL</h2>\n");
|
193
|
modalContent.add(title);
|
194
|
|
195
|
Form logoURLForm = new Form();
|
196
|
|
197
|
final TextBox logoURLTextBox = new TextBox();
|
198
|
if(repository.getLogoUrl()==null || repository.getLogoUrl().isEmpty())
|
199
|
logoURLTextBox.setPlaceholder("Logo URL");
|
200
|
else
|
201
|
logoURLTextBox.setValue(repository.getLogoUrl());
|
202
|
|
203
|
logoURLForm.addStyleName("uk-margin uk-grid");
|
204
|
|
205
|
FlowPanel logoURLTextBoxWrapper = new FlowPanel();
|
206
|
logoURLTextBoxWrapper.addStyleName("uk-width-1-1");
|
207
|
logoURLTextBoxWrapper.add(logoURLTextBox);
|
208
|
logoURLForm.add(logoURLTextBoxWrapper);
|
209
|
|
210
|
modalContent.add(logoURLForm);
|
211
|
|
212
|
FlowPanel actionButtons = new FlowPanel();
|
213
|
actionButtons.addStyleName("uk-text-right uk-margin-bottom");
|
214
|
modalContent.add(actionButtons);
|
215
|
|
216
|
Button no = new Button("Cancel");
|
217
|
no.addStyleName("uk-button uk-button-default");
|
218
|
no.addClickHandler(new ClickHandler() {
|
219
|
@Override
|
220
|
public void onClick(ClickEvent event) {
|
221
|
updateLogoURLModal.hide();
|
222
|
updateLogoURLModal.removeFromParent();
|
223
|
}
|
224
|
});
|
225
|
actionButtons.add(no);
|
226
|
|
227
|
Button yes = new Button("Update");
|
228
|
yes.addStyleName("uk-button uk-button-primary");
|
229
|
yes.addClickHandler(new ClickHandler() {
|
230
|
@Override
|
231
|
public void onClick(ClickEvent event) {
|
232
|
|
233
|
repository.setLogoUrl(logoURLTextBox.getValue().trim());
|
234
|
repositoryService.updateRepositoryInformation(repository, new AsyncCallback<Void>() {
|
235
|
|
236
|
@Override
|
237
|
public void onFailure(Throwable throwable) {
|
238
|
|
239
|
errorAlert.setText("System error updating logo URL");
|
240
|
errorAlert.setVisible(true);
|
241
|
|
242
|
updateLogoURLModal.hide();
|
243
|
updateLogoURLModal.removeFromParent();
|
244
|
}
|
245
|
|
246
|
@Override
|
247
|
public void onSuccess(Void aVoid) {
|
248
|
|
249
|
successAlert.setVisible(true);
|
250
|
successAlert.setText("Logo updated successfully");
|
251
|
|
252
|
String logoURLSource = "";
|
253
|
if(repository.getLogoUrl()==null || repository.getLogoUrl().isEmpty())
|
254
|
logoURLSource = "img/yourLogoHere.jpg";
|
255
|
else
|
256
|
logoURLSource = repository.getLogoUrl();
|
257
|
|
258
|
UpdateRepositoryWidget.title.setHTML("<h1 class=\"uk-article-title\">" +
|
259
|
"<a id=\"updateLogoURL\" href=\"javascript:;\">" +
|
260
|
"<img src=\"" + logoURLSource + "\" alt=\"[Repo Logo]\" width=\"60px\" style=\"margin-right: 15px; margin-top:-8px\"></a>" +
|
261
|
repository.getOfficialName() + "</h1>");
|
262
|
|
263
|
addHandlers(repository);
|
264
|
|
265
|
updateLogoURLModal.hide();
|
266
|
updateLogoURLModal.removeFromParent();
|
267
|
}
|
268
|
});
|
269
|
}
|
270
|
});
|
271
|
actionButtons.add(yes);
|
272
|
|
273
|
ModalBody modalBody = new ModalBody();
|
274
|
modalBody.add(modalContent);
|
275
|
updateLogoURLModal.add(modalBody);
|
276
|
updateLogoURLModal.getElement().getChild(0).getChild(0).getChild(0).removeFromParent();
|
277
|
|
278
|
updateLogoURLModal.show();
|
279
|
}
|
280
|
}
|