Forum Discussion
Hi VikasB, sure thing.
The JS code for getting and posting the data:
<@liaAddScript> ;(function($) { $(document).ready(function() { // hide the validation message $('.lia-form-validation-help-text').hide(); $(document).on('click', '.lia-button-Cancel-action', function() { window.history.back(); }); // process everything when the submit button is clicked $(document).on('click','.lia-button-Submit-action',function() { // postid is in querystring of URL so get it with this function var postid = getUrlParameter('postid'), error = true, reasontext = $('#lia-additionalInformation').val(); if(reasontext.length) { error = false; }; if(error === false) { $.get('/aptgm87544/plugins/custom/plusnetplc/plusnetplc/superuserescalation', {post:postid}, function(data,status){ }).done(function(data){ // get everything from the data object endpoint var messageviewhref = $(data).find('messageviewhref').text(), messagesubject = $(data).find('messagesubject').text(), messagebody = $(data).find('messagebody').html(), messageauthor = $(data).find('messageauthor').text(), messageauthorid = $(data).find('messageauthorid').text(), messageboard = $(data).find('messageboard').text(), escalatesubject = '[ESCALATED] By: '+ messageauthor +' / Board: '+ messageboard, escalatebodypre = reasontext + '<p><br>Link to post: <a href="'+ messageviewhref +'">('+ messagesubject +')</a><br>by <li-user uid="'+ messageauthorid +'" login="'+ messageauthor +'"></li-user></p><p><br><a href="'+ messageviewhref +'">'+ messageviewhref +'</a></p><br>', escalatebody = messagebody, successMessage = '<div class="InfoMessage lia-panel-feedback-inline-note"><div class="lia-text"><p ng-non-bindable="" tabindex="0" role="informational">Success! This post has now been escalated</p><p><a href="'+ messageviewhref +'">Return to the post.</a></p></div></div>'; // pump the above variables into the endpoint so it can post $.get('/aptgm87544/plugins/custom/plusnetplc/plusnetplc/superuserescalationencode', {escalatebody:escalatebody,escalatesubject:escalatesubject,escalatebodypre:escalatebodypre}, function(postdata,status){ // When finished, remove the form and display successMessage }).done(function(){ $('.escalationform').remove(); $('.escalationform--feedback').append(successMessage); }) }); } else { $('.lia-form-validation-help-text').show(); }; }); function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; }); })(jQuery); </@liaAddScript>
Endpoint for get method (superuserescalation.ftl):
<#compress> <#assign messageId = http.request.parameters.name.get("post","")?html?js_string /> <#if messageId?length gt 0> <#attempt> <#assign message = rest("/messages/id/${messageId}").message /> <#assign author = rest(message.author.@href).user /> <#assign board = rest(message.board.@href).board /> <response> <status>success</status> <messageviewhref>${message.@view_href}</messageviewhref> <messagesubject>${message.subject}</messagesubject> <messagebody>${message.body}</messagebody> <messageauthor>${author.login}</messageauthor> <messageauthorid>${author.id}</messageauthorid> <messageboard>${board.title}</messageboard> </response> <#recover> Error retrieving message id ${messageId}. </#attempt> <#else> Missing required parameter "id". </#if> </#compress>
Endpoint for the post method (superuserescalationencode.ftl):
<#assign escalatesubject = http.request.parameters.name.get("escalatesubject","")> <#assign escalatebodypre = http.request.parameters.name.get("escalatebodypre","")> <#assign escalatebody = http.request.parameters.name.get("escalatebody","")> <#assign addPost = rest("/boards/id/Superuser-escalations/messages/post?message.subject=${escalatesubject?url}&message.body=${escalatebodypre?url}${escalatebody?html?url}") /> ${addPost}
(with the above I tried adding the /> to the assigns but that was not the issue)
The form as a custom component added to a custom page (I have stripped this down to the bare bones as there are a lot of wrapper divs):
<div class="escalationform--feedback"></div> <div class="escalationform lia-form-vertical"> <textarea id="lia-additionalInformation"></textarea> <div class="lia-form-validation-help-text">Tell us why you believe this content should be escalated.</div> <div class="lia-form-footer"> <button class="lia-button lia-button-primary lia-button-Submit-action">Submit</button> <button class="lia-button lia-button-primary lia-button-Cancel-action">Cancel</button> </div> </div>
HI jaread83
It works perfectly except one thing that endpoint superuserescalationcode trying to return ${addPost} which is not feasible. Either you have to create a custom response as you created in superuserescalation endpoint or you have to return ${addPost.message.root} or you can remove this freemarker variable.
I think you are trying to return the status of addPost call???
If yes, you can use ajax call with error/success methods to call the endpoint as below.
$.ajax({ url: '/aptgm87544/plugins/custom/plusnetplc/plusnetplc/superuserescalationencode', error: function(error) { console.log('error in call', error.responseText) }, success: function(responseText) { console.log(responseText) }, type: 'GET',
data: {subject: messagesubject,body: messagebody} });
Hope it would resolve it.
Related Content
- 2 years ago
- 12 months ago
- 3 years ago