This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
253bc0c
commit e92e153
Showing
3 changed files
with
58 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,53 @@ | ||
import React, {PropTypes} from 'react' | ||
import {Button} from 'react-toolbox' | ||
import {Card, CardTitle, CardText, CardActions} from 'react-toolbox/lib/card' | ||
import {List, ListItem, ListSubHeader, Button} from 'react-toolbox' | ||
|
||
export default function (compDef) { | ||
const {componentName} = compDef | ||
const {componentName, | ||
fields | ||
} = compDef | ||
|
||
const ComponentDisplay = (props) => { | ||
const {goBack, pushRoute, routing} = props | ||
const url = routing.locationBeforeTransitions.pathname | ||
const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) | ||
const fieldNames = Object.keys(fields) | ||
const ComponentEdit = (props) =>{ | ||
let next = Object.assign({}, props[componentName]) | ||
const url = props.routing.locationBeforeTransitions.pathname | ||
const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit` | ||
const component = props[`${componentName}`] | ||
let content = [] | ||
let cardActions = <div> | ||
<Button icon='add' | ||
floating accent mini onClick={()=>{ | ||
pushRoute(editURL)}}/> | ||
<Button icon='undo' | ||
floating accent mini onClick={()=>{ | ||
goBack()}}/> | ||
</div> | ||
if (component.index !== undefined) { | ||
for (let field of component) { | ||
if (component[field] && compDef[field]) { | ||
content.push(<p>{compDef[field].label} : {component[field]}</p>) | ||
} | ||
} | ||
const {goBack} = props | ||
const listCaption = `Datos de ${componentProperName}` | ||
const listFields = [] | ||
|
||
for (let fieldName of fieldNames) { | ||
const componentField = compDef.fields[fieldName] | ||
const field = <div key={fieldName}> | ||
<ListItem caption={next[fieldName] ||''} | ||
legend={componentField.label} righticon={componentField.icon}/> | ||
</div> | ||
listFields.push(field) | ||
} | ||
|
||
return <Card> | ||
<CardTitle title={compDef.title}/> | ||
<CardText>{content}</CardText> | ||
<CardActions>{cardActions}</CardActions> | ||
</Card> | ||
return ( | ||
<div> | ||
<List> | ||
<ListSubHeader caption={listCaption}/> | ||
{listFields} | ||
</List> | ||
<Button icon='edit' floating disabled={!next.isValid} accent mini onClick={(e)=>{ | ||
props.pushRoute(editURL) | ||
}}/> | ||
<Button icon='undo' floating accent mini onClick={()=>{goBack()}}/> | ||
</div> | ||
) | ||
} | ||
|
||
ComponentDisplay.propTypes = {} | ||
ComponentDisplay.propTypes[`${componentName}`] = PropTypes.object | ||
ComponentDisplay.propTypes.goBack = PropTypes.func | ||
ComponentDisplay.propTypes.pushRoute = PropTypes.func | ||
ComponentDisplay.propTypes.routing = PropTypes.object | ||
|
||
return ComponentDisplay | ||
ComponentEdit.propTypes = { | ||
pushRoute: PropTypes.func, | ||
goBack: PropTypes.func, | ||
routing: PropTypes.object | ||
} | ||
ComponentEdit.propTypes[`${componentName}`] = PropTypes.object | ||
ComponentEdit.propTypes[`save${componentProperName}`] = PropTypes.func | ||
ComponentEdit.propTypes[`store${componentProperName}`] = PropTypes.func | ||
return ComponentEdit | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters