Skip to content

Commit 84a4e86

Browse files
author
svuillet
committed
feature #14045
1 parent 816cab2 commit 84a4e86

File tree

16 files changed

+465
-15
lines changed

16 files changed

+465
-15
lines changed

mobile-war/src/main/java/org/silverpeas/mobile/client/apps/faq/FaqApp.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
import com.google.gwt.core.client.GWT;
2828
import org.fusesource.restygwt.client.Method;
2929
import org.silverpeas.mobile.client.SpMobil;
30-
import org.silverpeas.mobile.client.apps.faq.events.app.AbstractFaqAppEvent;
31-
import org.silverpeas.mobile.client.apps.faq.events.app.FaqAppEventHandler;
32-
import org.silverpeas.mobile.client.apps.faq.events.app.FaqAttachmentsLoadEvent;
33-
import org.silverpeas.mobile.client.apps.faq.events.app.FaqCategoriesLoadEvent;
30+
import org.silverpeas.mobile.client.apps.faq.events.app.*;
3431
import org.silverpeas.mobile.client.apps.faq.events.pages.FaqAttachmentsLoadedEvent;
3532
import org.silverpeas.mobile.client.apps.faq.events.pages.FaqCategoriesLoadedEvent;
3633
import org.silverpeas.mobile.client.apps.faq.pages.FaqPage;
@@ -43,10 +40,12 @@
4340
import org.silverpeas.mobile.client.common.ServicesLocator;
4441
import org.silverpeas.mobile.client.common.app.App;
4542
import org.silverpeas.mobile.client.common.network.MethodCallbackOnlineOnly;
43+
import org.silverpeas.mobile.client.components.Snackbar;
4644
import org.silverpeas.mobile.shared.dto.documents.DocumentType;
4745
import org.silverpeas.mobile.shared.dto.documents.SimpleDocumentDTO;
4846
import org.silverpeas.mobile.shared.dto.faq.CategoryDTO;
4947
import org.silverpeas.mobile.shared.dto.faq.QuestionDTO;
48+
import org.silverpeas.mobile.shared.dto.faq.QuestionDetailDTO;
5049
import org.silverpeas.mobile.shared.dto.navigation.Apps;
5150

5251
import java.util.List;
@@ -92,6 +91,7 @@ public void onSuccess(final Method method, final List<QuestionDTO> questions) {
9291
page.setApp(FaqApp.this);
9392
page.setData(questions);
9493
page.show();
94+
setMainPage(page);
9595
}
9696
};
9797
action.attempt();
@@ -144,4 +144,42 @@ public void onSuccess(final Method method, final List<SimpleDocumentDTO> attachm
144144

145145
action.attempt();
146146
}
147+
148+
@Override
149+
public void onCreateQuestion(QuestionCreateEvent event) {
150+
MethodCallbackOnlineOnly action = new MethodCallbackOnlineOnly<QuestionDetailDTO>() {
151+
@Override
152+
public void attempt() {
153+
super.attempt();
154+
ServicesLocator.getServiceFaq().createQuestion(getApplicationInstance().getId(), event.getQuestion(), this);
155+
}
156+
157+
@Override
158+
public void onSuccess(Method method, QuestionDetailDTO questionDetailDTO) {
159+
super.onSuccess(method, questionDetailDTO);
160+
Snackbar.show(msg.createConfirmation(), Snackbar.DELAY, Snackbar.INFO);
161+
reloadFaq();
162+
}
163+
};
164+
action.attempt();
165+
}
166+
167+
168+
private void reloadFaq() {
169+
MethodCallbackOnlineOnly action = new MethodCallbackOnlineOnly<List<QuestionDTO>>() {
170+
@Override
171+
public void attempt() {
172+
super.attempt();
173+
ServicesLocator.getServiceFaq().getAllQuestions(getApplicationInstance().getId(), this);
174+
}
175+
176+
@Override
177+
public void onSuccess(final Method method, final List<QuestionDTO> questions) {
178+
super.onSuccess(method, questions);
179+
FaqPage page = (FaqPage) getMainPage();
180+
page.setData(questions);
181+
}
182+
};
183+
action.attempt();
184+
}
147185
}

