Last active
May 29, 2018 20:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#js-other-comments{ | |
padding: 5px; | |
border-top: 1px solid #C0C0C0; | |
} | |
#js-other-comments a{ | |
padding: 5px 7px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^https*://(.*?)greenemployee.com/ATE/Default.aspx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!