Skip to content

Instantly share code, notes, and snippets.

@DeskWOW
Last active August 29, 2015 14:01
Show Gist options
  • Save DeskWOW/05962361fc16b70f9bd2 to your computer and use it in GitHub Desktop.
Save DeskWOW/05962361fc16b70f9bd2 to your computer and use it in GitHub Desktop.
This Desk.com custom email widget theme adds an example custom field and article suggest functionality. To input this code into your widget, login to your Desk.com Admin panel and go to Channels -> Email -> Widgets. Be sure to update the "ajax" part of the JavaScript code to point to your Desk.com subdomain (instead of YOUR-SITE).
<title>{{ site.company_name }}</title>
<link rel="icon" type="image/vnd.microsoft.icon" href='{{ "/favicon.png" | portal_image_url: image_asset_host }}' />
<link rel="icon" type="image/png" href='{{ "/favicon.png" | portal_image_url: image_asset_host }}' />
<style type="text/css">
.customer_inner_widget
{
padding-top:0px;
padding-bottom:20px;
padding-right:20px;
padding-left:20px;
}
.article-links {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 5px 0 15px 0;
width: 100%;
padding: 10px;
border: 1px dotted rgb(180, 180, 180);
}
.customer_widget {
top: auto;
bottom: auto;
}
.widget_button_extra_email {
margin: 15px 0 0 0;
position: relative;
left: auto;
}
.widget_button_extra_email {
margin: 15px 0 0 0;
position: relative;
left: auto;
}
</style>
<div id="customer_widget_main" class="customer_widget">
<div class="inside_title" style="font-size:25px">{{site.company_name}} {{system.snippets.help_center}}</div>
<div class="inside_desc">{{system.snippets.email_support}} </div>
<div class="customer_inner_widget" >
{% if current_user == nil or current_user.is_guest %}
<div class="input" ><span class="form_label">{{system.snippets.your_name}}:</span>
{{ interaction_name }}
</div>
<div class="input" ><span class="form_label">{{system.snippets.your_email}}:</span>
{{ interaction_email }}
</div>
{% endif %}
<div class="input"><span class="form_label">{{system.snippets.subject}}:</span>
{{ email_subject }}
</div>
<div class="input"><span class="form_label">Brand:</span>
<input class="default l" type="text" name="ticket[custom_brand]" id="ticket_custom_brand" value="" />
</div>
<div class="input"><span class="form_label">{{system.snippets.message}}:</span>
{{ email_body }}
</div>
<div id="autosuggest" class="article-links" style="display: none;"></div>
<div id="common" class="article-links">
<h4>Common Questions</h4>
<ul class="no-bullets">
<li><span class="label label-info">New</span> <a class="article" href=
"/customer/portal/articles/566428-getting-started-multilingual-support">Multilingual
Support</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/351939-how-do-i-access-the-desk-com-mobile-app-">Accessing
Desk.com Mobile</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/2619-custom-fields-for-case-and-customer">Adding
and Using Custom Fields</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1835-how-do-i-add-an-email-form-to-my-website-">Adding
an Email/Contact Form</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1548-how-to-use-your-own-domain-for-the-portal">Change
the Address of your Portal</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/749107-integrating-desk-com-and-salesforce">Integrate
Salesforce and Desk.com</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1376-understanding-business-rules">Understanding
Business Rules</a></li>
<li><a class="article" target="_blank" href="/customer/portal/articles/63009">Send Notifications For
Cases</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/2741-understanding-case-filters">Understanding
Case Filters</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/3085-how-do-i-add-a-chat-form-to-my-site-">Adding
Chat to your Site</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1424-understanding-the-case-lifecycle">Understanding
Case Statuses</a></li>
<li><a class="article" target="_blank" href="/customer/portal/articles/305053-glossary-of-terms">Glossary
of Terms</a></li>
</ul>
</div>
<div class='input'><span class='form_label'>{{system.snippets.file_attachment}}:</span>
{{ file_attachment }}
</div>
{{hidden_parameters }}
{{ submit_button }}
{{ interaction_info }}
</div><!--customer_inner_widget-->
</div><!--customer_widget_main-->
<script>
$(function() {
// Real-time auto-suggest
$('#email_subject, #email_body').keyup(function() {
count = 0;
if ($('#email_subject').val().length > 2 || $('#email_body').val().length > 2) {
query = $('#email_subject').val() + " " + $('#email_body').val();
$.ajax({
url: 'https://YOUR-SITE.desk.com/customer/portal/articles/autocomplete?term=' + query,
dataType: 'json'
}).done(apiSuccess).fail(apiFail);
} else {
$("#autosuggest").hide();
$("#common").show();
}
});
});
apiSuccess = function(data) {
auto_suggest_content = "";
auto_suggest_articles = "";
auto_suggest_questions = "";
$('#autosuggest').html("<h4>Do these help?</h4><ul class='no-bullets'></ul>");
$.each(data, function() {
var html = $(this.label);
article_title = html.find(".article-autocomplete-subject").html();
if (this.id.indexOf("questions") !== -1) {
auto_suggest_questions += '<li><a target="_blank" href="' + this.id + '" class="discussion">' + article_title + '</a></li>';
} else {
auto_suggest_articles += '<li><a target="_blank" href="' + this.id + '" class="article">' + article_title + '</a></li>';
}
count++;
});
if (count > 0) {
$('#autosuggest ul').append(auto_suggest_articles + auto_suggest_questions);
$("#common").hide();
$("#autosuggest").show();
} else {
$("#autosuggest").hide();
$("#common").show();
}
};
apiFail = function(data) {
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment