From 678af2747d6414379e81ee6856c7ec2f3cd5a890 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Sat, 30 Jan 2016 23:17:03 +0100 Subject: registering modifications on feeds / categories --- src/web/js/components/RightPanel.react.js | 156 ++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 51 deletions(-) (limited to 'src/web/js/components/RightPanel.react.js') diff --git a/src/web/js/components/RightPanel.react.js b/src/web/js/components/RightPanel.react.js index 2e2aac3e..fda7c976 100644 --- a/src/web/js/components/RightPanel.react.js +++ b/src/web/js/components/RightPanel.react.js @@ -4,11 +4,15 @@ var Glyphicon = require('react-bootstrap/Glyphicon'); var Button = require('react-bootstrap/Button'); var ButtonGroup = require('react-bootstrap/ButtonGroup'); +var RightPanelActions = require('../actions/RightPanelActions'); var RightPanelStore = require('../stores/RightPanelStore'); var JarrTime = require('./time.react'); var PanelMixin = { propTypes: {obj: React.PropTypes.object.isRequired}, + getInitialState: function() { + return {edit_mode: false, obj: this.props.obj}; + }, getHeader: function() { var icon = null; if(this.props.obj.icon_url){ @@ -46,7 +50,9 @@ var PanelMixin = { var items = []; var key; if(!this.state.edit_mode) { - this.fields.map(function(field) { + this.fields.filter(function(field) { + return field.type != 'ignore'; + }).map(function(field) { key = this.getKey('dt', field.key); items.push(
{field.title}
); key = this.getKey('dd', field.key); @@ -67,24 +73,30 @@ var PanelMixin = { } }.bind(this)); } else { - this.fields.map(function(field) { + items.push(
+ +
); + this.fields.filter(function(field) { + return field.type != 'ignore'; + }).map(function(field) { key = this.getKey('dd', field.key); items.push(
{field.title}
); key = this.getKey('dt', field.key); + var input = null; if(field.type == 'string' || field.type == 'link') { - items.push(
-
); + input = (); } else if (field.type == 'bool') { - items.push(
); + input = (); } + items.push(
{input}
); }.bind(this)); - items.push(
- -
); } return (
{items}
); }, @@ -99,15 +111,39 @@ var PanelMixin = { this.setState({edit_mode: !this.state.edit_mode}); }, onClickRemove: function() { + RightPanelActions.delObj(this.props.obj.id, this.obj_type); + }, + saveField: function(evnt) { + var obj = this.state.obj; + for(var i in this.fields) { + if(evnt.target.name == this.fields[i].key) { + if(this.fields[i].type == 'bool') { + obj[evnt.target.name] = evnt.target.checked; + } else { + obj[evnt.target.name] = evnt.target.value; + } + break; + } + } + this.setState({obj: obj}); + }, + saveObj: function() { + var to_push = {}; + this.fields.map(function(field) { + to_push[field.key] = this.state.obj[field.key]; + }.bind(this)); + this.setState({edit_mode: false}, function() { + RightPanelActions.putObj(this.props.obj.id, this.obj_type, to_push); + }.bind(this)); }, }; var Article = React.createClass({ mixins: [PanelMixin], - getInitialState: function() {return {edit_mode: false};}, - fields: [], isEditable: function() {return false;}, isRemovable: function() {return true;}, + fields: [], + obj_type: 'article', getTitle: function() {return this.props.obj.title;}, getBody: function() { return (
+ + - - ); }, - getBody: function() { - var filter_rows = []; - for(var i in this.state.filters) { - filter_rows.push(this.getFilterRow(i, this.state.filters[i])); + getFilterRows: function() { + var rows = []; + if(this.state.edit_mode) { + for(var i in this.state.obj.filters) { + rows.push(this.getFilterRow(i, this.state.obj.filters[i])); + } + return (
+
Filters
+
+ +
+ {rows} +
); } + rows = []; + rows.push(
Filters
); + for(var i in this.state.obj.filters) { + rows.push(
+ When {this.state.obj.filters[i]['action on']} on "{this.state.obj.filters[i].pattern}" ({this.state.obj.filters[i].type}) => {this.state.obj.filters[i].action} +
); + } + return
{rows}
; + }, + getBody: function() { return (
Created on
@@ -174,44 +235,37 @@ var Feed = React.createClass({
{this.getCore()} -
-
-
Filters
-
- - -
- {filter_rows} -
-
+ {this.getFilterRows()}
); }, addFilterRow: function() { - var filters = this.state.filters; - filters.push({action: null, action_on: null, - type: null, pattern: null}); - this.setState({filters: filters}); + var obj = this.state.obj; + obj.filters.push({action: "mark as read", 'action on': "match", + type: "simple match", pattern: ""}); + this.setState({obj: obj}); }, removeFilterRow: function(evnt) { - var filters = this.state.filters; - delete filters[evnt.target.getAttribute('data-index')]; - this.setState({filters: filters}); + var obj = this.state.obj; + delete obj.filters[evnt.target.getAttribute('data-index')]; + this.setState({obj: obj}); + }, + saveFilterChange: function(evnt) { + var index = evnt.target.getAttribute('data-index'); + var obj = this.state.obj; + obj.filters[index][evnt.target.name] = evnt.target.value; + this.setState({obj: obj}); }, }); var Category = React.createClass({ mixins: [PanelMixin], - getInitialState: function() {return {edit_mode: false};}, isEditable: function() { if(this.props.obj.id != 0) {return true;} else {return false;} }, isRemovable: function() {return this.isEditable();}, + obj_type: 'category', fields: [{'title': 'Category name', 'type': 'string', 'key': 'name'}], getTitle: function() {return this.props.obj.name;}, getBody: function() { @@ -299,7 +353,7 @@ var RightPanel = React.createClass({ RightPanelStore.removeChangeListener(this._onChange); }, _onChange: function() { - this.setState(RightPanelStore._datas); + this.setState(RightPanelStore.getAll()); }, }); -- cgit