Skip to content

Instantly share code, notes, and snippets.

@deskie-io
Last active October 3, 2022 11:04
Show Gist options
  • Save deskie-io/eded12543f31eaaf6f887799da137bd9 to your computer and use it in GitHub Desktop.
Save deskie-io/eded12543f31eaaf6f887799da137bd9 to your computer and use it in GitHub Desktop.
Sample JS file for cases list page
$(function() {
/**
* Your website, to use it as an example
*/
var URL = 'http://example.com';
/**
* Some variables available in the global visibility of Deskie:
* CurrentCaseId
* CurrentUserId
* CurrentStaffId
* CurrentClientId
*
* The data in these variables can already be used to get a more detailed result using the Deskie API.
* https://deskie.io/api/introduction/intro
*/
var STAFF_ID = CurrentStaffId;
/**
* Some selectors to use as examples
*/
var HORIZONTAL_MENU_SELECTOR = '.header-container';
var HORIZONTAL_MENU_BUTTONS_SELECTOR = '.global-actions > .global-actions-list:last-child';
var HORIZONTAL_MENU_ELEMENTS_SELECTOR = '.primary-nav';
var TOP_PANEL_SELECTOR = '#alpha1_panel';
var RECORD_SELECTOR = '.req-tr.req-data-row';
var RECORD_INFO_SELECTOR = '.req-td.req-inf';
/** HELPERS */
/**
* Checking for undefined
*/
var checkNotUndefined = function(data) {
return (typeof data === 'undefined') ? false : true;
}
/**
* Inserting in the end or beginning of the element
*/
var addCode = function(selector, htmlCode, after) {
var element = $(selector);
if(checkNotUndefined(after) === true && after === true) {
element.append(htmlCode);
} else {
element.prepend(htmlCode);
}
};
/** EXAMPLES */
/**
* Adding custom info in the user's block
*
* Header goes first
*/
addCode(
TOP_PANEL_SELECTOR,
`<div style="color:red;">
<strong>External Data</strong>
</div>`,
true
);
/**
* Example of adding an item to the menu
* Code result in Deskie: https://deskie.io/img/js_files/02_sample_for_case_and_create_case_pages.png
*/
addCode(
HORIZONTAL_MENU_ELEMENTS_SELECTOR,
`<li class="nav-item nav-item-example inlb">
<a class="nav-item-url " href="#example">Example</a>
</li>`,
true
);
/**
* Example of adding a button to the right block of the header
* Code result in Deskie: https://deskie.io/img/js_files/03_sample_for_case_and_create_case_pages.png
*/
addCode(
HORIZONTAL_MENU_BUTTONS_SELECTOR,
`<li class="global-action-item inlb force-login" title="Example">
<a class="nav-item-url" href="#example">
<i class="icon fi-star"></i>
</a>
</li>`,
false
);
/**
* Adding your company colors to the horizontal menu
* Code result in Deskie: https://deskie.io/img/js_files/04_sample_for_case_and_create_case_pages.png
*/
$(document).find(HORIZONTAL_MENU_SELECTOR).css({
'border-bottom': 'solid 2px red',
});
/**
* Connecting your CSS in Deskie code. There are additional icons in CSS
*/
$(document)
.find('body')
.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css">');
/**
* Adding falling snow if your agents are going to work on New Year's Eve :)
*/
$.get('https://cdnjs.cloudflare.com/ajax/libs/JQuery-Snowfall/1.7.4/snowfall.jquery.min.js', {
}, function(jsLibCode) {
$("body").append($("<script />", {
html: jsLibCode + ' $(document).snowfall({flakeColor : "yellow", shadow: true});',
}));
});
$('body').css('overflow-y', 'hidden');
/**
* That was a brief explanation about how you can change or add any buttons, forms and code to the case page.
*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment