I'm integrating an applet on a workflow in the Alfresco. I created a new button org/alfresco/components/form/controls/workflow/activiti-transitions.ftl here
...
<button onclick="changePDF(); this.disabled=true; return false;"> Change </button>
<div id="pdfTexto" style="width:1000px;height:1000px"></div>
<div class="applet">
<script type="text/javascript">
deploy();
</script>
</div>
</#if>
And this button change (through the javascript of the applet) calls the functionality of the applet that is make changes in the file of the respective workflow. After this, I want to put "Approved" like the button accept standard does. But, I only want to make this after the changes make effect. My applet returns a "ok" when the changes are completed (the POST request is completed), after this, I want to put "Approved" and redirect to the same page that "accept" button redirects. In resume, after "ok", make what the accept button does.
My applet updates the content of an exiting document with:
http://localhost:8080/share/proxy/alfresco/api/upload ...
How can I make this? Any hints for a better solution then the below?
Evolution:
I'm trying to make this:
var form = new FormData();
form.append("prop_wf_reviewOutcome","Approve");
form.append("prop_bpm_comment","good");
form.append("prop_transitions","Next");
var requestTask = new XMLHttpRequest();
requestTask[Alfresco.util.CSRFPolicy.getHeader()] = Alfresco.util.CSRFPolicy.getToken();
requestTask.open("POST", "http://localhost:8080/share/proxy/alfresco/api/task/"+ taskidVar+ "/formprocessor" + "?" + Alfresco.util.CSRFPolicy.getParameter() + "=" + encodeURIComponent(Alfresco.util.CSRFPolicy.getToken()));
requestTask.send(form);
But lack redirect the page as the "Approve" button.
First of all, you need to define your behaviour:
package com.someco.alfresco.policy;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class DocumentUpdatePolicy implements ContentServicePolicies.OnContentUpdatePolicy {
private final Log logger = LogFactory.getLog(getClass());
private PolicyComponent policyComponent;
private NodeService nodeService;
public void init() {
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"),
ContentModel.TYPE_CONTENT,
new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.EVERY_EVENT));
}
#Override
public void onContentUpdate(NodeRef nodeRef, boolean newContent) {
logger.debug("Called on: " + nodeRef);
if (null == nodeRef || !nodeService.exists(nodeRef)) {
logger.error("Wrong nodeRef");
/* This can happen in some circumstances */
/* Do you want to just ignore it or do something ? You decide */
return;
}
/* Here goes the code to update the task */
}
public void setPolicyComponent(final PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
}
Than you need to initialise it in your custom Spring context:
<bean id="onDocumentUpdatePolicy" class="com.someco.alfresco.policy.DocumentUpdatePolicy">
<property name="policyComponent">
<ref bean="policyComponent" />
</property>
<property name="nodeService">
<ref bean="NodeService" />
</property>
</bean>
Related
I use jquery datepicker and it not display after I click ajax button.
Is there any way to show datepicker again after click? I use wicket 8.
BasePage.java
public class BasePage extends WebPage {
...
}
BasePage.html
<body>
...
<script src="/js/jquery.min.js"></script>
<script src="/js/jqueryui.min.js"></script>
<script src="/js/main.js"></script>
</body>
HomePage.java
public class HomePage extends BasePage {
public HomePage() {
SearchForm searchForm = new SearchForm();
Form<SearchForm> form = new Form<>(new CompoundPropertyModel<SearchForm>(searchForm))
AjaxButton btn = new AjaxButton() {
protected void onSubmit(AjaxRequest target) {
// Handle search data
...
target.add(form);
}
};
TextField<String> date = new TextField<>("searchDate");
form.add(date);
form.add(btn);
}
}
HomePage.html
<wicket:extend>
<form wicket:id="form">
<input wicket:id="searchDate" class="datepicker" />
<button wicket:id="btn">Search</button>
</form>
</wicket:extend>
main.js
$(function() {
$(".datepicker").datepicker();
...
});
After click ajax button all script in file main.js not working
Please help me.
when you update form via AJAX you replace each element inside it, which includes the input field you use with datepicker. But doing so you loose the javascript setting done by main.js when page was first loaded.
You can solve this in two ways. First, you could update only those elements that need to be refreshed, for example the component that you use to show search result (I suppose there must be such an element in your code).
The second solution, more heavier and complicated, is to make a custom TextField component that execute the datepicker javascript code each time is rendered.
An example of such solution can be found is in the user guide: https://wicket-guide.herokuapp.com/wicket/bookmarkable/org.wicketTutorial.ajaxdatepicker.HomePage
I would recommend to follow the first solution as it's more natural and simpler and requires less code.
UPDATE:
If you want to refresh the textfield another simple solution is to use target.appendJavaScript​ to reapply the datepicker plugin:
target.add("$('#" + date.getMarkupId() + "').datepicker();");
this should add the datepicker to the fresh new field.
I have a component which is a form, with a number of child components. What is the best way to consolidate the data from all of the child components, when submitting the form? Below is one idea, is this the correct method? I pass a reference to a function that will update a property of a form upon change in a component. What is best practice? Thanks.
import React from 'react';
import { Component , PropTypes} from 'react';
import { connect } from 'react-redux';
import { saveData } from '../actions/index'
import {bindActionCreators} from 'redux';
export default class MyClass extends Component {
constructor(props) {
super (props);
this.formData = {};
this.setFormData = this.setFormData.bind(this);
this.onSubmitHandler = this.onSubmitHandler.bind(this);
}
setFormData(key, value){
this.formData[key] = value;
}
onSubmitHandler(evt){
this.props.saveData(this.formData);
}
render (){
return (
<div>
<form onSubmit = {this.onSubmitHandler} >
<div >
<NameComponent setFormData = {this.setFormData}/>
<AddressComponent setFormData = {this.setFormData}/>
//...lots more components
</form>
</div>
);
}
}
export default connect( mapStateToProps, {saveData)(MyClass)
Yes, this approach is correct, because children are generally expected to delegate to parent that is responsible for them. In fact, that's how Redux Form works. <Field /> input components delegate their state to a Higher Order <Form /> wrapper.
The problem with your approach is that you have to do a lot of repetitive stuff on your own (such as calling onChange, delegating the value etc).
We use Redux Form for one of our projects and it's great as it integrates forms, react and redux. I find myself writing much less code and there is build in validation for both remote, local submission, submission from child components and other neat stuff.
My suggestion is to go with Redux Form instead of reinventing the wheel.
What is required to define a custom event for a UI plugin in NativeScript?
What I'm trying to achieve is to trigger a foo event that works similar to the tap event on a Button and can be hooked into as follows:
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:fooplugin="nativescript-foo-plugin">
<StackLayout>
<Button text="Tap Me!" tap="{{ onTap }}" />
<fooplugin:FooPlugin foo="{{ onFoo }}" />
</StackLayout>
</Page>
What I've done essentially boils down to calling the notify function with the eventName value of foo from within the plugin code (ignoring memory leak considerations):
import * as view from 'ui/core/view';
export class FooPlugin extends view.View {
constructor() {
super();
setTimeout(() => {
this.notify({
eventName: 'foo',
object: this,
});
// also tried this._emit('foo');
}, 1000);
}
}
Is there something else that I'm missing and that I need to do to make this work?
create a property public static fooEvent="foo"
the name of the property is important it should be eventname+ Event now it should work.
create a property of your Event public static fooEvent="foo". The name is important! It has to be eventname + "Event"
overload the on-function in your declaration file index.d.ts or FooPlugin.d.ts
// Needed when on method is overriden.
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
What is the method for redirecting the user to a completely external URL in Angular 2. For example, if I need to redirect the user to an OAuth2 server in order to authenticate, how would I do that?
Location.go(), Router.navigate(), and Router.navigateByUrl() are fine for sending the user to another section (route) within the Angular 2 app, but I can't see how they could be used to redirect to an external site?
You can use this-> window.location.href = '...';
This would change the page to whatever you want..
An Angular approach to the methods previously described is to import DOCUMENT from #angular/common (or #angular/platform-browser in Angular
< 4) and use
document.location.href = 'https://stackoverflow.com';
inside a function.
some-page.component.ts
import { DOCUMENT } from '#angular/common';
...
constructor(#Inject(DOCUMENT) private document: Document) { }
goToUrl(): void {
this.document.location.href = 'https://stackoverflow.com';
}
some-page.component.html
<button type="button" (click)="goToUrl()">Click me!</button>
Check out the platformBrowser repo for more info.
The solution, as Dennis Smolek said, is dead simple. Set window.location.href to the URL you want to switch to and it just works.
For example, if you had this method in your component's class file (controller):
goCNN() {
window.location.href='http://www.cnn.com/';
}
Then you could call it quite simply with the appropriate (click) call on a button (or whatever) in your template:
<button (click)="goCNN()">Go to CNN</button>
I think you need à target="_blank", so then you can use window.open :
gotoGoogle() : void {
window.open("https://www.google.com", "_blank");
}
If you've been using the OnDestry lifecycle hook, you might be interested in using something like this before calling window.location.href=...
this.router.ngOnDestroy();
window.location.href = 'http://www.cnn.com/';
that will trigger the OnDestry callback in your component that you might like.
Ohh, and also:
import { Router } from '#angular/router';
is where you find the router.
---EDIT---
Sadly, I might have been wrong in the example above. At least it's not working as exepected in my production code right now - so, until I have time to investigate further, I solve it like this (since my app really need the hook when possible)
this.router.navigate(["/"]).then(result=>{window.location.href = 'http://www.cnn.com/';});
Basically routing to any (dummy) route to force the hook, and then navigate as requested.
in newer versions of Angular with window as an any
(window as any).open(someUrl, "_blank");
There are 2 options:
if you want to redirect in same window/tab
gotoExternalDomain(){
window.location.href='http://google.com/'
}
if you want to redirect in new tab
gotoExternalDomain(){
(window as any).open("http://google.com/", "_blank");
}
After ripping my head off, the solution is just to add http:// to href.
Go somewhere
I used window.location.href='http://external-url';
For me the the redirects worked in Chrome, but didn't work in Firefox.
The following code resolved my problem:
window.location.assign('http://external-url');
I did it using Angular 2 Location since I didn't want to manipulate the global window object myself.
https://angular.io/docs/ts/latest/api/common/index/Location-class.html#!#prepareExternalUrl-anchor
It can be done like this:
import {Component} from '#angular/core';
import {Location} from '#angular/common';
#Component({selector: 'app-component'})
class AppCmp {
constructor(location: Location) {
location.go('/foo');
}
}
You can redirect with multiple ways:
like
window.location.href = 'redirect_url';
another way Angular document:
import document from angular and the document must be inject as well as bellow otherwise you will get error
import { DOCUMENT } from '#angular/common';
export class AppComponent {
constructor(
#Inject(DOCUMENT) private document: Document
) {}
this.document.location.href = 'redirect_url';
}
None of the above solutions worked for me, I just added
window.location.href = "www.google.com"
event.preventDefault();
This worked for me.
Or try using
window.location.replace("www.google.com");
To use #Inject, you must import it. I didn't see this in any of the answers.
TS file:
import { Component, Inject } from '#angular/core';
import { DOCUMENT } from '#angular/common';
#Component({
selector: 'app-my-comp.page',
templateUrl: './my-comp.page.component.html',
styleUrls: ['./my-comp.page.component.scss']
})
export class MyCompPageComponent {
constructor(
#Inject(DOCUMENT) private document: Document
) { }
goToUrl(): void {
this.document.location.href = 'https://google.com/';
}
}
HTML file:
<button type="button" (click)="goToUrl()">Google</button>
In your component.ts
import { Component } from '#angular/core';
#Component({
...
})
export class AppComponent {
...
goToSpecificUrl(url): void {
window.location.href=url;
}
gotoGoogle() : void {
window.location.href='https://www.google.com';
}
}
In your component.html
<button type="button" (click)="goToSpecificUrl('http://stackoverflow.com/')">Open URL</button>
<button type="button" (click)="gotoGoogle()">Open Google</button>
<li *ngFor="item of itemList" (click)="goToSpecificUrl(item.link)"> // (click) don't enable pointer when we hover so we should enable it by using css like: **cursor: pointer;**
Just simple as this
window.location.href='http://www.google.com/';
After the facebook button is pushed, the user logs in and then that webview immediately goes to the facebook mobile site. What I need is for that webview to disappear so I can continue interacting with my app, and not the facebook mobile site.
I apologize if I'm not being clear, its 5am and I'm, going a little crazy here lol. Take a look at the code...
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
backgroundColor="#2F28C1" title="Setup"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import com.facebook.graph.FacebookMobile;
import mx.events.FlexEvent;
import views.setup_first.facebook;
import views.setup_first.flickr;
import views.setup_first.google;
import views.setup_first.tumblr;
import views.setup_first.twitter;
public var permissions:Array = ["user_birthday", "read_stream", "publish_stream"];
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
FacebookMobile.init("262320357178421", loginHandler);
}
protected function loginHandler(success:Object,fail:Object):void
{
}
protected function login():void
{
var facebookWebView:StageWebView = new StageWebView();
facebookWebView.viewPort = new Rectangle (0,0, stage.width, stage.height);
FacebookMobile.login(loginHandler, this.stage, permissions, facebookWebView);
trace("I'm logged in!");
}
protected function logout():void
{
FacebookMobile.logout(onLogout, "https://m.facebook.com/dialog/permissions.request?app_id=262320357178421&display=touch&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&type=user_agent&perms=publish_stream&fbconnect=1");
}
protected function onLogout(result:Object):void
{
trace("Perfect Log Out!")
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:navigationContent/>
<s:Button left="62" top="86" click="navigator.pushView(views.setup_first.google)"
icon="#Embed('../Setup/Setup_0002_Layer-5.png')"/>
<s:Button right="64" top="86" click="login()" icon="#Embed('../Setup/Setup_0001_Layer-6.png')"/>
<s:Button click="navigator.pushView(views.setup_first.tumblr)" horizontalCenter="-4"
icon="#Embed('../Setup/Setup_0000_Layer-7.png')" verticalCenter="-14"/>
<s:Button left="62" bottom="117" click="navigator.pushView(views.setup_first.flickr)"
icon="#Embed('../Setup/Setup_0004_Setup.png')"/>
<s:Button right="63" bottom="117" click="navigator.pushView(views.setup_first.twitter)"
icon="#Embed('../Setup/Setup_0005_Layer-1.png')"/>
<s:Button right="54" bottom="10" label="Skip" click="navigator.pushView(thirdPage)"/>
<s:Button id="logOut" x="323" y="210" height="28" label="LogOut" fontSize="15"
click="logout()"/>
Hello Corey I don't know if you resolved your question but I did just a moment, so I will tell you about my experience.
With your code if the user logged in, and install the app in his applications of facebook, the loginHandler is dispatched with the FacebookSession in success, and facebookWebView is removed automatically.
But If the user cancel the install or don't allow the requested permissions there is not any event dispatched and facebookWebView show a white page with the word "Success".
I have fixed this adding listeners to facebookWebView of location chage event. Then always facebookWebView change the url showed the method is dispatched, including when there is the error of user denied (dispatched when the user don't allow the app).
This is my code:
private var facebookWebView:StageWebView = new StageWebView();
protected function login():void{
facebookWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChange);
facebookWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChange);
facebookWebView.viewPort = new Rectangle(0, 0, stage.width, stage.height);
FacebookMobile.login(onLogin, this.stage, permissions, facebookWebView);
}
private function locationChange(e:LocationChangeEvent):void
{
var url:String = e.location;
if(url.search("error") != -1)
removeFacebookView();
}
protected function onLogin(success:Object, fail:Object):void{
if(success){
//save user content FacebookSession(success).user
removeFacebookView();
setCurrentState("login");
}
}
private function removeFacebookView():void
{
facebookWebView.removeEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChange);
facebookWebView.removeEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChange);
this.actionBarVisible = true;
facebookWebView.stage = null;
}
As you can see to remove the facebookWebView I have a variable in the view, not a local variable of the function. (You can get it with e.target too). And you will remove it with facebookWebView.stage = null; Don't remove the eventlistener before. Only when loginhandle is dispatched with success, and when there is an error and you must to remove facebookWebView.