-
Notifications
You must be signed in to change notification settings - Fork 782
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
Showing
8 changed files
with
448 additions
and
415 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,88 +1,98 @@ | ||
import React from 'react'; | ||
var Editor=function(editable, attr, format, editorClass, defaultValue){ | ||
|
||
const editor = function(editable, attr, format, editorClass, defaultValue) { | ||
if (editable === true || typeof editable === 'string') { // simple declare | ||
const type = editable ? 'text' : editable; | ||
return ( | ||
<input { ...attr } type={ type } defaultValue={ defaultValue } | ||
className={ ( editorClass || '') + ' form-control editor edit-text' } /> | ||
); | ||
} else if (!editable) { | ||
const type = editable ? 'text' : editable; | ||
return ( | ||
<input { ...attr } type={ type } defaultValue={ defaultValue } | ||
disabled='disabled' | ||
className={ ( editorClass || '') + ' form-control editor edit-text' } /> | ||
); | ||
} else if (editable.type) {// standard declare | ||
// put style if exist | ||
editable.style && (attr.style = editable.style); | ||
// put class if exist | ||
attr.className = (editorClass || '') + | ||
' form-control editor edit-' + | ||
editable.type + | ||
(editable.className ? (' ' + editable.className) : ''); | ||
|
||
if(editable===true||typeof editable==="string"){//simple declare | ||
var type=editable===true?'text':editable; | ||
return ( | ||
<input {...attr} type={type} defaultValue={defaultValue} | ||
className={(editorClass||"")+" form-control editor edit-text"} /> | ||
) | ||
} else if(!editable){ | ||
var type=editable===true?'text':editable; | ||
if (editable.type === 'select') {// process select input | ||
let options = []; | ||
const values = editable.options.values; | ||
if (Array.isArray(values)) {// only can use arrray data for options | ||
let rowValue; | ||
options = values.map((d, i) => { | ||
rowValue = format ? format(d) : d; | ||
return ( | ||
<option key={ 'option' + i } value={ d }>{ rowValue }</option> | ||
); | ||
}); | ||
} | ||
return ( | ||
<input {...attr} type={type} defaultValue={defaultValue} disabled='disabled' | ||
className={(editorClass||"")+" form-control editor edit-text"} /> | ||
) | ||
} else if(editable.type){//standard declare | ||
//put style if exist | ||
editable.style&&(attr.style=editable.style); | ||
|
||
//put class if exist | ||
attr.className = (editorClass||"") + | ||
" form-control editor edit-" + | ||
editable.type + | ||
(editable.className?(" "+editable.className):""); | ||
|
||
if(editable.type === 'select'){//process select input | ||
var options = [], values=editable.options.values; | ||
if(Array.isArray(values)){//only can use arrray data for options | ||
var rowValue; | ||
options=values.map(function(d,i){ | ||
rowValue=format?format(d):d; | ||
return( | ||
<option key={'option'+i} value={d}>{rowValue}</option> | ||
) | ||
}); | ||
} | ||
return( | ||
<select {...attr} defaultValue={defaultValue}>{options}</select> | ||
); | ||
} else if(editable.type === 'textarea'){//process textarea input | ||
//put other if exist | ||
editable.cols&&(attr.cols=editable.cols); | ||
editable.rows&&(attr.rows=editable.rows); | ||
var keyUpHandler=attr.onKeyDown,saveBtn=null; | ||
if(keyUpHandler){ | ||
attr.onKeyDown=function(e){ | ||
if (e.keyCode != 13) { //not Pressed ENTER | ||
keyUpHandler(e); | ||
} | ||
}; | ||
saveBtn=<butto className="btn btn-info btn-xs textarea-save-btn" onClick={keyUpHandler}>save</butto> | ||
} | ||
|
||
return( | ||
<div> | ||
<textarea {...attr} defaultValue={defaultValue}></textarea> | ||
{saveBtn} | ||
</div> | ||
|
||
); | ||
} else if(editable.type === 'checkbox'){ | ||
let values = 'true:false'; | ||
if(editable.options && editable.options.values){ | ||
// values = editable.options.values.split(':'); | ||
values = editable.options.values; | ||
<select { ...attr } defaultValue={ defaultValue }> | ||
{ options } | ||
</select> | ||
); | ||
} else if (editable.type === 'textarea') {// process textarea input | ||
// put other if exist | ||
editable.cols && (attr.cols = editable.cols); | ||
editable.rows && (attr.rows = editable.rows); | ||
let saveBtn; | ||
const keyUpHandler = attr.onKeyDown; | ||
if (keyUpHandler) { | ||
attr.onKeyDown = function(e) { | ||
if (e.keyCode !== 13) { // not Pressed ENTER | ||
keyUpHandler(e); | ||
} | ||
attr.className = attr.className.replace('form-control',''); | ||
attr.className += ' checkbox pull-right'; | ||
}; | ||
saveBtn = ( | ||
<button | ||
className='btn btn-info btn-xs textarea-save-btn' | ||
onClick={ keyUpHandler }> | ||
save | ||
</button> | ||
); | ||
} | ||
return ( | ||
<div> | ||
<textarea { ...attr } defaultValue={ defaultValue }></textarea> | ||
{ saveBtn } | ||
</div> | ||
); | ||
} else if (editable.type === 'checkbox') { | ||
let values = 'true:false'; | ||
if (editable.options && editable.options.values) { | ||
// values = editable.options.values.split(':'); | ||
values = editable.options.values; | ||
} | ||
attr.className = attr.className.replace('form-control', ''); | ||
attr.className += ' checkbox pull-right'; | ||
|
||
let checked = defaultValue && defaultValue.toString() == values.split(':')[0]?true:false; | ||
const checked = defaultValue && | ||
defaultValue.toString() === values.split(':')[0] ? true : false; | ||
|
||
return ( | ||
<input {...attr} type='checkbox' value={values} defaultChecked={checked}/> | ||
); | ||
} else{//process other input type. as password,url,email... | ||
return( | ||
<input {...attr} type={type} defaultValue={defaultValue}/> | ||
) | ||
} | ||
return ( | ||
<input { ...attr } type='checkbox' | ||
value={ values } defaultChecked={ checked }/> | ||
); | ||
} else {// process other input type. as password,url,email... | ||
return ( | ||
<input { ...attr } type='text' defaultValue={ defaultValue }/> | ||
); | ||
} | ||
//default return for other case of editable | ||
return( | ||
<input {...attr} type="text" className={(editorClass||"")+" form-control editor edit-text"}/> | ||
) | ||
} | ||
// default return for other case of editable | ||
return ( | ||
<input {...attr} type='text' | ||
className={ (editorClass || '') + ' form-control editor edit-text' }/> | ||
); | ||
}; | ||
|
||
export default Editor; | ||
export default editor; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import React from 'react'; | ||
import classSet from 'classnames'; | ||
import Const from './Const'; | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
class SelectRowHeaderColumn extends React.Component{ | ||
class SelectRowHeaderColumn extends Component { | ||
|
||
render(){ | ||
return( | ||
<th style={{textAlign: 'center'}}> | ||
render() { | ||
return ( | ||
<th style={ { textAlign: 'center' } }> | ||
{ this.props.children } | ||
</th> | ||
) | ||
); | ||
} | ||
} | ||
|
||
SelectRowHeaderColumn.propTypes = { | ||
children: PropTypes.node | ||
}; | ||
export default SelectRowHeaderColumn; |
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
Oops, something went wrong.