Skip to content

Instantly share code, notes, and snippets.

@Ayyagaries
Created July 10, 2019 15:13
Show Gist options
  • Save Ayyagaries/08c595f0d4a03349d8cbb68dbb36eaec to your computer and use it in GitHub Desktop.
Save Ayyagaries/08c595f0d4a03349d8cbb68dbb36eaec to your computer and use it in GitHub Desktop.
Javascript file
function displayUI(_response) {
var buttonView;
var response_keys = _.keys(_response);
if (response_keys.length === 0) {
$.vw_row_fn.add(addText("Contact's first name", "txt_firstname"));
$.vw_row_ln.add(addText("Contact's last name", "txt_lastname"));
$.vw_row_dept.add(addText("Department", "txt_department"));
$.vw_row_purpose.add(addText("Purpose of visit", "txt_purpose"));
} else if (response_keys.length > 0) {
if (response_keys.includes("location")) {
if (_response.location.length > 0) {
_.each($.vw_row_dept.children, function(child) {
$.vw_row_dept.remove(child);
});
buttonView = addButton("department", "-Location of Visit-", _response.location);
//buttonView.addEventListener('click', displayList);
$.vw_row_dept.add(buttonView);
} else {
$.vw_row_dept.add(addText("Department", "txt_department"));
}
}
if (response_keys.includes("purpose")) {
if (_response.purpose.length > 0) {
_.each($.vw_row_purpose.children, function(child) {
$.vw_row_purpose.remove(child);
});
buttonView = addButton("purpose", "-Purpose of Visit-", _response.purpose);
//buttonView.addEventListener('click', displayList);
$.vw_row_purpose.add(buttonView);
} else {
$.vw_row_purpose.add(addText("Purpose of visit", "txt_purpose"));
}
}
// if there is person_visiting in the key and the length is greater than zero
if (response_keys.includes("person_visiting")) {
if (_response.person_visiting.length > 0) {
_.each($.vw_row_fn.children, function(child) {
$.vw_row_fn.remove(child);
});
$.fn_ln_box.remove($.vw_row_fn);
_.each($.vw_row_ln.children, function(child) {
$.vw_row_ln.remove(child);
});
buttonView = addButton("personvisting", "-Person Visiting-", _response.person_visiting);
//buttonView.addEventListener('click', displayList);
$.vw_row_ln.add(buttonView);
}
} else {
$.vw_row_fn.add(addText("Contact's first name", "txt_firstname"));
$.vw_row_ln.add(addText("Contact's last name", "txt_lastname"));
}
}
App.closeLoading();
}
function addLabel(lblName) {
var alertlabel = Ti.UI.createLabel({
id: "lbl_alert_" + lblName,
color: Alloy.Globals.colors.red,
font: {
fontFamily: 'FontAwesome',
fontSize: 20
},
height: Ti.UI.FILL,
right: 3,
text: Alloy.Globals.fa.exclamationTriangle,
textAlign: 'center',
visible: false,
width: 32
});
if (Alloy.isTablet) {
alertlabel.font = {
fontFamily: 'FontAwesome',
fontSize: 25
};
}
return alertlabel;
}
function addButton(btnName, btnTitle, dataDisplay) {
var buttonView = Ti.UI.createView({
id: "btn_view_" + btnName,
width: Ti.UI.FILL,
height: Ti.UI.SIZE,
dataToDisplay: dataDisplay
});
var chevronLabel = Ti.UI.createLabel({
id: "chevron_lbl_" + btnName,
color: Alloy.Globals.colors.gray,
font: {
fontFamily: 'FontAwesome',
fontSize: 20
},
height: Ti.UI.FILL,
right: 5,
text: Alloy.Globals.fa.chevronRight,
textAlign: 'center',
width: 32,
dataToDisplay: dataDisplay,
});
//chevronLabel.addEventListener("click", displayList);
if (Alloy.isTablet) {
chevronLabel.font = {
fontFamily: 'FontAwesome',
fontSize: 25
};
}
var select_button = Ti.UI.createTextField({
id: "btn_" + btnName,
hintText: btnTitle,
backgroundColor: 'transparent',
borderColor: '#fff',
borderRadius: 6,
borderWidth: 1,
width: '90%',
editable: false,
dataToDisplay: dataDisplay,
left: "2%",
});
select_button.addEventListener("click", displayList);
buttonView.addEventListener("click", displayList);
buttonView.add(select_button);
buttonView.add(chevronLabel);
return buttonView;
}
function displayList(e) {
App.openScreen('checkin/facilityDefaults', {
dataToDisplay: e.source.dataToDisplay
}).on('checkin.loadfacilityDefaults', function(data) {
e.source.value = data.companyName;
});
}
function addText(hintText, textid) {
var textfield = Ti.UI.createTextField({
hintText: hintText,
id: textid,
backgroundColor: 'transparent',
borderWidth: 0,
width: '98%',
});
if (OS_IOS) {
textfield.width = "95%";
}
if (Alloy.isTablet) {
textfield.font = {
fontSize: 20
};
}
textfield.addEventListener("change", textFieldChanged);
return textfield;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment