Skip to content

Commit

Permalink
eslint on phase1
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Mar 16, 2016
1 parent fe90577 commit e5310fa
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 415 deletions.
166 changes: 88 additions & 78 deletions src/Editor.js
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;
40 changes: 19 additions & 21 deletions src/Notification.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import React from 'react';
import Const from './Const';
import React, { Component } from 'react';

import {
ToastContainer,
ToastMessage,
} from "react-toastr";
import { ToastContainer, ToastMessage } from 'react-toastr';


var ToastrMessageFactory=React.createFactory(ToastMessage.animation);
const ToastrMessageFactory = React.createFactory(ToastMessage.animation);

class Notification extends React.Component{
class Notification extends Component {
// allow type is success,info,warning,error
notice(type,msg,title){
notice(type, msg, title) {
this.refs.toastr[type](
msg,title, {
mode:'single',
timeOut: 5000,
extendedTimeOut: 1000,
showAnimation: "animated bounceIn",
hideAnimation: "animated bounceOut"
});
msg, title, {
mode: 'single',
timeOut: 5000,
extendedTimeOut: 1000,
showAnimation: 'animated bounceIn',
hideAnimation: 'animated bounceOut'
});
}

render(){
return(
<ToastContainer ref="toastr" toastMessageFactory={ToastrMessageFactory}
id="toast-container" className="toast-top-right"></ToastContainer>
)
render() {
return (
<ToastContainer ref='toastr'
toastMessageFactory={ ToastrMessageFactory }
id='toast-container'
className='toast-top-right'/>
);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/SelectRowHeaderColumn.js
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;
69 changes: 35 additions & 34 deletions src/TableColumn.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import React from 'react';
import React, { Component, PropTypes } from 'react';
import Const from './Const';

class TableColumn extends React.Component{
class TableColumn extends Component {

constructor(props) {
super(props);
}

/* eslint no-unused-vars: [0, { "args": "after-used" }] */
shouldComponentUpdate(nextProps, nextState) {
const { children } = this.props;
let shouldUpdated = this.props.width !== nextProps.width
|| this.props.className !== nextProps.className
|| this.props.hidden !== nextProps.hidden
|| this.props.dataAlign !== nextProps.dataAlign
|| typeof children !== typeof nextProps.children
|| (''+this.props.onEdit).toString() !== (''+nextProps.onEdit).toString()
|| ('' + this.props.onEdit).toString() !== ('' + nextProps.onEdit).toString();

if(shouldUpdated){
if (shouldUpdated) {
return shouldUpdated;
}

if(typeof children === 'object' && children !== null && children.props !== null) {
if(children.props.type === 'checkbox' || children.props.type === 'radio') {
if (typeof children === 'object' && children !== null && children.props !== null) {
if (children.props.type === 'checkbox' || children.props.type === 'radio') {
shouldUpdated = shouldUpdated ||
children.props.type !== nextProps.children.props.type ||
children.props.checked !== nextProps.children.props.checked;
Expand All @@ -32,62 +32,63 @@ class TableColumn extends React.Component{
shouldUpdated = shouldUpdated || children !== nextProps.children;
}

if(shouldUpdated){
if (shouldUpdated) {
return shouldUpdated;
}

if(!(this.props.cellEdit && nextProps.cellEdit)) {
if (!(this.props.cellEdit && nextProps.cellEdit)) {
return false;
} else {
return shouldUpdated
|| this.props.cellEdit.mode !== nextProps.cellEdit.mode;
}
}

handleCellEdit(e){
if(this.props.cellEdit.mode == Const.CELL_EDIT_DBCLICK){
if(document.selection && document.selection.empty) {
handleCellEdit = e => {
if (this.props.cellEdit.mode === Const.CELL_EDIT_DBCLICK) {
if (document.selection && document.selection.empty) {
document.selection.empty();
} else if(window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
} else if (window.getSelection) {
const sel = window.getSelection();
sel.removeAllRanges();
}
}
this.props.onEdit(
e.currentTarget.parentElement.rowIndex+1,
e.currentTarget.parentElement.rowIndex + 1,
e.currentTarget.cellIndex);
}

render(){
var tdStyle = {
render() {
const tdStyle = {
textAlign: this.props.dataAlign,
display: this.props.hidden?"none":null
display: this.props.hidden ? 'none' : null
};

var opts = {};
if(this.props.cellEdit){
if(this.props.cellEdit.mode == Const.CELL_EDIT_CLICK){
opts.onClick = this.handleCellEdit.bind(this);
}else if(this.props.cellEdit.mode == Const.CELL_EDIT_DBCLICK){
opts.onDoubleClick = this.handleCellEdit.bind(this);
const opts = {};
if (this.props.cellEdit) {
if (this.props.cellEdit.mode === Const.CELL_EDIT_CLICK) {
opts.onClick = this.handleCellEdit;
} else if (this.props.cellEdit.mode === Const.CELL_EDIT_DBCLICK) {
opts.onDoubleClick = this.handleCellEdit;
}
}
return (
<td style={tdStyle} className={this.props.className} {...opts}>
{this.props.children}
<td style={ tdStyle } className={ this.props.className } { ...opts }>
{ this.props.children }
</td>
)
);
}
}
TableColumn.propTypes = {
dataAlign: React.PropTypes.string,
hidden: React.PropTypes.bool,
className:React.PropTypes.string
dataAlign: PropTypes.string,
hidden: PropTypes.bool,
className: PropTypes.string,
children: PropTypes.node
};

TableColumn.defaultProps = {
dataAlign: "left",
dataAlign: 'left',
hidden: false,
className:""
}
className: ''
};
export default TableColumn;
Loading

0 comments on commit e5310fa

Please sign in to comment.