Last active
December 12, 2015 00:38
-
-
Save JogoShugh/4685074 to your computer and use it in GitHub Desktop.
Understand the How the Barebones User Story Editor Works
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
$(function () { | |
var storyId = ''; | |
$("#storyGet").click(function (e) { | |
storyId = $('#StoryId').val(); | |
if (storyId == '') { | |
return; | |
} | |
var storyUrl = url + storyId + select | |
$.ajax({ | |
url: storyUrl, | |
type: 'GET', | |
dataType: 'json', | |
headers: headers | |
}).done(function (data) { | |
bindDtoToForm(data); | |
$("#editor").show(); | |
}).fail(function (jqXHR) { | |
alert('Error during get. See console for details.'); | |
console.log('Error:'); | |
console.log(jqXHR.responseText); | |
}); | |
}); | |
// ... etc |
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
var url = "http://eval.versionone.net/platformtest/rest-1.v1/Data/Story/"; | |
var select = "?sel=Name,Description,Estimate" | |
var headers = { Authorization: "Basic " + btoa("admin:admin"), Accept: 'haljson' }; |
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
$.ajax({ | |
url: url, | |
type: 'GET', | |
dataType: 'json', | |
headers: headers | |
}).done(function (data) { | |
bindDtoToForm(data); | |
$("#editor").show(); | |
}).fail(function (jqXHR) { | |
alert('Error during get. See console for details.'); | |
console.log('Error:'); | |
console.log(jqXHR.responseText); | |
}); |
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
function bindDtoToForm(data) { | |
for (var key in data) { | |
$("#" + key).val(data[key]); | |
} | |
} |
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
{ | |
"Name": "Tutorial Story", | |
"Description": "Sample tutorial story", | |
"Estimate": "5" | |
} |
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
function bindDtoToForm(data) { | |
$('#Name').val(data.Name); // or data['Name'], as these are equivalent | |
$('#Description').val(data.Description); | |
$('#Estimate').val(data.Estimate); | |
} |
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
$("#save").click(function() { | |
var storyDto = createDtoFromForm("#editorForm input, #editorForm textarea"); | |
$.ajax({ | |
url: url + storyId, | |
type: "POST", | |
data: JSON.stringify(storyDto), | |
dataType: "json", | |
contentType: "haljson", | |
headers: headers | |
}).done(function(data) { | |
$("#message").text("Save successful! You can load it in VersionOne and see the results of your labor."); | |
console.log(data); | |
}).fail(function(jqXHR) { | |
alert("Error during save. See console for message."); | |
console.log("Error on save:"); | |
console.log(jqXHR.responseText); | |
}); | |
}); |
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
function createDtoFromForm(selector) { | |
var dto = {}; | |
$(selector).each(function () { | |
var item = $(this); | |
var id = item.attr('id'); | |
dto[id] = item.val(); | |
}); | |
return dto; | |
} |
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
$(function () { | |
var storyId = ''; | |
$("#storyGet").click(function (e) { | |
storyId = $('#StoryId').val(); | |
if (storyId == '') { | |
return; | |
} | |
var storyUrl = url + storyId + select | |
$.ajax({ | |
url: storyUrl, | |
type: 'GET', | |
dataType: 'json', | |
headers: headers | |
}).done(function (data) { | |
bindDtoToForm(data); | |
$("#editor").show(); | |
}).fail(function (jqXHR) { | |
alert('Error during get. See console for details.'); | |
console.log('Error:'); | |
console.log(jqXHR.responseText); | |
}); | |
}); | |
// ... etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment