Skip to content

Commit

Permalink
bouton supprimer les keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
PookMook committed Jul 11, 2017
1 parent 0d6cda3 commit ea9b7bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion yamlEditor/dist/js/bundle.js

Large diffs are not rendered by default.

35 changes: 27 additions & 8 deletions yamlEditor/src/js/components/Keywords.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,35 @@ export function Keywords(){
)
}

function Keyword(props){
return(
<div className="keywords">
<input className={props.controlled ? "controlled":"free"} type="text" placeholder="FR" value={props.object.fr} readOnly="true"/>
<input className={props.controlled ? "controlled":"free"} type="text" placeholder="EN" value={props.object.en} readOnly="true"/>
<i className="fa fa-minus-circle" aria-hidden="true" data-id={props.index}></i>
</div>
)
class Keyword extends React.Component{

constructor(props) {
super(props);
}

removeKeyword(controlled){
if(this.props.controlled){
store.dispatch({type:"MISC_UPDATE",target:"controlledKeywords["+this.props.index+"].selected", value:false});
}
else{
let uncontrolledKeywords = store.getState().misc.uncontrolledKeywords;
uncontrolledKeywords.splice(this.props.index, 1);
store.dispatch({type:"MISC_UPDATE",target:"uncontrolledKeywords", value:uncontrolledKeywords});
}
}

render() {
return(
<div className="keywords">
<input className={this.props.controlled ? "controlled":"free"} type="text" placeholder="FR" value={this.props.object.fr} readOnly="true"/>
<input className={this.props.controlled ? "controlled":"free"} type="text" placeholder="EN" value={this.props.object.en} readOnly="true"/>
<i className="fa fa-minus-circle" aria-hidden="true" data-id={this.props.index} onClick={this.removeKeyword.bind(this)}></i>
</div>
)
}
}


class InputKeyword extends React.Component{
constructor(props) {
super(props);
Expand Down
3 changes: 2 additions & 1 deletion yamlEditor/src/js/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function compileKeywords(state){
let categories = state.misc.categories.filter(function(category){
return category.selected === true;
});
state.misc.controlledKeywords = categories;
state.obj.controlledKeywords = categories.map((o)=>(Object.assign({},o))).map(function(o){delete o.selected;return o});

//Compute uncontrolledKeywords
Expand All @@ -54,6 +55,6 @@ function compileKeywords(state){
state.obj.keyword_fr.push(state.misc.uncontrolledKeywords[i].fr);
state.obj.keyword_en.push(state.misc.uncontrolledKeywords[i].en);
}
console.log("update keywords");
//console.log("update keywords");
return state;
}

0 comments on commit ea9b7bb

Please sign in to comment.