Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit dc8749b

Browse files
committed
Missing form component type "monitor", factorize with "button".
1 parent d73a15f commit dc8749b

File tree

1 file changed

+74
-17
lines changed

1 file changed

+74
-17
lines changed

core/src/plugins/gui.ajax/res/js/ui/reactjs/jsx/ReactFormComponents.js

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -645,18 +645,15 @@
645645

646646
});
647647

648-
/**
649-
* Simple RaisedButton executing the applyButtonAction
650-
*/
651-
var InputButton = React.createClass({
648+
var ActionRunnerMixin = {
652649

653650
propTypes:{
654-
attributes:React.PropTypes.object,
651+
attributes:React.PropTypes.object.isRequired,
655652
applyButtonAction:React.PropTypes.func,
656653
actionCallback:React.PropTypes.func
657654
},
658655

659-
applyButton:function(){
656+
applyAction:function(callback){
660657
var choicesValue = this.props.attributes['choices'].split(":");
661658
var firstPart = choicesValue.shift();
662659
if(firstPart == "run_client_action" && global.pydio){
@@ -672,19 +669,35 @@
672669
if(this.props.attributes['name'].indexOf("/") !== -1){
673670
parameters['button_key'] = PathUtils.getDirname(this.props.attributes['name']);
674671
}
675-
var callback = this.props.actionCallback;
676-
if(!callback){
677-
callback = function(transport){
678-
var text = transport.responseText;
679-
if(text.startsWith('SUCCESS:')){
680-
global.pydio.displayMessage('SUCCESS', transport.responseText.replace('SUCCESS:', ''));
681-
}else{
682-
global.pydio.displayMessage('ERROR', transport.responseText.replace('ERROR:', ''));
683-
}
684-
};
685-
}
686672
this.props.applyButtonAction(parameters, callback);
687673
}
674+
}
675+
676+
};
677+
678+
/**
679+
* Simple RaisedButton executing the applyButtonAction
680+
*/
681+
var InputButton = React.createClass({
682+
683+
mixins:[ActionRunnerMixin],
684+
685+
686+
applyButton:function(){
687+
688+
var callback = this.props.actionCallback;
689+
if(!callback){
690+
callback = function(transport){
691+
var text = transport.responseText;
692+
if(text.startsWith('SUCCESS:')){
693+
global.pydio.displayMessage('SUCCESS', transport.responseText.replace('SUCCESS:', ''));
694+
}else{
695+
global.pydio.displayMessage('ERROR', transport.responseText.replace('ERROR:', ''));
696+
}
697+
};
698+
}
699+
this.applyAction(callback);
700+
688701
},
689702

690703
render:function(){
@@ -698,6 +711,46 @@
698711
}
699712
});
700713

714+
715+
var MonitoringLabel = React.createClass({
716+
717+
mixins:[ActionRunnerMixin],
718+
719+
getInitialState:function(){
720+
let loadingMessage = 'Loading';
721+
if(this.context && this.context.getMessage){
722+
loadingMessage = this.context.getMessage(466, '');
723+
}else if(global.pydio && global.pydio.MessageHash){
724+
loadingMessage = global.pydio.MessageHash[466];
725+
}
726+
return {status:loadingMessage};
727+
},
728+
729+
componentDidMount:function(){
730+
var callback = function(transport){
731+
this.setState({status:transport.responseText});
732+
}.bind(this);
733+
this._poller = function(){
734+
this.applyAction(callback);
735+
}.bind(this);
736+
this._poller();
737+
this._pe = global.setInterval(this._poller, 10000);
738+
},
739+
740+
componentWillUnmount:function(){
741+
if(this._pe){
742+
global.clearInterval(this._pe);
743+
}
744+
},
745+
746+
render: function(){
747+
return (<div>{this.state.status}</div>);
748+
}
749+
750+
751+
});
752+
753+
701754
/**
702755
* UI to drop a file (or click to browse), used by the InputImage component.
703756
*/
@@ -1664,6 +1717,9 @@
16641717
case 'button':
16651718
value = <InputButton {...props}/>;
16661719
break;
1720+
case 'monitor':
1721+
value = <MonitoringLabel {...props}/>;
1722+
break;
16671723
case 'image':
16681724
value = <InputImage {...props}/>;
16691725
break;
@@ -1831,6 +1887,7 @@
18311887
PydioForm.InputBoolean = InputBoolean;
18321888
PydioForm.InputInteger = InputInteger;
18331889
PydioForm.InputButton = InputButton;
1890+
PydioForm.MonitoringLabel = MonitoringLabel;
18341891
PydioForm.InputSelectBox = InputSelectBox;
18351892
PydioForm.InputImage = InputImage;
18361893
PydioForm.FormPanel = PydioFormPanel;

0 commit comments

Comments
 (0)