mobile-war/src/main/java/org/silverpeas/mobile/client/apps/faq/events/app/FaqAppEventHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ public interface FaqAppEventHandler extends EventHandler{
3131
void loadCategories(FaqCategoriesLoadEvent faqCategoriesLoadEvent);
3232

3333
void loadAttachments(FaqAttachmentsLoadEvent faqAttachmentsLoadEvent);
34+
35+
void onCreateQuestion(QuestionCreateEvent questionCreateEvent);
3436
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2000 - 2024 Silverpeas
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* As a special exception to the terms and conditions of version 3.0 of
10+
* the GPL, you may redistribute this Program in connection with Free/Libre
11+
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12+
* FLOSS exception. You should have received a copy of the text describing
13+
* the FLOSS exception, and it is also available here:
14+
* "https://www.silverpeas.org/legal/floss_exception.html"
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
package org.silverpeas.mobile.client.apps.faq.events.app;
26+
27+
import org.silverpeas.mobile.client.apps.faq.events.pages.AbstractFaqPagesEvent;
28+
import org.silverpeas.mobile.client.apps.faq.events.pages.FaqPagesEventHandler;
29+
import org.silverpeas.mobile.shared.dto.faq.QuestionDetailDTO;
30+
31+
public class QuestionCreateEvent extends AbstractFaqAppEvent {
32+
33+
private QuestionDetailDTO question;
34+
35+
public QuestionCreateEvent(){
36+
super();
37+
}
38+
39+
public QuestionCreateEvent(final QuestionDetailDTO question) {
40+
this.question = question;
41+
}
42+
43+
@Override
44+
protected void dispatch(FaqAppEventHandler handler) {
45+
handler.onCreateQuestion(this);
46+
}
47+
48+
public QuestionDetailDTO getQuestion() {
49+
return question;
50+
}
51+
}

mobile-war/src/main/java/org/silverpeas/mobile/client/apps/faq/events/pages/FaqPagesEventHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
package org.silverpeas.mobile.client.apps.faq.events.pages;
2626

2727
import com.google.gwt.event.shared.EventHandler;
28+
import org.silverpeas.mobile.client.apps.faq.events.app.QuestionCreateEvent;
2829

2930
public interface FaqPagesEventHandler extends EventHandler{
3031

3132
void onCategoriesLoaded(FaqCategoriesLoadedEvent faqCategoriesLoadedEvent);
3233

3334
void onAttachmentsLoaded(FaqAttachmentsLoadedEvent faqAttachmentsLoadedEvent);
35+
3436
}

mobile-war/src/main/java/org/silverpeas/mobile/client/apps/faq/pages/FaqPage.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.gwt.uibinder.client.UiBinder;
3030
import com.google.gwt.uibinder.client.UiField;
3131
import com.google.gwt.uibinder.client.UiHandler;
32+
import com.google.gwt.user.client.Command;
3233
import com.google.gwt.user.client.Window;
3334
import com.google.gwt.user.client.ui.HTMLPanel;
3435
import com.google.gwt.user.client.ui.ListBox;
@@ -41,10 +42,12 @@
4142
import org.silverpeas.mobile.client.apps.faq.pages.widgets.FaqItem;
4243
import org.silverpeas.mobile.client.apps.faq.resources.FaqMessages;
4344
import org.silverpeas.mobile.client.apps.favorites.pages.widgets.AddToFavoritesButton;
45+
import org.silverpeas.mobile.client.apps.news.pages.NewsEditPage;
4446
import org.silverpeas.mobile.client.common.EventBus;
4547
import org.silverpeas.mobile.client.common.app.App;
4648
import org.silverpeas.mobile.client.components.UnorderedList;
4749
import org.silverpeas.mobile.client.components.base.PageContent;
50+
import org.silverpeas.mobile.client.components.base.widgets.AddButton;
4851
import org.silverpeas.mobile.shared.dto.ContentsTypes;
4952
import org.silverpeas.mobile.shared.dto.faq.CategoryDTO;
5053
import org.silverpeas.mobile.shared.dto.faq.QuestionDTO;
@@ -70,7 +73,7 @@ public class FaqPage extends PageContent implements FaqPagesEventHandler {
7073
private List<CategoryDTO> cats;
7174

7275
private AddToFavoritesButton favorite = new AddToFavoritesButton();
73-
76+
private AddButton ask = new AddButton();
7477

7578
interface FaqPageUiBinder extends UiBinder<Widget, FaqPage> {
7679
}
@@ -80,7 +83,15 @@ public FaqPage() {
8083
setPageTitle(msg.title());
8184
initWidget(uiBinder.createAndBindUi(this));
8285
EventBus.getInstance().addHandler(AbstractFaqPagesEvent.TYPE, this);
83-
86+
ask.setId("ask");
87+
ask.setCallback(new Command() {
88+
@Override
89+
public void execute() {
90+
QuestionPage page = new QuestionPage();
91+
page.setApp(getApp());
92+
page.show();
93+
}
94+
});
8495
}
8596

8697
@Override
@@ -94,6 +105,9 @@ public void setApp(final App app) {
94105
super.setApp(app);
95106
addActionMenu(favorite);
96107
favorite.init(getApp().getApplicationInstance().getId(), getApp().getApplicationInstance().getId(), ContentsTypes.Component.name(), getPageTitle());
108+
if (app.getApplicationInstance().getRights().getPublisher() || app.getApplicationInstance().getRights().getManager()) {
109+
addActionShortcut(ask);
110+
}
97111
}
98112

99113
public void setData(List<QuestionDTO> data) {
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (C) 2000 - 2024 Silverpeas
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* As a special exception to the terms and conditions of version 3.0 of
10+
* the GPL, you may redistribute this Program in connection with Free/Libre
11+
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12+
* FLOSS exception. You should have received a copy of the text describing
13+
* the FLOSS exception, and it is also available here:
14+
* "https://www.silverpeas.org/legal/floss_exception.html"
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
package org.silverpeas.mobile.client.apps.faq.pages;
26+
27+
import com.google.gwt.core.client.GWT;
28+
import com.google.gwt.event.dom.client.ChangeEvent;
29+
import com.google.gwt.event.dom.client.ClickEvent;
30+
import com.google.gwt.uibinder.client.UiBinder;
31+
import com.google.gwt.uibinder.client.UiField;
32+
import com.google.gwt.uibinder.client.UiHandler;
33+
import com.google.gwt.user.client.ui.*;
34+
import org.silverpeas.mobile.client.apps.faq.events.app.FaqCategoriesLoadEvent;
35+
import org.silverpeas.mobile.client.apps.faq.events.app.QuestionCreateEvent;
36+
import org.silverpeas.mobile.client.apps.faq.events.pages.*;
37+
import org.silverpeas.mobile.client.apps.faq.resources.FaqMessages;
38+
import org.silverpeas.mobile.client.common.EventBus;
39+
import org.silverpeas.mobile.client.common.app.App;
40+
import org.silverpeas.mobile.client.components.base.PageContent;
41+
import org.silverpeas.mobile.shared.dto.faq.QuestionDetailDTO;
42+
43+
public class QuestionPage extends PageContent implements FaqPagesEventHandler {
44+
45+
private static QuestionPageUiBinder uiBinder = GWT.create(QuestionPageUiBinder.class);
46+
47+
@UiField(provided = true) protected FaqMessages msg = null;
48+
49+
@UiField
50+
HTMLPanel container;
51+
52+
@UiField
53+
ListBox categoryList;
54+
55+
@UiField
56+
TextBox question;
57+
58+
@UiField
59+
TextArea description;
60+
61+
@UiField Anchor submit;
62+
63+
interface QuestionPageUiBinder extends UiBinder<Widget, QuestionPage> {
64+
}
65+
66+
public QuestionPage() {
67+
msg = GWT.create(FaqMessages.class);
68+
setPageTitle(msg.title());
69+
initWidget(uiBinder.createAndBindUi(this));
70+
EventBus.getInstance().addHandler(AbstractFaqPagesEvent.TYPE, this);
71+
container.getElement().setId("questionForm");
72+
question.getElement().setAttribute("placeholder", msg.questionField());
73+
description.getElement().setAttribute("placeholder", msg.descriptionField());
74+
description.getElement().setAttribute("rows", "6");
75+
categoryList.addItem(msg.categoryField(), "");
76+
submit.getElement().addClassName("formIncomplete");
77+
78+
EventBus.getInstance().fireEvent(new FaqCategoriesLoadEvent());
79+
}
80+
81+
@Override
82+
public void stop() {
83+
super.stop();
84+
EventBus.getInstance().removeHandler(AbstractFaqPagesEvent.TYPE, this);
85+
}
86+
87+
@Override
88+
public void setApp(final App app) {
89+
super.setApp(app);
90+
}
91+
92+
@Override
93+
public void onCategoriesLoaded(FaqCategoriesLoadedEvent event) {
94+
event.getCategories().forEach(category -> {categoryList.addItem(category.getTitle(), category.getId());});
95+
}
96+
97+
@Override
98+
public void onAttachmentsLoaded(final FaqAttachmentsLoadedEvent faqAttachmentsLoadedEvent) {
99+
}
100+
101+
@UiHandler("question")
102+
protected void changeTitle(ChangeEvent event) {
103+
validateForm();
104+
}
105+
106+
private boolean validateForm() {
107+
boolean valid = !question.getText().isEmpty();
108+
if (valid) {
109+
submit.getElement().removeClassName("formIncomplete");
110+
} else {
111+
submit.getElement().addClassName("formIncomplete");
112+
}
113+
return valid;
114+
}
115+
116+
private QuestionDetailDTO populate() {
117+
QuestionDetailDTO dto = new QuestionDetailDTO();
118+
dto.setQuestion(question.getText());
119+
dto.setDescription(description.getText());
120+
dto.setCategoryId(categoryList.getSelectedValue());
121+
return dto;
122+
}
123+
124+
@UiHandler("submit")
125+
protected void save(ClickEvent event) {
126+
if (!submit.getElement().hasClassName("formIncomplete")) {
127+
QuestionDetailDTO dto = populate();
128+
QuestionCreateEvent createEvent = new QuestionCreateEvent(dto);
129+
EventBus.getInstance().fireEvent(createEvent);
130+
back();
131+
}
132+
}
133+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
~ Copyright (C) 2000 - 2024 Silverpeas
3+
~
4+
~ This program is free software: you can redistribute it and/or modify
5+
~ it under the terms of the GNU Affero General Public License as
6+
~ published by the Free Software Foundation, either version 3 of the
7+
~ License, or (at your option) any later version.
8+
~
9+
~ As a special exception to the terms and conditions of version 3.0 of
10+
~ the GPL, you may redistribute this Program in connection with Free/Libre
11+
~ Open Source Software ("FLOSS") applications as described in Silverpeas's
12+
~ FLOSS exception. You should have received a copy of the text describing
13+
~ the FLOSS exception, and it is also available here:
14+
~ "https://www.silverpeas.org/legal/floss_exception.html"
15+
~
16+
~ This program is distributed in the hope that it will be useful,
17+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
~ GNU Affero General Public License for more details.
20+
~
21+
~ You should have received a copy of the GNU Affero General Public License
22+
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
-->
24+
25+
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
26+
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
27+
xmlns:g="urn:import:com.google.gwt.user.client.ui"
28+
xmlns:base="urn:import:org.silverpeas.mobile.client.components.base"
29+
xmlns:components="urn:import:org.silverpeas.mobile.client.components">
30+
31+
<ui:with field='msg' type='org.silverpeas.mobile.client.apps.faq.resources.FaqMessages' />
32+
33+
<g:HTMLPanel ui:field="container" styleName="content ui-content ui-body-a">
34+
<g:ListBox ui:field="categoryList" styleName="category"/>
35+
<g:TextBox ui:field="question" styleName="question"/>
36+
<g:TextArea ui:field="description" styleName="description"/>
37+
38+
<div class=" ui-controlgroup ui-controlgroup-horizontal">
39+
<div class="ui-controlgroup-controls ">
40+
<g:Anchor ui:field="submit" styleName="btn-validate ui-link">
41+
<span ui:field="submitTitle" class="ui-btn-text"><ui:text from="{msg.create}"/></span>
42+
</g:Anchor>
43+
</div>
44+
</div>
45+
46+
</g:HTMLPanel>
47+
</ui:UiBinder>

mobile-war/src/main/java/org/silverpeas/mobile/client/apps/faq/resources/FaqMessages.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828

2929
public interface FaqMessages extends Messages {
3030
String title();
31+
String create();
32+
String questionField();
33+
String descriptionField();
34+
String categoryField();
35+
String createConfirmation();
3136
}

0 commit comments

Comments
 (0)