mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 10:44:08 +01:00
issue ajax edit
This commit is contained in:
parent
bf2e76fc7e
commit
f0d5c3992b
2 changed files with 56 additions and 8 deletions
|
@ -56,6 +56,43 @@ var Gogits = {
|
|||
},
|
||||
toggleShow: function () {
|
||||
$(this).removeClass("hidden");
|
||||
},
|
||||
toggleAjax: function (successCallback) {
|
||||
var url = $(this).data("ajax");
|
||||
var method = $(this).data('ajax-method') || 'get';
|
||||
var ajaxName = $(this).data('ajax-name');
|
||||
var data = {};
|
||||
$('[data-ajax-rel=' + ajaxName + ']').each(function () {
|
||||
var field = $(this).data("ajax-field");
|
||||
var t = $(this).data("ajax-val");
|
||||
if (t == "val") {
|
||||
data[field] = $(this).val();
|
||||
return true;
|
||||
}
|
||||
if (t == "txt") {
|
||||
data[field] = $(this).text();
|
||||
return true;
|
||||
}
|
||||
if (t == "html") {
|
||||
data[field] = $(this).html();
|
||||
return true;
|
||||
}
|
||||
if (t == "data") {
|
||||
data[field] = $(this).data("ajax-data");
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: method.toUpperCase(),
|
||||
data: data,
|
||||
success: function (d) {
|
||||
if (successCallback) {
|
||||
successCallback(d);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}(jQuery));
|
||||
|
@ -386,11 +423,11 @@ function initIssue() {
|
|||
var $openBtn = $('#issue-open-btn');
|
||||
$('#issue-reply-content').on("keyup", function () {
|
||||
if ($(this).val().length) {
|
||||
$closeBtn.text($closeBtn.data("text"));
|
||||
$openBtn.text($openBtn.data("text"));
|
||||
$closeBtn.val($closeBtn.data("text"));
|
||||
$openBtn.val($openBtn.data("text"));
|
||||
} else {
|
||||
$closeBtn.text($closeBtn.data("origin"));
|
||||
$openBtn.text($openBtn.data("origin"));
|
||||
$closeBtn.val($closeBtn.data("origin"));
|
||||
$openBtn.val($openBtn.data("origin"));
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
@ -406,6 +443,16 @@ function initIssue() {
|
|||
$('#issue-edit-title,#issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleHide();
|
||||
})
|
||||
}());
|
||||
|
||||
// issue ajax update
|
||||
$('.issue-edit-save').on("click", function () {
|
||||
$(this).toggleAjax(function(json){
|
||||
if(json.ok){
|
||||
$('.issue-head h1.title').text(json.title);
|
||||
$('.issue-main > .issue-content .content').html(json.content);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
(function ($) {
|
||||
|
|
|
@ -9,11 +9,12 @@
|
|||
<div class="number pull-right">#{{.Issue.Index}}</div>
|
||||
<a class="author pull-left" href="/user/{{.Issue.Poster.Name}}"><img class="avatar" src="{{.Issue.Poster.AvatarLink}}" alt="" width="30"/></a>
|
||||
<h1 class="title pull-left">{{.Issue.Name}}</h1>
|
||||
<input id="issue-edit-title" class="form-control input-lg pull-left hidden" type="text" value="{issue.title}" data-ajax-rel="issue-save"/>
|
||||
<input id="issue-edit-title" class="form-control input-lg pull-left hidden" type="text" value="{issue.title}" data-ajax-rel="issue-edit-save" data-ajax-val="val" data-ajax-field="title"/>
|
||||
<input type="hidden" value="{issue.id}" data-ajax-rel="issue-edit-save" data-ajax-val="val" data-ajax-field="issue_id"/>
|
||||
<p class="info pull-left">
|
||||
<!-- <a class="btn btn-default pull-right issue-edit" href="#" id="issue-edit-btn">Edit</a> -->
|
||||
<a class="btn btn-default pull-right issue-edit" href="#" id="issue-edit-btn">Edit</a>
|
||||
<a class="btn btn-danger pull-right issue-edit-cancel hidden" href="#">Cancel</a>
|
||||
<a class="btn btn-primary pull-right issue-edit-save hidden" href="#" data-ajax="{issue.save.link}" data-ajax-name="issue-save">Save</a>
|
||||
<a class="btn btn-primary pull-right issue-edit-save hidden" href="#" data-ajax="{issue.edit.save.link}" data-ajax-name="issue-edit-save" data-ajax-method="post">Save</a>
|
||||
<span class="status label label-{{if .Issue.IsClosed}}danger{{else}}success{{end}}">{{if .Issue.IsClosed}}Closed{{else}}Open{{end}}</span>
|
||||
<a href="/user/{{.Issue.Poster.Name}}" class="author"><strong>{{.Issue.Poster.Name}}</strong></a> opened this issue
|
||||
<span class="time">{{TimeSince .Issue.Created}}</span> · {{.Issue.NumComments}} comments
|
||||
|
@ -25,7 +26,7 @@
|
|||
<div class="content">
|
||||
{{str2html .Issue.Content}}
|
||||
</div>
|
||||
<textarea class="form-control hidden" name="content" id="issue-edit-content" rows="10" data-ajax-rel="issue-save">content</textarea>
|
||||
<textarea class="form-control hidden" name="content" id="issue-edit-content" rows="10" data-ajax-rel="issue-edit-save" data-ajax-val="val" data-ajax-field="content">{issue.content}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
{{range .Comments}}
|
||||
|
|
Loading…
Reference in a new issue