flux_on_rails 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/flux_on_rails-1.0.0.gem +0 -0
- data/flux_on_rails.gemspec +23 -0
- data/lib/flux_on_rails.rb +5 -0
- data/lib/flux_on_rails/version.rb +3 -0
- data/lib/generators/flux_on_rails/install_generator.rb +51 -0
- data/lib/generators/flux_on_rails/templates/actions/example-actions.js +22 -0
- data/lib/generators/flux_on_rails/templates/application.js +3 -0
- data/lib/generators/flux_on_rails/templates/components/.gitkeep +0 -0
- data/lib/generators/flux_on_rails/templates/constants/app-constants.js +5 -0
- data/lib/generators/flux_on_rails/templates/dispatcher.js +280 -0
- data/lib/generators/flux_on_rails/templates/dispatchers/app-dispatcher.js +29 -0
- data/lib/generators/flux_on_rails/templates/form-for.js +1 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/.bower.json +15 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/.bowerrc +3 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/.gitignore +2 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/README.md +94 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/checkbox-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/color-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/date-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/datetime-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/email-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/form-errors.react.js +13 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/form-for.react.js +78 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/hidden-input.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/input.react.js +92 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/number-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/options-for-select.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/password-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/radio-input.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/select-input.react.js +17 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/submit-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/text-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/textarea-input.react.js +10 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/components/time-input.react.js +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/bower.json +11 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/index.html +6 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/js/app.js +76 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/example/react/app.jsx +76 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/gulpfile.js +39 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/package.json +12 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/src/bower.json +27 -0
- data/lib/generators/flux_on_rails/templates/react-form-for-object/src/form-for.js +362 -0
- data/lib/generators/flux_on_rails/templates/react.js +18095 -0
- data/lib/generators/flux_on_rails/templates/stores/example-store.js +110 -0
- data/lib/generators/flux_on_rails/templates/tasks/react_tasks.rake +14 -0
- metadata +122 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
//= require dispatcher
|
2
|
+
|
3
|
+
var AppDispatcher = $.extend(new Dispatcher(), {
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @param {object} action The details of the action, including the action's
|
7
|
+
* type and additional data coming from the server.
|
8
|
+
*/
|
9
|
+
handleServerAction: function(action) {
|
10
|
+
var payload = {
|
11
|
+
source: 'SERVER_ACTION',
|
12
|
+
action: action
|
13
|
+
};
|
14
|
+
this.dispatch(payload);
|
15
|
+
},
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @param {object} action The details of the action, including the action's
|
19
|
+
* type and additional data coming from the view.
|
20
|
+
*/
|
21
|
+
handleViewAction: function(action) {
|
22
|
+
var payload = {
|
23
|
+
source: 'VIEW_ACTION',
|
24
|
+
action: action
|
25
|
+
};
|
26
|
+
this.dispatch(payload);
|
27
|
+
}
|
28
|
+
|
29
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require ./react-form-for-object/src/form-for
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"name": "react-form-for-object",
|
3
|
+
"homepage": "https://github.com/edshadi/react-form-for",
|
4
|
+
"version": "1.0.0",
|
5
|
+
"_release": "1.0.0",
|
6
|
+
"_resolution": {
|
7
|
+
"type": "version",
|
8
|
+
"tag": "v1.0.0",
|
9
|
+
"commit": "4eb5230dc74fd4f7e9127246303ce431462cd7d1"
|
10
|
+
},
|
11
|
+
"_source": "git://github.com/edshadi/react-form-for.git",
|
12
|
+
"_target": "~1.0.0",
|
13
|
+
"_originalSource": "react-form-for-object",
|
14
|
+
"_direct": true
|
15
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
## React Form For Object
|
2
|
+
|
3
|
+
No-effort, simple ReactJS form builder for Javascript objects.
|
4
|
+
|
5
|
+
Simply pass FormFor a javascript object and it will display the form and handle
|
6
|
+
data for you. You can always override defaults by passing FormFor options.
|
7
|
+
|
8
|
+
There is a full working example [here](./example)
|
9
|
+
|
10
|
+
### Install
|
11
|
+
```bash
|
12
|
+
bower install react-form-for-object
|
13
|
+
```
|
14
|
+
|
15
|
+
### Usage
|
16
|
+
FormFor will determine the type of input based on the your object. We do our best
|
17
|
+
to detect the type of the input you're looking for. However, some things are harder to detect such as textarea. We give you the option to override them in the options by passing a type (see example below).
|
18
|
+
|
19
|
+
Supply a submit handler with onSubmit key in the options. On submit, FormFor will pass all of the form data to the callback you provided.
|
20
|
+
|
21
|
+
Supply a cancel handler with onCancel key in the options. If you don't want a cancel button,
|
22
|
+
simply don't supply an onCancel handler.
|
23
|
+
|
24
|
+
FormFor will display all errors supplied to it in the errors prop.
|
25
|
+
|
26
|
+
If we can't successfully detect the type of value from an object attribute, we default
|
27
|
+
to text input.
|
28
|
+
|
29
|
+
By default, id attributes are built as hidden input.
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
var todo = {
|
33
|
+
name: "Clean my room",
|
34
|
+
description: "My room needs some serious cleaning",
|
35
|
+
completed: false,
|
36
|
+
list: "Home"
|
37
|
+
}
|
38
|
+
var formOptions: {
|
39
|
+
onSubmit: function(data, utils) {console.log(data)},
|
40
|
+
onCancel: function(data) { //do something like change state to editing false }
|
41
|
+
description: { type: 'textarea' },
|
42
|
+
list: { type: 'select', values: [{value:"Home", show: "Home"}, {value:"Work", show: "Work"}] }
|
43
|
+
}
|
44
|
+
|
45
|
+
<FormFor object={todo} options={formOptions} errors={[]} />
|
46
|
+
|
47
|
+
```
|
48
|
+
#### How to use the options
|
49
|
+
Each attribute on your object can have its own options/overrides. In your option object,
|
50
|
+
use the name of the attribute as the key (see example above). Currently you can supply the following options:
|
51
|
+
|
52
|
+
- type: 'textarea', 'select' (please see supported inputs below). Please keep in mind that you don't have to supply any options for FormFor to work, only supply them to override what we give you
|
53
|
+
based on your object attributes.
|
54
|
+
- className
|
55
|
+
- value
|
56
|
+
- onSubmit
|
57
|
+
- onCancel
|
58
|
+
|
59
|
+
|
60
|
+
### Input support
|
61
|
+
|
62
|
+
- text
|
63
|
+
- checkbox
|
64
|
+
- number
|
65
|
+
- hidden
|
66
|
+
- select
|
67
|
+
- password
|
68
|
+
- textarea
|
69
|
+
- date
|
70
|
+
- datetime
|
71
|
+
- email
|
72
|
+
- submit
|
73
|
+
- color
|
74
|
+
|
75
|
+
### Utilities
|
76
|
+
When we call your submitHandler, we pass it a utils object that will have
|
77
|
+
some useful functions that you could use. Currently, we support the following
|
78
|
+
utility functions:
|
79
|
+
- clearInputs: use this to clear all input fields after success.
|
80
|
+
|
81
|
+
## Examples
|
82
|
+
A working example can be found [here](./example)
|
83
|
+
|
84
|
+
## TODO
|
85
|
+
- file
|
86
|
+
- image
|
87
|
+
- month
|
88
|
+
- radio
|
89
|
+
- range
|
90
|
+
- reset
|
91
|
+
- search
|
92
|
+
- tel
|
93
|
+
- url
|
94
|
+
- week
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/checkbox-input.react.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
var CheckboxInput = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var data = this.props.data;
|
4
|
+
return (
|
5
|
+
<input ref={data.name} type="checkbox" defaultChecked={data.defaultChecked} className={data.className} value={data.value} />
|
6
|
+
);
|
7
|
+
}
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
module.exports = CheckboxInput;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/color-input.react.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
var ColorInput = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var data = this.props.data;
|
4
|
+
return (
|
5
|
+
<input ref={data.name} name={data.name} type="color" defaultValue={data.defaultValue} className={data.className} />
|
6
|
+
);
|
7
|
+
}
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
module.exports = ColorInput;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/date-input.react.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
var DateInput = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var data = this.props.data;
|
4
|
+
return (
|
5
|
+
<input ref={data.name} type="date" defaultValue={data.defaultValue} placeholder={data.placeholder} className={data.className} />
|
6
|
+
);
|
7
|
+
}
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
module.exports = DateInput;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/datetime-input.react.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
var DatetimeInput = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var data = this.props.data;
|
4
|
+
return (
|
5
|
+
<input ref={data.name} type="datetime-local" defaultValue={data.defaultValue} className={data.className} />
|
6
|
+
);
|
7
|
+
}
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
module.exports = DatetimeInput;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/email-input.react.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
var EmailInput = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var data = this.props.data;
|
4
|
+
return (
|
5
|
+
<input ref={data.name} type="email" defaultValue={data.defaultValue} placeholder={data.placeholder} className={data.className} />
|
6
|
+
);
|
7
|
+
}
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
module.exports = EmailInput;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/form-errors.react.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
var FormErrors = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var errors = [];
|
4
|
+
this.props.errors.forEach(function(err) {
|
5
|
+
errors.push(<li>{err}</li>)
|
6
|
+
})
|
7
|
+
return (
|
8
|
+
<ul className="form-errors">{errors}</ul>
|
9
|
+
);
|
10
|
+
}
|
11
|
+
});
|
12
|
+
|
13
|
+
module.exports = FormErrors;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/form-for.react.js
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
var Input = require('./input.react');
|
2
|
+
var FormErrors = require('./form-errors.react');
|
3
|
+
module.exports = FormFor = React.createClass({
|
4
|
+
render: function() {
|
5
|
+
if(Object.keys(this.props.object).length === 0) return(<div />);
|
6
|
+
return (
|
7
|
+
<form onSubmit={this.handleSubmit} className="form-for">
|
8
|
+
<FormErrors errors={this.props.errors} />
|
9
|
+
{this.inputs()}
|
10
|
+
<input type="submit" value={this.submitText()} className="btn btn-default"/>
|
11
|
+
{this.renderCancelButton()}
|
12
|
+
</form>
|
13
|
+
);
|
14
|
+
},
|
15
|
+
inputs: function() {
|
16
|
+
var object = this.props.object;
|
17
|
+
var inputs = [];
|
18
|
+
Object.keys(object).forEach(function(key, i) {
|
19
|
+
var value = object[key];
|
20
|
+
var dataForInput = {value: value, name: key}
|
21
|
+
var options = this.options()[key] || {};
|
22
|
+
inputs.push(<Input key={key} ref={key} data={dataForInput} options={options}/>);
|
23
|
+
}.bind(this));
|
24
|
+
return inputs;
|
25
|
+
},
|
26
|
+
options: function() {
|
27
|
+
return this.props.options || {};
|
28
|
+
},
|
29
|
+
submitText: function() {
|
30
|
+
var submit = this.options().submit;
|
31
|
+
if(submit && submit.value) return submit.value
|
32
|
+
submit = this.props.object.id ? 'Update' : 'Create';
|
33
|
+
if(this.options().objectName) submit = submit + ' ' + this.options().objectName;
|
34
|
+
return submit;
|
35
|
+
},
|
36
|
+
handleSubmit: function(e) {
|
37
|
+
e.preventDefault();
|
38
|
+
var submitHandler = this.options().onSubmit
|
39
|
+
if(submitHandler) {
|
40
|
+
var data = {};
|
41
|
+
Object.keys(this.refs).forEach(function(ref) {
|
42
|
+
var value = this.getInputValue(ref);
|
43
|
+
data[ref] = value;
|
44
|
+
}.bind(this));
|
45
|
+
submitHandler(data, {clearInputs: this.clearInputs});
|
46
|
+
} else {
|
47
|
+
console.log("You must pass an onSubmit function in your options.");
|
48
|
+
}
|
49
|
+
},
|
50
|
+
renderCancelButton: function() {
|
51
|
+
if(!this.options().onCancel) return;
|
52
|
+
return(<input type="button" value="Cancel" onClick={this.handleCancel} />);
|
53
|
+
},
|
54
|
+
handleCancel: function() {
|
55
|
+
this.clearInputs();
|
56
|
+
this.options().onCancel();
|
57
|
+
},
|
58
|
+
getInputValue: function(ref) {
|
59
|
+
// find the ref component
|
60
|
+
// find the refs of the found component
|
61
|
+
// find the input ref from the found component
|
62
|
+
// get the getDOMNode and the value
|
63
|
+
if(this.refs[ref] && this.refs[ref].refs && this.refs[ref].refs.input && this.refs[ref].refs.input.getDOMNode) {
|
64
|
+
var input = this.refs[ref].refs.input.getDOMNode();
|
65
|
+
if(input.type === "checkbox") return input.checked;
|
66
|
+
return input.value;
|
67
|
+
}
|
68
|
+
},
|
69
|
+
// Utility function to clear inputs.
|
70
|
+
clearInputs: function() {
|
71
|
+
Object.keys(this.refs).forEach(function(ref) {
|
72
|
+
if(this.refs[ref] && this.refs[ref].refs && this.refs[ref].refs.input && this.refs[ref].refs.input.getDOMNode) {
|
73
|
+
this.refs[ref].refs.input.getDOMNode().value = "";
|
74
|
+
}
|
75
|
+
}.bind(this));
|
76
|
+
}
|
77
|
+
|
78
|
+
});
|
@@ -0,0 +1,92 @@
|
|
1
|
+
var TextInput = require('./text-input.react');
|
2
|
+
var CheckboxInput = require('./checkbox-input.react');
|
3
|
+
var NumberInput = require('./number-input.react');
|
4
|
+
var HiddenInput = require('./hidden-input.react');
|
5
|
+
var SelectInput = require('./select-input.react');
|
6
|
+
var PasswordInput = require('./password-input.react');
|
7
|
+
var TextareaInput = require('./textarea-input.react');
|
8
|
+
var DateInput = require('./date-input.react');
|
9
|
+
var ColorInput = require('./color-input.react');
|
10
|
+
var DatetimeInput = require('./datetime-input.react');
|
11
|
+
var EmailInput = require('./email-input.react');
|
12
|
+
var TimeInput = require('./time-input.react');
|
13
|
+
var Input = React.createClass({
|
14
|
+
render: function() {
|
15
|
+
var data = this.props.data;
|
16
|
+
return (
|
17
|
+
<div>
|
18
|
+
<div className="form-group">
|
19
|
+
{this.input()}
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
);
|
23
|
+
},
|
24
|
+
input: function() {
|
25
|
+
var data = this.props.data;
|
26
|
+
switch(this.type()) {
|
27
|
+
case 'boolean':
|
28
|
+
return(<span><CheckboxInput ref="input" data={{name: data.name, defaultChecked: data.value, className: this.props.options.className, value: data.value}} /><span>{this.placeholder()}</span></span>)
|
29
|
+
break;
|
30
|
+
case 'number':
|
31
|
+
return(<NumberInput ref="input" data={{name: data.name, defaultValue: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
32
|
+
break;
|
33
|
+
case 'color':
|
34
|
+
return(<ColorInput ref="input" data={{name: data.name, defaultValue: data.value, className: this.props.options.className}} />)
|
35
|
+
break;
|
36
|
+
case 'email':
|
37
|
+
return(<EmailInput ref="input" data={{name: data.name, defaultValue: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
38
|
+
break;
|
39
|
+
case 'date':
|
40
|
+
return(<DateInput ref="input" data={{name: data.name, defaultValue: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
41
|
+
break;
|
42
|
+
case 'datetime':
|
43
|
+
return(<DatetimeInput ref="input" data={{name: data.name, defaultValue: data.value, className: this.props.options.className}} />)
|
44
|
+
break;
|
45
|
+
case 'time':
|
46
|
+
return(<TimeInput ref="input" data={{name: data.name, defaultValue: data.value, className: this.props.options.className}} />)
|
47
|
+
break;
|
48
|
+
case 'hidden':
|
49
|
+
return(<HiddenInput ref="input" data={{name: data.name, value: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
50
|
+
break;
|
51
|
+
case 'select':
|
52
|
+
return(<SelectInput ref="input" data={{name: data.name, value: data.value, values: this.props.options.values , className: this.props.options.className}} />)
|
53
|
+
break;
|
54
|
+
case 'password':
|
55
|
+
return(<PasswordInput ref="input" data={{name: data.name, defaultChecked: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
56
|
+
break;
|
57
|
+
case 'textarea':
|
58
|
+
return(<TextareaInput ref="input" data={{name: data.name, defaultValue: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
59
|
+
break;
|
60
|
+
default:
|
61
|
+
return(<TextInput ref="input" data={{name: data.name, defaultValue: data.value, placeholder: this.placeholder(), className: this.props.options.className}} />)
|
62
|
+
}
|
63
|
+
|
64
|
+
},
|
65
|
+
type: function() {
|
66
|
+
var type = typeof(this.props.data.value);
|
67
|
+
if(this.props.options.type) type = this.props.options.type;
|
68
|
+
if(this.isId()) type = 'hidden';
|
69
|
+
if(this.isPassword()) type = 'password';
|
70
|
+
if(this.isEmail()) type = 'email';
|
71
|
+
return type;
|
72
|
+
},
|
73
|
+
isId: function() {
|
74
|
+
if(this.props.data.name === 'id') return true;
|
75
|
+
return false;
|
76
|
+
},
|
77
|
+
isPassword: function() {
|
78
|
+
if(this.props.data.name === 'password' || this.props.data.name === 'password_confirmation') return true;
|
79
|
+
return false;
|
80
|
+
},
|
81
|
+
isEmail: function() {
|
82
|
+
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
83
|
+
if(this.props.data.name === 'email' || re.test(this.props.data.value)) return true;
|
84
|
+
return false;
|
85
|
+
},
|
86
|
+
placeholder: function() {
|
87
|
+
var name = this.props.options.placeholder || this.props.data.name;
|
88
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
89
|
+
}
|
90
|
+
});
|
91
|
+
|
92
|
+
module.exports = Input;
|
data/lib/generators/flux_on_rails/templates/react-form-for-object/components/number-input.react.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
var NumberInput = React.createClass({
|
2
|
+
render: function() {
|
3
|
+
var data = this.props.data;
|
4
|
+
return (
|
5
|
+
<input ref={data.name} type="number" defaultValue={data.defaultValue} placeholder={data.placeholder} className={data.className}/>
|
6
|
+
);
|
7
|
+
}
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
module.exports = NumberInput;
|