-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
.../src/main/java/com/logicaldoc/gui/frontend/client/metadata/form/WebFormPrefilledLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.logicaldoc.gui.frontend.client.metadata.form; | ||
|
||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
import com.logicaldoc.gui.common.client.beans.GUIForm; | ||
import com.logicaldoc.gui.common.client.i18n.I18N; | ||
import com.logicaldoc.gui.common.client.log.GuiLog; | ||
import com.logicaldoc.gui.common.client.util.ItemFactory; | ||
import com.logicaldoc.gui.common.client.widgets.ExtendedPropertiesPanel; | ||
import com.logicaldoc.gui.common.client.widgets.StickyWindow; | ||
import com.logicaldoc.gui.frontend.client.services.FormService; | ||
import com.smartgwt.client.types.TitleOrientation; | ||
import com.smartgwt.client.widgets.form.DynamicForm; | ||
import com.smartgwt.client.widgets.form.ValuesManager; | ||
import com.smartgwt.client.widgets.form.fields.StaticTextItem; | ||
import com.smartgwt.client.widgets.form.fields.SubmitItem; | ||
import com.smartgwt.client.widgets.form.fields.TextItem; | ||
|
||
/** | ||
* Helps to create pre-filled web form link | ||
* | ||
* @author Marco Meschieri - LogicalDOC | ||
* @since 8.8.5 | ||
*/ | ||
public class WebFormPrefilledLink extends StickyWindow { | ||
|
||
private ValuesManager vm; | ||
|
||
private ExtendedPropertiesPanel extPanel; | ||
|
||
private StaticTextItem prefilledLink; | ||
|
||
public WebFormPrefilledLink(long formId) { | ||
super("prefilledlink"); | ||
|
||
centerInPage(); | ||
setWidth(500); | ||
setAutoHeight(); | ||
|
||
initGUI(formId); | ||
} | ||
|
||
private void initGUI(long formId) { | ||
DynamicForm responderForm = new DynamicForm(); | ||
vm = new ValuesManager(); | ||
responderForm.setValuesManager(vm); | ||
responderForm.setTitleOrientation(TitleOrientation.TOP); | ||
responderForm.setNumCols(1); | ||
|
||
TextItem responder = ItemFactory.newEmailItem("responderemail", "responderemail", false); | ||
responder.setWidth(200); | ||
|
||
responderForm.setItems(responder); | ||
|
||
addItem(responderForm); | ||
|
||
FormService.Instance.get().getById(formId, new AsyncCallback<GUIForm>() { | ||
|
||
@Override | ||
public void onFailure(Throwable caught) { | ||
GuiLog.serverError(caught); | ||
} | ||
|
||
@Override | ||
public void onSuccess(GUIForm frm) { | ||
extPanel = new ExtendedPropertiesPanel(frm, null, true, false, false); | ||
addItem(extPanel); | ||
|
||
prefilledLink = ItemFactory.newStaticTextItem("prefilledlink", null); | ||
prefilledLink.setWidth(200); | ||
|
||
SubmitItem getLink = new SubmitItem(); | ||
getLink.setTitle(I18N.message("getlink")); | ||
getLink.addClickHandler(event -> onGetLink()); | ||
|
||
DynamicForm linkForm = new DynamicForm(); | ||
linkForm.setTitleOrientation(TitleOrientation.TOP); | ||
linkForm.setNumCols(1); | ||
linkForm.setWidth100(); | ||
linkForm.setItems(getLink, prefilledLink); | ||
|
||
addItem(linkForm); | ||
} | ||
}); | ||
|
||
} | ||
|
||
public void onGetLink() { | ||
if (!vm.validate()) | ||
return; | ||
|
||
if (!extPanel.validate()) | ||
return; | ||
|
||
FormService.Instance.get().getPreFilledLink((GUIForm) extPanel.getObject(), | ||
vm.getValueAsString("responderemail"), new AsyncCallback<String>() { | ||
|
||
@Override | ||
public void onFailure(Throwable caught) { | ||
GuiLog.serverError(caught); | ||
} | ||
|
||
@Override | ||
public void onSuccess(String link) { | ||
prefilledLink.setValue("<a href='" + link + "' target=='_blank'>" + link + "</a>"); | ||
} | ||
}); | ||
} | ||
} |