Skip to content

Instantly share code, notes, and snippets.

@bennett-elder
Forked from ChrisMBarr/Add Css.css
Created December 15, 2016 04:42
Show Gist options
  • Select an option

  • Save bennett-elder/495b04a2bbb5f659d447cb1eecd785cf to your computer and use it in GitHub Desktop.

Select an option

Save bennett-elder/495b04a2bbb5f659d447cb1eecd785cf 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment