2016-02-12 23:52:43 +08:00
|
|
|
// New result asset behaviour
|
|
|
|
$("#new-result-asset").on("ajax:success", function(e, data) {
|
2016-07-21 19:11:15 +08:00
|
|
|
var $form = $(data.html);
|
|
|
|
$("#results").prepend($form);
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
formAjaxResultAsset($form);
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
// Cancel button
|
|
|
|
$form.find(".cancel-new").click(function () {
|
|
|
|
$form.remove();
|
|
|
|
toggleResultEditButtons(true);
|
|
|
|
});
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
toggleResultEditButtons(false);
|
|
|
|
|
|
|
|
$("#result_name").focus();
|
2016-02-12 23:52:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#new-result-asset").on("ajax:error", function(e, xhr, status, error) {
|
2016-08-05 23:00:29 +08:00
|
|
|
// TODO
|
2016-02-12 23:52:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Edit result asset button behaviour
|
|
|
|
function applyEditResultAssetCallback() {
|
2016-07-21 19:11:15 +08:00
|
|
|
$(".edit-result-asset").on("ajax:success", function(e, data) {
|
|
|
|
var $result = $(this).closest(".result");
|
|
|
|
var $form = $(data.html);
|
|
|
|
var $prevResult = $result;
|
|
|
|
$result.after($form);
|
|
|
|
$result.remove();
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
formAjaxResultAsset($form);
|
|
|
|
|
|
|
|
// Cancel button
|
|
|
|
$form.find(".cancel-edit").click(function () {
|
|
|
|
$form.after($prevResult);
|
|
|
|
$form.remove();
|
|
|
|
applyEditResultAssetCallback();
|
|
|
|
toggleResultEditButtons(true);
|
2016-02-12 23:52:43 +08:00
|
|
|
});
|
2016-07-21 19:11:15 +08:00
|
|
|
|
|
|
|
toggleResultEditButtons(false);
|
|
|
|
|
|
|
|
$("#result_name").focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".edit-result-asset").on("ajax:error", function(e, xhr, status, error) {
|
2016-08-05 23:00:29 +08:00
|
|
|
// TODO
|
2016-07-21 19:11:15 +08:00
|
|
|
});
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply ajax callback to form
|
|
|
|
function formAjaxResultAsset($form) {
|
2016-07-21 19:11:15 +08:00
|
|
|
$form
|
|
|
|
.on("ajax:success", function(e, data) {
|
2016-08-05 23:00:29 +08:00
|
|
|
$form.after(data.html);
|
2016-08-17 15:44:53 +08:00
|
|
|
var $newResult = $form.next();
|
|
|
|
initFormSubmitLinks($newResult);
|
2016-08-05 23:00:29 +08:00
|
|
|
$(this).remove();
|
|
|
|
applyEditResultAssetCallback();
|
|
|
|
applyCollapseLinkCallBack();
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2016-08-05 23:00:29 +08:00
|
|
|
toggleResultEditButtons(true);
|
|
|
|
initResultCommentTabAjax();
|
2016-08-17 15:44:53 +08:00
|
|
|
expandResult($newResult);
|
|
|
|
$imgs = $newResult.find("img");
|
|
|
|
reloadImages($imgs);
|
2016-07-21 19:11:15 +08:00
|
|
|
})
|
2016-08-05 23:00:29 +08:00
|
|
|
.on("ajax:error", function(e, data) {
|
2016-10-03 19:43:35 +08:00
|
|
|
// This check is here only because of remotipart bug, which returns
|
|
|
|
// HTML instead of JSON, go figure
|
|
|
|
var errors = '';
|
|
|
|
if (data.errors)
|
|
|
|
errors = data.errors;
|
|
|
|
else
|
|
|
|
errors = data.responseJSON.errors;
|
|
|
|
$form.renderFormErrors("result", errors, true, e);
|
2016-07-21 19:11:15 +08:00
|
|
|
});
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
applyEditResultAssetCallback();
|