<input type="submit" class="button" name="LoadDraft" value="<&|/l&>Load draft</&>" />
% }
<input type="submit" class="button" name="SaveDraft" value="<% ($Draft && $Draft->id) ? loc('Update draft') : loc('Save draft')%>" />
+
+<script type="text/javascript">
+jQuery(function() {
+ timeout_save_draft = window.setTimeout(save_draft, <% RT->Config->Get('AutoSaveDraftPeriod', $session{'CurrentUser'}) || 300 %> * 1000);
+});
+
+function save_draft() {
+ jQuery.post("/Helpers/SaveDraft", {UserId: "<% $session{'CurrentUser'}->id %>", TicketId: "<% $Ticket->id %>", Content: jQuery('#UpdateContent').val(), ContentType: jQuery('#UpdateContent').hasClass('richtext') ? 'text/html' : 'text/plain'},
+ function(res) {
+ console.log(res);
+ }
+ );
+ timeout_save_draft = window.setTimeout(save_draft, <% RT->Config->Get('AutoSaveDraftPeriod', $session{'CurrentUser'}) || 300 %> * 1000);
+}
+</script>
<%init>
my $Ticket = LoadTicket($ARGS{'id'});
--- /dev/null
+<%ARGS>
+$UserId => undef;
+$TicketId => undef;
+$Content => undef;
+$ContentType => undef;
+</%ARGS>
+
+<%INIT>
+my $Ticket = LoadTicket($TicketId);
+my $Draft = RT::Attribute->new($session{'CurrentUser'});
+$Draft->LoadByNameAndObject(Object => $session{'CurrentUser'}->UserObj, Name => 'Draft-' . $Ticket->id);
+my ($ok, $msg) = (0, '');
+if ($Content) {
+ if ($Draft && $Draft->Id) {
+ ($ok, $msg) = $Draft->SetContent($Content);
+ $Draft->SetContentType($ContentType);
+ } else {
+ ($ok, $msg) = $Draft->Create(Name => 'Draft-' . $Ticket->id,
+ Object => $session{'CurrentUser'}->UserObj,
+ Content => $Content,
+ ContentType => $ContentType,
+ );
+ }
+}
+$m->out($msg);
+$m->abort;
+</%INIT>
=cut
+# User overridable options
+$RT::Config::META{AutoSaveDraftPeriod} = {
+ Section => 'Ticket composition',
+ Overridable => 1,
+ SortOrder => 20,
+ Widget => '/Widgets/Form/Integer',
+ WidgetArguments => {
+ Description => 'Period (in seconds) to automatically save a response/comment draft'
+ },
+};
+
1; # End of RT::Extension::Drafts