Add changing of state
By clicking on a story's state you change that story's state to the next possible state.
This commit is contained in:
parent
53dfb99f6b
commit
e529f38b59
2 changed files with 34 additions and 5 deletions
23
js/main.js
23
js/main.js
|
@ -25,7 +25,7 @@ var StoryRow = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
// A little ugly to get a space, but I don't know of any other
|
// A little ugly to get a space, but I don't know of any other
|
||||||
// way.
|
// way.
|
||||||
var state = " " + this.props.story.state;
|
var state = " " + this.state.state;
|
||||||
var sdata = null;
|
var sdata = null;
|
||||||
|
|
||||||
if (this.state.content)
|
if (this.state.content)
|
||||||
|
@ -34,11 +34,13 @@ var StoryRow = React.createClass({
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<StateIcon state={this.props.story.state} />
|
<span onClick={this.changeState}>
|
||||||
|
<StateIcon state={this.state.state} />
|
||||||
{state}
|
{state}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a id={this.props.story.id} onClick={this.handleClick}>
|
<a onClick={this.handleClick}>
|
||||||
As a {this.props.story.role}, I
|
As a {this.props.story.role}, I
|
||||||
{this.props.story.necessity} to
|
{this.props.story.necessity} to
|
||||||
{this.props.story.title}
|
{this.props.story.title}
|
||||||
|
@ -50,7 +52,8 @@ var StoryRow = React.createClass({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {content: null};
|
return {state: this.props.story.state,
|
||||||
|
content: null};
|
||||||
},
|
},
|
||||||
handleClick: React.autoBind(function(event) {
|
handleClick: React.autoBind(function(event) {
|
||||||
if (!!this.state.content) {
|
if (!!this.state.content) {
|
||||||
|
@ -63,6 +66,18 @@ var StoryRow = React.createClass({
|
||||||
function (data, textStatus, jqXHR) {
|
function (data, textStatus, jqXHR) {
|
||||||
self.setState({content: data});
|
self.setState({content: data});
|
||||||
}, 'json');
|
}, 'json');
|
||||||
|
}),
|
||||||
|
changeState: React.autoBind(function(event) {
|
||||||
|
$.ajax({
|
||||||
|
url: "/stories/state/",
|
||||||
|
type: "POST",
|
||||||
|
data: {'id': this.props.story.id},
|
||||||
|
dataType: 'json',
|
||||||
|
mimeType: 'textPlain',
|
||||||
|
success: function(data) {
|
||||||
|
this.setState({state: eval(data).state});
|
||||||
|
}.bind(this)
|
||||||
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
14
scrumelo.el
14
scrumelo.el
|
@ -115,6 +115,19 @@
|
||||||
(save-buffer)))
|
(save-buffer)))
|
||||||
(elnode-send-redirect httpcon "/"))))
|
(elnode-send-redirect httpcon "/"))))
|
||||||
|
|
||||||
|
(defun scrumelo-change-state (httpcon)
|
||||||
|
"Parse data from HTTPCON and change the given task's state."
|
||||||
|
(elnode-method httpcon
|
||||||
|
(POST
|
||||||
|
(with-scrumelo-http-params (id) httpcon
|
||||||
|
(message "HI: %s" id)
|
||||||
|
(with-scrumelo-buffer
|
||||||
|
(let ((entry (cdr (org-id-find id))))
|
||||||
|
(goto-char entry)
|
||||||
|
(org-todo)
|
||||||
|
(scrumelo--send-json
|
||||||
|
httpcon (list (cons :state (org-entry-get (point) "TODO"))))))))))
|
||||||
|
|
||||||
(defun scrumelo--send-json (httpcon obj)
|
(defun scrumelo--send-json (httpcon obj)
|
||||||
"Respond to HTTPCON with OBJ converted to a json structure."
|
"Respond to HTTPCON with OBJ converted to a json structure."
|
||||||
(elnode-http-start httpcon 200 '("Content-Type" . "text/json"))
|
(elnode-http-start httpcon 200 '("Content-Type" . "text/json"))
|
||||||
|
@ -161,6 +174,7 @@
|
||||||
(concat scrumelo--base-dir "js/main.js")))
|
(concat scrumelo--base-dir "js/main.js")))
|
||||||
("^/stories/$" . scrumelo-main-json)
|
("^/stories/$" . scrumelo-main-json)
|
||||||
("^/stories/new/$" . scrumelo-new-story)
|
("^/stories/new/$" . scrumelo-new-story)
|
||||||
|
("^/stories/state/$" . scrumelo-change-state)
|
||||||
("^/stories/\\([a-z0-9:-]+\\)/$" . scrumelo-story-json))))
|
("^/stories/\\([a-z0-9:-]+\\)/$" . scrumelo-story-json))))
|
||||||
|
|
||||||
(elnode-start 'scrumelo-handler :port 8028 :host "0.0.0.0")
|
(elnode-start 'scrumelo-handler :port 8028 :host "0.0.0.0")
|
||||||
|
|
Loading…
Reference in a new issue