Skip to content

Instantly share code, notes, and snippets.

@ChrisMBarr
Last active May 29, 2018 20:12
Show Gist options
  • Save ChrisMBarr/22fec2cdf0199976a12c to your computer and use it in GitHub Desktop.
Save ChrisMBarr/22fec2cdf0199976a12c to your computer and use it in GitHub Desktop.
Allows auto-filling of GreenShades timesheet comments & easy filling with pre-made comments
#js-other-comments{
padding: 5px;
border-top: 1px solid #C0C0C0;
}
#js-other-comments a{
padding: 5px 7px;
}
<script>
function changeButtons(){
//Select buttons
var $btn_copy = $("#btnAutoFill");
var $btn_add = $("#btnAddEntry");
var $btn_delete = $("a[id$=btnDeleteAllEntries]");
var $btn_submit = $("a[id$=btnSubmit]");
var $btn_back = $(".page1").children(".btn");
//Change buttons colors
$btn_copy.removeClass("btn-primary").addClass("btn-default");
$btn_add.removeClass("btn-primary").addClass("btn-success");
$btn_delete.removeClass("btn-primary").addClass("btn-default");
$btn_back.removeClass("btn-primary").addClass("btn-default");
//Change button sizes
$btn_copy.add($btn_delete).add($btn_back).addClass("btn-sm");
//Change button icons
$btn_copy.children(".glyphicon").attr("class","glyphicon glyphicon-repeat");
$btn_submit.children(".glyphicon").attr("class","glyphicon glyphicon-ok");
//Select the buttons inside of modal windows
$(".section-modal .btn").each(function(){
var $thisModalBtn = $(this);
var btnTxt = $thisModalBtn.text().toLowerCase();
//Change button colors inside the modals depending on the text
if(btnTxt.indexOf("save")>=0 || btnTxt.indexOf("submit")>=0){
$thisModalBtn.removeClass("btn-primary").addClass("btn-success");
}else if(btnTxt.indexOf("delete")>=0){
$thisModalBtn.removeClass("btn-primary").addClass("btn-danger");
}
});
}
function setModalText(){
//These are all the possible options that will show up below the textbox to select
var comments = ["ATL Office","Remote - Cartersville, GA", "Remote - Rome, GA"]
var otherId = "js-other-comments";
var $visibleModals = $(".section-modal:visible");
if($visibleModals.length>0){
//find the comments field only for fields marked as null
var $textbox = $visibleModals.find("#Comments textarea");
//Show the other possible values as selectable links below the textbox
if(!$("#"+otherId).length){
var otherHtml = "<ul id='"+otherId +"' class='nav nav-pills'>";
for(var i=0;i<comments.length;i++){
otherHtml+="<li><a href='javascript:{};' data-txt='"+comments[i]+"'>"+comments[i]+"</a></li>";
}
otherHtml += "</ul>";
$textbox.after(otherHtml);
$("#"+otherId+" a").on("click",function(){
setTextboxVal($textbox, $(this).data("txt"), true);
});
}
//set the initial textbox value, but only if it's flagged as being null
if($textbox.parents(".dxeNullText_Greenshades").length>0){
var today = new Date;
//Tuesdays(2) I am normally in the ATL office, most other days I work from home in Cartersville
var textToUse = comments[(today.getDay()===2 ? 0 : 1)];
setTextboxVal($textbox, textToUse, true);
}else{
//Otherwise, don't set the value, just highlight the button that matches the current value
setTextboxVal($textbox, $textbox.val(), false);
}
}
function setTextboxVal($tb, val, setValue){
if(setValue){
$tb.val(val).trigger("keyup").blur().focus();
}
$("#"+otherId+" li").removeClass("active").find("a[data-txt='"+val+"']").parent().addClass("active");
}
}
$(function(){
//Run initially
changeButtons();
setModalText();
//Run on updatePanel posts
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(){
setTimeout(function(){
changeButtons();
setModalText();
},250);
});
});</script>
^https*://(.*?)greenemployee.com/ATE/Default.aspx
@ChrisMBarr
Copy link
Author

What Is This?

Use this if you use GreenShades with your company. This will take a set of predefined comments and auto-fill your timesheet entries with them. If you have multiple comments, they will appear as a buttons below the text field so that you can easily click to select one.

How to Install

Step 1: Use Chrome & Install the Personalized Web Options extention.

Step 2 Go into the extension options and create a new rule.

Step 3 Add the text above into the corresponding "Match URL" and **"Add CSS"**and "Add HTML" fields.
(NOTE: The script that does the magic here in enclosed in <script> tags and must be placed in the HTML field, and not into the script field of the extension! This allows it to have access to the HTML nodes that it needs.)

How to Change

Change the comments array (line 40) to contain all the comment options you'd like. Lines 64-67 currently decide on what the default comment should be based on the day of the week, but this is probably different for everyone. Please change this as you see fit.

@renet123
Copy link

this is pretty great! Have you seen anything to grab how much time someone has been clocked in? everyone here hates to log in to see how much time they have worked. (especially on friday afternoons) I called greenshades about an API, but no luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment