Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render link to cabinet details as menu button #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 72 additions & 20 deletions code/data-tracker/data-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ function customizeLoginButton(viewId) {

// Create a div for Login buttons
var $coacdButton = $("<div/>", {
id: "coacd-button-login"
id: "coacd-button-login",
});
$coacdButton.appendTo("#" + viewId);

// Append Big SSO Login button and non-SSO Login button
bigButton("coacd-big-button", "coacd-button-login", url, "sign-in", "Sign-In")
bigButton(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious on the reasoning of re-expanding the SSO code to take up more lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the default formatting behavior of Prettier. i actually was surprised it picked up more linting, since i linted this code the last time i edited it a few months ago. it makes me wonder if knack does some kind of linting automatically, or if my linter settings changed somehow.

i'm happy to defer to the linter's opinions, which aim for more readable code over being concise. in the past we've talked about standardizing these settings and making sure we use them globally, basically the standard right now it prettier's default.

"coacd-big-button",
"coacd-button-login",
url,
"sign-in",
"Sign-In"
);

$coacdButton.append(
"<a class='small-button' href='javascript:void(0)'>" +
Expand Down Expand Up @@ -53,10 +59,29 @@ $(document).on("knack-view-render.any", function (event, page) {
/*************** Big Buttons ****************/
/********************************************/
//Create Big Button nested in a block
function bigButton(id, view_id, url, fa_icon, button_label, is_disabled = false, callback = null) {
function bigButton(
id,
view_id,
url,
fa_icon,
button_label,
is_disabled = false,
callback = null
) {
var disabledClass = is_disabled ? " big-button-disabled'" : "'";
$( "<a id='" + id + "' class='big-button-container" + disabledClass + " href='" + url +
"'><span><i class='fa fa-" + fa_icon + "'></i></span><span> " + button_label + "</span></a>" ).appendTo("#" + view_id);
$(
"<a id='" +
id +
"' class='big-button-container" +
disabledClass +
" href='" +
url +
"'><span><i class='fa fa-" +
fa_icon +
"'></i></span><span> " +
button_label +
"</span></a>"
).appendTo("#" + view_id);

if (callback) callback();
}
Expand All @@ -65,10 +90,29 @@ function bigButton(id, view_id, url, fa_icon, button_label, is_disabled = false,
/************** Small Buttons ***************/
/********************************************/
//Create Small Button nested in a block
function smallButton(id, view_id, url, fa_icon, button_label, is_disabled = false, callback = null) {
function smallButton(
id,
view_id,
url,
fa_icon,
button_label,
is_disabled = false,
callback = null
) {
var disabledClass = is_disabled ? " small-button-disabled'" : "'";
$( "<a id='" + id + "' class='back-button" + disabledClass + " href='" + url +
"'><span><i class='fa fa-" + fa_icon + "'></i></span><span> " + button_label + "</span></a>" ).appendTo("#" + view_id);
$(
"<a id='" +
id +
"' class='back-button" +
disabledClass +
" href='" +
url +
"'><span><i class='fa fa-" +
fa_icon +
"'></i></span><span> " +
button_label +
"</span></a>"
).appendTo("#" + view_id);

if (callback) callback();
}
Expand Down Expand Up @@ -568,7 +612,10 @@ $(document).on("knack-scene-render.scene_1171", function (event, page) {
$("#" + detailsView)
.find("div.kn-detail." + fields.quantity.current)
.find(".kn-detail-body span")[0]
).text().replaceAll(",", "").trim()
)
.text()
.replaceAll(",", "")
.trim()
);

// handle situation where stock levels are negative (this should not but prob will happen)
Expand Down Expand Up @@ -746,7 +793,6 @@ $(document).on("knack-scene-render.scene_634", function (event, scene) {
/// Begin Technician Time Log Validation ///
////////////////////////////////////////////


function appendErrorMessage(viewKey, formDiv, msg) {
// remove existing error msg if present
var errorDiv = $(
Expand Down Expand Up @@ -852,19 +898,12 @@ $(document).on("knack-view-render.view_1252", function (event, page) {
highlightErrorField(`#${viewKey}-${startField.key}`);
highlightErrorField(`#${viewKey}-${endField.key}`);

errorMsgs = `${errorMsgs}${formatErrorMessage(
startField,
endField
)}`;
errorMsgs = `${errorMsgs}${formatErrorMessage(startField, endField)}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good condensed.

}
}
if (!passesValidation) {
// show red error banner
appendErrorMessage(
viewKey,
formDiv,
errorMsgs
);
// show red error banner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good condensed.

appendErrorMessage(viewKey, formDiv, errorMsgs);
}
return passesValidation;
});
Expand All @@ -873,3 +912,16 @@ $(document).on("knack-view-render.view_1252", function (event, page) {
////////////////////////////////////////////
/// End Technician Time Log Validation ///
////////////////////////////////////////////

//// Update link text to cabinet details page from signal detals
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of JS, use this Trigger Button article styling the button with CSS and calling it with the HTML whenever you need it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that's a cool trick! TIL. those docs are excellent!

in this case i'm styling a details link from a connection field, so i don't have control in the builder over what html is rendered by Knack. without this custom code, the link text would simply be the display field on the cabinets record.

for the CSS, i'm just using the same classes that knack uses on their menu buttons. that actually might be a nice improvement in your docs. you might not need to write any custom CSS if you can get by with the knack classes.

$(document).on("knack-view-render.view_1261", function (event, page) {
// find cabinet ID field div
var el = $(".field_1789");
// find child <a>
var a = $(el).find("a");
// update text
$(a).addClass("kn-link kn-link-1 kn-link-page kn-button");
$(a).html(
"<span class='icon is-small'><i class='fa fa-list'></i></span><span>Cabinet details</span>"
);
});