Skip to content

Commit 23bc837

Browse files
committed
Sell/View edit.js
1 parent 9ad0d7a commit 23bc837

25 files changed

+1168
-106
lines changed

Uris.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ module.exports = Uris = {
3535
BASE: '/field/index/:tab',
3636
},
3737
INVENTORY: {
38-
CREATE: '/inventory/create',
3938
VIEW: '/inventory/view/:id',
40-
EDIT: '/inventory/edit/:id',
4139
BASE: '/inventory/index',
4240
},
4341
toAbsoluteUri: toAbsoluteUri

inventory/Create.js

Whitespace-only changes.

inventory/Edit.js

Whitespace-only changes.

inventory/InventoryAutoComplete.js

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
var React = require('react');
2+
var lib = require('../components/functions');
3+
var Autosuggest = require('react-autosuggest');
4+
5+
class InventoryAutoComplete extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
9+
this.state = {
10+
suggestions: [],
11+
isLoading: false
12+
};
13+
14+
this.onChange = this.onChange.bind(this);
15+
this.onSuggestionsUpdateRequested = this.onSuggestionsUpdateRequested.bind(this);
16+
}
17+
18+
loadSuggestions(value) {
19+
this.setState({
20+
isLoading: true
21+
});
22+
23+
// Fake an AJAX call
24+
setTimeout(() => {
25+
const suggestions = getMatchingLanguages(value);
26+
27+
if (value === this.props.value) {
28+
this.setState({
29+
isLoading: false,
30+
suggestions
31+
});
32+
} else { // Ignore suggestions if input value changed
33+
this.setState({
34+
isLoading: false
35+
});
36+
}
37+
}, randomDelay());
38+
}
39+
40+
onChange(event, { newValue }) {
41+
var e = {target: {}};
42+
e.target.name = this.props.name;
43+
e.target.value = newValue;
44+
if (!!this.props.onChange) this.props.onChange(e);
45+
}
46+
47+
onSuggestionsUpdateRequested({ value }) {
48+
this.loadSuggestions(value);
49+
}
50+
51+
render() {
52+
const { suggestions, isLoading } = this.state;
53+
54+
const value = this.props.value || "";
55+
56+
const inputProps = {
57+
id: this.props.id || '',
58+
placeholder: this.props.placeholder || '',
59+
name: this.props.name || '',
60+
value: value,
61+
onChange: this.onChange
62+
};
63+
const status = (isLoading ? <span className="text-info">Searching...</span>
64+
: (!suggestions.length && !!value) ? <span className="text-success">Not Found</span> : '');
65+
66+
return (
67+
<div className="row">
68+
<div className="col-md-10">
69+
70+
<Autosuggest suggestions={suggestions}
71+
onSuggestionsUpdateRequested={this.onSuggestionsUpdateRequested}
72+
getSuggestionValue={getSuggestionValue}
73+
renderSuggestion={renderSuggestion}
74+
inputProps={inputProps}/>
75+
76+
</div>
77+
78+
<div className="col-md-2">
79+
{status}
80+
</div>
81+
</div>
82+
);
83+
}
84+
}
85+
86+
InventoryAutoComplete.defaultProps = {
87+
placeholder: 'Type inventory name',
88+
name: '',
89+
value: '',
90+
onChange: function () {
91+
}
92+
};
93+
94+
function getSuggestionValue(inventory) {
95+
return inventory.name;
96+
}
97+
98+
function renderSuggestion(inventory) {
99+
return (
100+
<span>{inventory.name}</span>
101+
);
102+
}
103+
104+
function getMatchingLanguages(value) {
105+
const escapedValue = lib.escapeRegexCharacters(value.trim());
106+
107+
if (escapedValue === '') {
108+
return [];
109+
}
110+
111+
const regex = new RegExp('^' + escapedValue, 'i');
112+
113+
return languages.filter(language => regex.test(language.name));
114+
}
115+
116+
function randomDelay() {
117+
return 300 + Math.random() * 1000;
118+
}
119+
120+
const languages = [
121+
{
122+
name: 'C',
123+
year: 1972
124+
},
125+
{
126+
name: 'C#',
127+
year: 2000
128+
},
129+
{
130+
name: 'C++',
131+
year: 1983
132+
},
133+
{
134+
name: 'Clojure',
135+
year: 2007
136+
},
137+
{
138+
name: 'Elm',
139+
year: 2012
140+
},
141+
{
142+
name: 'Go',
143+
year: 2009
144+
},
145+
{
146+
name: 'Haskell',
147+
year: 1990
148+
},
149+
{
150+
name: 'Java',
151+
year: 1995
152+
},
153+
{
154+
name: 'Javascript',
155+
year: 1995
156+
},
157+
{
158+
name: 'Perl',
159+
year: 1987
160+
},
161+
{
162+
name: 'PHP',
163+
year: 1995
164+
},
165+
{
166+
name: 'Python',
167+
year: 1991
168+
},
169+
{
170+
name: 'Ruby',
171+
year: 1995
172+
},
173+
{
174+
name: 'Scala',
175+
year: 2003
176+
}
177+
];
178+
179+
module.exports = InventoryAutoComplete;

inventory/InventorySummary.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var React = require('react');
2+
var QuantityInUnitView = require('../utils/QuantityInUnitView');
3+
4+
var InventorySummary = React.createClass({
5+
getDefaultProps: function () {
6+
return {
7+
summary: []
8+
};
9+
},
10+
render: function () {
11+
var $this = this;
12+
var summary = $this.props.summary || [];
13+
14+
return (
15+
<table className="table table-striped">
16+
17+
<thead>
18+
<tr>
19+
<th>#</th>
20+
<th>Product</th>
21+
<th>Quantity</th>
22+
<th>Added</th>
23+
<th>Removed</th>
24+
</tr>
25+
</thead>
26+
27+
<tbody>
28+
29+
{
30+
summary.map(function (sm, index) {
31+
return (
32+
<tr key={(index + 1) + '.'}>
33+
<td>{index + 1}</td>
34+
<td>{sm.product}</td>
35+
<td>{$this.formatQuantity(sm.quantity)}</td>
36+
<td>{$this.formatQuantity(sm.added)}</td>
37+
<td>{$this.formatQuantity(sm.removed)}</td>
38+
</tr>
39+
);
40+
})
41+
}
42+
43+
</tbody>
44+
45+
</table>
46+
);
47+
},
48+
formatQuantity: function (quantity) {
49+
return (
50+
<QuantityInUnitView quantity={quantity.amount} unit={quantity.unit.name}/>
51+
);
52+
}
53+
});
54+
55+
module.exports = InventorySummary;

inventory/List.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
"use strict";
2+
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';
3+
var React = require('react');
4+
5+
var NewInventoryDialog = require('./NewInventoryDialog');
6+
7+
var ListInventories;
8+
module.exports = ListInventories = React.createClass({
9+
getDefaultProps: function () {
10+
return {};
11+
},
12+
getInitialState: function () {
13+
return {
14+
inventories: [
15+
{id: '1', name: 's', remarks: 'rr', totalProducts: 12},
16+
{id: '2', name: 's', remarks: 'rr', totalProducts: 14},
17+
{id: '3', name: 's', remarks: 'rr', totalProducts: 75},
18+
{id: '4', name: 's', remarks: 'rr', totalProducts: 147},
19+
]
20+
};
21+
},
22+
render: function () {
23+
var $this = this;
24+
var inventories = $this.state.inventories || [];
25+
26+
return (
27+
28+
<div className="row">
29+
<div className="col-md-12">
30+
31+
<div className="panel panel-default">
32+
33+
<div className="panel-heading">
34+
35+
<div className="row">
36+
<div className="col-md-8">
37+
<h3 className="panel-title">Inventory List [ total: {inventories.length} ]</h3>
38+
</div>
39+
<div className="col-md-4">
40+
<span className="btn btn-primary pull-right"
41+
onClick={$this.createNewInventory}>New</span>
42+
</div>
43+
</div>
44+
45+
</div>
46+
47+
<BootstrapTable data={inventories} cellEdit={$this.cellEditProp()}>
48+
<TableHeaderColumn dataField="id" isKey={true}>ID</TableHeaderColumn>
49+
<TableHeaderColumn dataField="name">Name</TableHeaderColumn>
50+
<TableHeaderColumn dataField="totalProducts" editable={false}>
51+
Total Products</TableHeaderColumn>
52+
<TableHeaderColumn dataField="remarks">Remarks</TableHeaderColumn>
53+
<TableHeaderColumn dataField="action" editable={false}
54+
dataFormat={$this.formatAction}>Action</TableHeaderColumn>
55+
</BootstrapTable>
56+
57+
</div>
58+
59+
<NewInventoryDialog onInit={$this.onNewInventoryDialogInit}/>
60+
61+
</div>
62+
</div>
63+
);
64+
},
65+
onNewInventoryDialogInit: function (ref) {
66+
this.newInventoryDialog = ref;
67+
},
68+
createNewInventory: function () {
69+
var $this = this;
70+
$this.newInventoryDialog.createNewInventory();
71+
},
72+
formatAction: function (ac, inventory) {
73+
var $this = this;
74+
return (
75+
<div>
76+
77+
<span className="btn btn-primary" style={{marginRight: '5px'}} title="Add product to this inventory."
78+
onClick={function () {
79+
$this.addRemoveProducts(inventory);
80+
}}>
81+
Add/Remove Products
82+
</span>
83+
84+
<a className="btn btn-success" style={{marginRight: '5px'}} title="View this inventory.">
85+
View
86+
</a>
87+
88+
<span className="btn btn-danger" title="Delete this inventory."
89+
onClick={function () {
90+
$this.deleteInventory(inventory);
91+
}}>
92+
<span className="glyphicon glyphicon-remove" aria-hidden="true"></span>
93+
</span>
94+
95+
</div>
96+
);
97+
},
98+
addRemoveProducts: function (inventory) {
99+
},
100+
deleteInventory: function (inventory) {
101+
var $this = this;
102+
$this.setState({
103+
inventories: $this.state.inventories.filter(function (u) {
104+
return u != inventory;
105+
})
106+
});
107+
},
108+
cellEditProp: function () {
109+
var $this = this;
110+
return {
111+
mode: "dbclick",
112+
blurToSave: true,
113+
afterSaveCell: $this.onAfterSaveCell
114+
};
115+
},
116+
onAfterSaveCell: function (row, cellName, cellValue) {
117+
var $this = this;
118+
}
119+
});

0 commit comments

Comments
 (0)