Autolisp - DCL File - Why must this dialog box need an "OK" and "CANCEL" buttons? - cad

I'm running into an error, and I don't know why it exists. I'm trying to build a dialog box for users to update all of the title blocks and revisions for a job of their choosing. I have a rough layout put together, but when I go to run it, I get the following error message.
Continuing past this point just causes the application to crash. Adding ok_cancel ; to the end stops the dialog box from crashing, but now I have two additional button that aren't clearly defined for the user and are redundant in purpose.
How do I make the dialog box work without adding any additional buttons?
Lisp Code
(setq *sDCLPath* "[Stored directory]"); Either use "\\" or "/" between folder names
(setq *sName01* "[File's name]")
;; Starts the dialog box for user input
(defun C:Test01 (/ sPathAndName dclFile vModule)
;; File Exists
(setq sPathAndName (findfile (strcat *sDCLPath* "\\" *sName01* ".dcl")))
(if (not sPathAndName)(progn
(princ "\nError: The DCL file was not found.\n")
(princ "\nPath and name: ")(princ sPathAndName)(terpri)
(exit)
));if<-progn
;; DCL File
(setq dclFile (load_dialog sPathAndName))
(if (>= 0 dclFile)(progn
(princ "\nError: DCL file cannot be loaded.\n")
(exit)
));if<-progn
(new_dialog "TitleRevUpdate" dclFile "(done_dialog 0)" '(-1 -1))
(start_dialog)
(unload_dialog dclFile)
(gc)
(princ)
);C:Test01
DCL Code
TitleRevUpdate : dialog {
key = "Title" ;
label = "Update Title Block and Revision" ;
// Title
: boxed_column {
key = "Column_TitleBoxes" ;
label = "Title" ;
// Client
: boxed_column {
key = "Client_Box" ;
label = "Client" ;
: row { // Row 01 - Name
key = "Row_Client_Name" ;
: text {
key = "txt_Client_Name" ;
label = "Client's Name" ;
}// text
: edit_box {
key = "edbx_Client_Name" ;
}// edit_box
} //row
: row { // Row 02 - Location
key = "Row_Client_Loc" ;
: text {
key = "txt_Client_Loc" ;
label = "Client's Location" ;
}// text
: edit_box {
key = "edbx_Client_Loc" ;
}// edit_box
} //row
} //boxed_column
: spacer ;
// Job
: boxed_column {
key = "Job_Box" ;
label = "Job" ;
: row { // Row 03 - Name
key = "Row_Job_Name" ;
: text {
key = "txt_Job_Name" ;
label = "Job's Name" ;
}// text
: edit_box {
key = "edbx_Job_Name" ;
}// edit_box
} //row
: row { // Row 04 - Number
key = "Row_Job_Number" ;
: text {
key = "txt_Job_Number" ;
label = "Job's Number" ;
}// text
: edit_box {
key = "edbx_Job_Number" ;
}// edit_box
} //row
} //boxed_column
: spacer ;
// Miscellaneous
: boxed_column {
key = "Miscellaneous_Box" ;
label = "Miscellaneous" ;
: row { // Row 05 - Creator's Initials
key = "Row_Creator_Name" ;
: text {
key = "txt_Creator_Name" ;
label = "Creator's Name" ;
}// text
: edit_box {
key = "edbx_Creator_Name" ;
}// edit_box
} //row
: row { // Row 06 - Date of Creation
key = "Row_Date" ;
: text {
key = "txt_TitleDate" ;
label = "Date" ;
}// text
: edit_box {
key = "edbx_TitleDate" ;
}// edit_box
} //row
: row { // Row 07 - Issued For
key = "Row_Issued_For" ;
: text {
key = "txt_Issued_For" ;
label = "Issued For" ;
}// text
: edit_box {
key = "edbx_Issued_For" ;
}// edit_box
} //row
} //boxed_column
} //boxed_column
: spacer ;
// Revision
: boxed_column {
key = "Column_Revision" ;
label = "Revision" ;
: row { // Row 08 - Quick Choices
key = "Row_Buttons" ;
: button {
key = "btn_IFC" ;
label = "Issued for Construction" ;
}// button
: button {
key = "tbn_AB" ;
label = "As Built" ;
}// button
: radio_column {
key = "RadioCol_WriteMethod" ;
: radio_button {
key = "rbtn_Owt" ;
label = "Clear & Overwrite" ;
}// radio_button
: radio_button {
key = "rbtn_Apnd" ;
label = "Append / New Line" ;
}// radio_button
} //radio_column
} //row
: spacer ;
: row { // Row 09 - Rev Labels
key = "Row_Labels" ;
: text {
key = "txt_Rev" ;
label = "Rev" ;
}// text
: text {
key = "txt_Initials" ;
label = "Initials" ;
}// text
: text {
key = "txt_Description" ;
label = "Description" ;
}// text
: text {
key = "txt_RevDate" ;
label = "Date" ;
}// text
} //row
: row { // Row 10 - Rev Edit Boxes
key = "Row_Rev" ;
: edit_box {
key = "edbx_Rev" ;
}// edit_box
: edit_box {
key = "edbx_Initials" ;
}// edit_box
: edit_box {
key = "edbx_Date" ;
}// edit_box
: edit_box {
key = "edbx_RevDate" ;
}// edit_box
} //row
} //boxed_column
: spacer ;
// Return Commands
: row { // Row 11 - Buttons
key = "Row_Return" ;
: button {
key = "btn_DWGs" ;
action = "(done_dialog 2)" ;
label = "Show Drawings" ;
}// button
: button {
key = "btn_Confirm" ;
action = "(done_dialog 1)" ;
label = "Confirm" ;
}// button
: button {
key = "btn_Cancel" ;
action = "(done_dialog 0)" ;
label = "Cancel" ;
}// button
} //row
ok_cancel ; // How to remove this without throwing errors.
: spacer ;
} // TitleRevUpdate

Every DCL form must contain a control with either the attribute is_default = true or is_cancel = true. Each of these attributes can also only be assigned to a single control on the form.
The set of predefined DCL clusters ok_cancel, ok_only, ok_cancel_help, ok_cancel_help_errtile,ok_cancel_help_info already contain controls which possess these attributes, thus avoiding the error when you include them in your DCL definition.
As such, to fix your dialog, simply change the DCL to the following:
: row { // Row 11 - Buttons
key = "Row_Return" ;
: button {
key = "btn_DWGs" ;
action = "(done_dialog 2)" ;
label = "Show Drawings" ;
}// button
: button {
key = "btn_Confirm" ;
action = "(done_dialog 1)" ;
label = "Confirm" ;
is_default = true; // <-------------------- Added
}// button
: button {
key = "btn_Cancel" ;
action = "(done_dialog 0)" ;
label = "Cancel" ;
is_cancel = true; // <-------------------- Added
}// button
} //row
The use of is_cancel = true will also allow the red 'x' in the top-right corner of the dialog to evaluate the action of the control to which is_cancel = true has been assigned.

Related

Jetpack Compose - How Do I program this composable to access the "url" in the "list"

//I'm having problems trying to get the title text in the KbfPlayScreen.kt to access the "url" in the list that is in the Data.kt on button click.
**KbfPlayScreen.kt**
#Composable
fun KbfSermonsView(sermons: List<Sermon>) {
Column() {
sermons.forEach {
SermonRow(it.title, it.timestamp)
Divider(thickness = 1.dp, modifier = Modifier.padding(top = 5.dp, bottom = 5.dp))
}
}
}
**Data.kt**
val kbfList = listOf<Kbf>(
Kbf(
title = "The Purpose Of KBF", description = "", imageId = R.drawable.kbf_tony, sermons =
listOf<Sermon>(
Sermon(title= "The Purpose Of KBF", image= "kbf_tony", url=
"https://www.youtube.com/embed/O5xZCZlCqBw", timestamp= "1612674000"),
)),
Kbf(
title = "Goal Setting", description = "", imageId = R.drawable.kbf_mike, sermons =
listOf<Sermon>(
Sermon(title = "Goal Setting", image = "kbf_mike", url =
"https://www.youtube.com/embed/HRDPWpUagxY", timestamp = "1612674000")
))
)

How do you write SharePoint 2010 conditional formatting for this?

I am using SPD 2010 and SharePoint Sever 2010.
Using conditional formatting I'm trying to format a list so that if today's date is greater than 30 days before the start date column a cell will turn red.
I've tried several XPath expressions from other Stackoverflow entries but nothing has worked. I'm wondering if I am even adding the XPath expression in the right place: In SPD I am selecting a date from the desired column, choosing "Conditional Formatting", selecting "Format Column", selecting "Advanced" and putting my expressions in the XPath expression textbox.
Appreciate your help!
I'm going to suggest a non-Xpath approach, but if you're looking to stick with Xpath you should take a look at the answers on this similar question.
After struggling with this problem myself, I've taken to using JavaScript for conditional formatting, since it can work with dates (including the current date), numbers, and strings, and it can manipulate HTML pretty easily.
A bit of client side code can automatically:
Detect whether a list of conditional formatting rules exists
Create the list if necessary
Provide an interface for creating new rules (which are stored as list items) that should apply to the current page
Loop through all the current page's rules and apply them to any list view web parts detected on the same page
The nicest part of this approach is that I can add the web part to a page and just let the business users configure the formatting to their liking; no need for me to be further involved whenever they want to change something.
I put the combined HTML/CSS/JavaScript in a text file that can be saved to a document library somewhere in my site collection. To then add the conditional formatting to page, I just add a content editor web part to the page and set its "content link" property to be the path to the text file.
The content editor web part then displays a gray "Conditional Formatting" button that the user can click to view and modify the formatting rules, as seen in the screen shot below.
Here's the conditional formatting code for SharePoint 2010 that I use in my text file:
<div id="_conditional_formatting_link" style="display:none; ">
<div unselectable="on" style="display:inline-block; user-select:none; cursor:pointer; padding: 3px; background-color:#9b9b9b; color:white; border:1px solid #888;" onclick="javascript:var rules = document.getElementById('_conditional_formatting'); if(rules.style.display == 'none'){rules.style.display = 'inline-block'}else{rules.style.display = 'none'}">
Conditional Formatting
</div>
</div>
<div id="_conditional_formatting" style="display:none;background-color:#dfdfdf; border: 1px solid black; width:95%; max-width:1100px;">
<a style="border:0px;padding:5px;float:right;" title="Reapply Formatting" href="javascript:getConditions(false);">
<img style="border:0px;" src="/_layouts/images/staticrefresh.gif"/>
</a>
<ol id="_conditional_formatting_rules"></ol>
<div style="text-align:right; ">
<div id="_add_conditional_formatting_rule" unselectable="on" onclick="javascript: Add_Conditional_Formatting();" style="user-select:none; cursor:pointer; padding: 3px; margin: 3px; display:inline-block; background-color:#9b9b9b; border:1px solid #888; color:white;">Add Rule</div>
</div>
</div>
<script>
this.cfl = this.cfl ? this.cfl : new Object(null);
var conditionalFormattingList = "Conditional Formatting";
function getConditions(reloadRules) {
/* if reloadRules, query the conditions list and get all the rules. Otherwise just reapply the ones in memory to the current document. */
if (typeof reloadRules == "undefined") { reloadRules = true; }
if (reloadRules) {
var conditionalFormattingRules = document.getElementById("_conditional_formatting_rules");
while (conditionalFormattingRules.children.length > 0) { /* Clear out the currently displayed list of rules. */
conditionalFormattingRules.removeChild(conditionalFormattingRules.children[0]);
}
this.cfl.clientContext = new SP.ClientContext();
this.cfl.user = cfl.clientContext.get_web().get_currentUser();
var list = cfl.clientContext.get_web().get_lists().getByTitle(conditionalFormattingList);
var camlQuery = new SP.CamlQuery();
var folder = list.get_rootFolder();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'URL\' /><Value Type=\'Text\'>' + document.location.pathname + '</Value></Eq></Where><OrderBy><FieldRef Name=\'Priority\' /><FieldRef Name=\'Name\' /></OrderBy></Query></View>');
this.cfl.items = list.getItems(camlQuery);
cfl.clientContext.load(cfl.user);
cfl.clientContext.load(list, 'EffectiveBasePermissions');
cfl.clientContext.load(cfl.items);
cfl.clientContext.load(folder);
}
this.cfl.clientContext.executeQueryAsync(
Function.createDelegate(this,
function () {
var Me = this.cfl.user.get_title();
if (reloadRules) {
var baseFormUrl = folder.get_serverRelativeUrl() + "/EditForm.aspx?ID=";
/* Figure out if the current user has access to create or edit items on the Conditional Formatting list */
var perms = list.get_effectiveBasePermissions();
this.cfl.hasEdit = perms.has(SP.PermissionKind.editListItems);
this.cfl.hasCreate = perms.has(SP.PermissionKind.addListItems);
/* Fill an array with our formatting rules */
this.cfl.targets = [];
var itemEnumerator = this.cfl.items.getEnumerator();
while (itemEnumerator.moveNext()) {
var item = itemEnumerator.get_current();
var targ = new Object(null);
targ.column = item.get_item("Column");
targ.comparison = item.get_item("Comparison");
targ.style = item.get_item("Style");
targ.scope = item.get_item("Scope");
targ.type = item.get_item("Type");
targ.value = item.get_item("Value"); if (targ.value == null) { targ.value = ""; }
targ.id = item.get_item("ID");
targ.offset = item.get_item("Offset");
cfl.targets.push(targ);
}
}
if (!this.cfl.hasCreate) { document.getElementById("_add_conditional_formatting_rule").style.display = "none"; }
for (var targetIterator = 0, len = cfl.targets.length; targetIterator < len; targetIterator++) {
var currentTarget = cfl.targets[targetIterator];
if (reloadRules) {
var rulelist = document.getElementById("_conditional_formatting_rules");
var ruletoadd = document.createElement("li");
var comparisondisplay = currentTarget.type.indexOf("Field") != -1 ? "value of the <b>" + currentTarget.value + "</b> column" : "<b>'" + currentTarget.value + "'</b>";
if (currentTarget.type == "Special" || currentTarget.type == "Number") {
if (currentTarget.value.toString().toLowerCase() == "[me]") { comparisondisplay = "<b>[Me](" + Me + ")</b>"; }
else { comparisondisplay = "<b>" + currentTarget.value + "</b>"; }
}
if (currentTarget.value == "") { comparisondisplay = "<b>(blank)</b>"; }
if (currentTarget.offset != null) {
comparisondisplay += "<b>" + (currentTarget.offset < 0 ? " " : " +") + currentTarget.offset + "</b>"
}
var editLink = this.cfl.hasEdit ? "<div style='display:inline-block;cursor:pointer;' onclick='SP.UI.ModalDialog.commonModalDialogOpen(" + '"' + baseFormUrl + currentTarget.id + '&Source=' + document.location.pathname + '"' + ",{},refreshPageConditions); '>" + "<img src='/_layouts/images/EDITITEM.GIF' style='vertical-align:middle;' title='Customize' alt='Customize'/>" + " </div>" : "";
ruletoadd.innerHTML = editLink + "When <b>" + currentTarget.column + "</b> "
+ currentTarget.comparison + " " + comparisondisplay
+ ", apply {" + (currentTarget.style == null ? "remove all formatting" : "<span style='" + currentTarget.style + "'>" + currentTarget.style + "</span>") + "} to the <b>" + currentTarget.scope + "</b>" + ((currentTarget.scope != "Cell" && currentTarget.scope != "Row") ? " column" : "");
rulelist.appendChild(ruletoadd);
}
var tables = document.querySelectorAll("table.ms-listviewtable"); /* Should get all the list view web parts on the page. */
var t_i = 0;
while (t_i < tables.length) {
var columnIndex = null; /* Index of the column to compare against */
var valueIndex = null; /* Index of a second column from which to pull the value to compare */
var styleTargetIndex = null; /* Index of a column to apply formatting to */
var thisTable = tables[t_i];
var headings = thisTable.rows[0].cells;
var h_i = 0;
while (h_i < headings.length) { /* Check all the column headings... */
var thisHeading = headings[h_i].querySelector("div:first-child");
if (thisHeading != null) {
/* In Internet Explorer, the headings have a DisplayName attribute you can grab. If that's not there, just grab the innerText or textContent */
var dispname = thisHeading.DisplayName ? thisHeading.DisplayName : (thisHeading.innerText ? thisHeading.innerText : thisHeading.textContent);
dispname = dispname.replace(/^\s+|\s+$/g, '');/* removes leading and trailing whitespace */
if (currentTarget.scope != "Cell" && currentTarget.scope != "Row") {
/*If the scope isn't Cell or Row, see if this is the cell to which the formatting should applied */
if (dispname == currentTarget.scope) { styleTargetIndex = h_i; }
}
if (currentTarget.type.indexOf("Field") != -1) {
/*If the value type is a Field, check to see if this is the field whose value we care about */
if (dispname == currentTarget.value.toString()) { valueIndex = h_i; }
}
if (dispname == currentTarget.column) { columnIndex = h_i; }
}
h_i += 1;
}
if (columnIndex != null) { /* If we found a matching heading, let's try to apply the rules... */
var rows = thisTable.rows;
for (var i = (rows.length > 0 ? 1 : 0) ; i < rows.length; i++) {
var cells = rows[i].children;
if (cells.length <= columnIndex) { continue }
var innerLink = cells[columnIndex].querySelector("a"); /* I want to specifically target links so that we can change their text color if necessary */
/* Populate valueToEval with the text value of the current cell, or its inner link if it has one */
var valueToEval = cells[columnIndex].innerText ? (innerLink != null ? innerLink.innerText : cells[columnIndex].innerText) : (innerLink != null ? innerLink.textContent : cells[columnIndex].textContent);
if (typeof (valueToEval) == "undefined") { valueToEval = "" } /* Treat empties as blanks */
var listValueToCompareAgainst = null;
if (valueIndex != null) { /* valueIndex only has a value if we need to grab the comparison value from another column on the list */
valueLink = cells[valueIndex].querySelector("a");
listValueToCompareAgainst = cells[valueIndex].innerText ? (valueLink != null ? valueLink.innerText : cells[valueIndex].innerText) : (valueLink != null ? valueLink.textContent : cells[valueIndex].textContent);
}
var needsStyling = false;
switch (currentTarget.type) {
case "Number":
if (!isNaN(Number(valueToEval))) {
valueToEval = +(valueToEval);
}
if (!isNaN(Number(currentTarget.value))) {
currentTarget.value = +(currentTarget.value);
}
break;
case "Date":
valueToEval = new Date(valueToEval);
currentTarget.value = new Date(currentTarget.value);
if (currentTarget.offset != null) {
currentTarget.value.setDate(currentTarget.value.getDate() + +(currentTarget.offset));
}
break;
case "Text": /* Already covered, bro */ break;
case "Date Field":
valueToEval = new Date(valueToEval);
currentTarget.value = new Date(listValueToCompareAgainst);
if (currentTarget.offset != null) {
currentTarget.value.setDate(currentTarget.value.getDate() + +(currentTarget.offset));
}
break;
case "Text Field": currentTarget.value = listValueToCompareAgainst; break;
case "Number Field":
if (!isNaN(Number(listValueToCompareAgainst))) {
currentTarget.value = listValueToCompareAgainst;
if (currentTarget.offset != null) {
currentTarget.value += Number(currentTarget.offset);
}
}
if (!isNaN(Number(valueToEval))) {
valueToEval = Number(valueToEval);
}
break;
case "Special":
if (currentTarget.value.toLowerCase) {
if (currentTarget.value.toLowerCase() == "[me]") { currentTarget.value = Me }
else if (currentTarget.value.toLowerCase().indexOf("[today]") != -1) {
var dateDifference = Number(currentTarget.value.toLowerCase().replace("[today]", "").replace(" ", "").replace("+", ""));
currentTarget.value = new Date();
if (!isNaN(dateDifference)) { currentTarget.value.setDate(currentTarget.value.getDate() + dateDifference); }
if (currentTarget.offset != null) {
currentTarget.value.setDate(currentTarget.value.getDate() + Number(currentTarget.offset));
}
valueToEval = new Date(valueToEval);
}
} else { valueToEval = new Date(valueToEval); }
break;
}
switch (currentTarget.comparison) {
case "Greater Than or Equal To": needsStyling = (valueToEval >= currentTarget.value); break;
case "Greater Than": needsStyling = (valueToEval > currentTarget.value); break;
case "Less Than or Equal To": needsStyling = (valueToEval <= currentTarget.value); break;
case "Less Than": needsStyling = (valueToEval < currentTarget.value); break;
case "Equal To": needsStyling = (valueToEval == currentTarget.value); break;
case "Not Equal To": needsStyling = (valueToEval != currentTarget.value); break;
case "Contains": needsStyling = (valueToEval.indexOf(currentTarget.value) != -1); break;
case "Does Not Contain": needsStyling = (valueToEval.indexOf(currentTarget.value) == -1); break;
}
if (needsStyling) {
var links;
if (currentTarget.scope != "Row") {
var targetIndex = (styleTargetIndex != null) ? styleTargetIndex : columnIndex;
cells[targetIndex].setAttribute("style", currentTarget.style);
links = cells[targetIndex].querySelectorAll("a");
} else {
rows[i].setAttribute("style", currentTarget.style);
for (var j = 0; j < cells.length; j++) {
cells[j].setAttribute("style", currentTarget.style);
}
links = rows[i].querySelectorAll("a");
}
for (var j = 0; j < links.length; j++) {
if (links[j].title != "Open Menu") {
links[j].setAttribute("style", currentTarget.style);
links[j].style.backgroundColor = "";
}
links[j].style.border = "0px";
}
}
}
}
t_i += 1;
}
}
document.getElementById("_conditional_formatting_link").style.display = "inline-block";
}
),
Function.createDelegate(this,
function (sender, args) { /* There was an error accessing the list. Time to create it! */
var lci = new SP.ListCreationInformation();
lci.set_title(conditionalFormattingList);
lci.set_templateType(SP.ListTemplateType.genericList);
var condition_list = clientContext.get_web().get_lists().add(lci);
clientContext.load(condition_list);
var colTitle = condition_list.get_fields().getByTitle("Title");
colTitle.set_required(false); colTitle.set_hidden(true); colTitle.update();
condition_list.update();
var colColumn = condition_list.get_fields().addFieldAsXml('<Field Description=\'The column to compare (must be visible on the page)\' DisplayName=\'Column\' Type=\'Text\'/>', true, SP.AddFieldOptions.defaultValue);
var colComparison = condition_list.get_fields().addFieldAsXml('<Field Description=\'\' Type=\'Choice\' DisplayName=\'Comparison\' Format=\'Dropdown\' FillInChoice=\'FALSE\'><Default>Equal To</Default><CHOICES><CHOICE>Greater Than</CHOICE><CHOICE>Greater Than or Equal To</CHOICE><CHOICE>Equal To</CHOICE><CHOICE>Less Than or Equal To</CHOICE><CHOICE>Less Than</CHOICE><CHOICE>Not Equal To</CHOICE><CHOICE>Contains</CHOICE><CHOICE>Does Not Contain</CHOICE></CHOICES></Field>', true, SP.AddFieldOptions.defaultValue);
var colValue = condition_list.get_fields().addFieldAsXml('<Field Description=\'The value or the name of a column to compare against\' DisplayName=\'Value\' Type=\'Text\'/>', true, SP.AddFieldOptions.defaultValue);
var colType = condition_list.get_fields().addFieldAsXml('<Field Description=\'Indicate the type of value you are comparing against. Choose Special if using the [Me] or [Today] placeholders.\' Type=\'Choice\' DisplayName=\'Type\' Format=\'Dropdown\' FillInChoice=\'FALSE\'><Default>Text</Default><CHOICES><CHOICE>Date</CHOICE><CHOICE>Number</CHOICE><CHOICE>Text</CHOICE><CHOICE>Date Field</CHOICE><CHOICE>Number Field</CHOICE><CHOICE>Text Field</CHOICE><CHOICE>Special</CHOICE></CHOICES></Field>');
var colOffset = condition_list.get_fields().addFieldAsXml('<Field Description=\'Optionally specify a number to offset the value by when comparing against a number or date.\' DisplayName=\'Offset\' Type=\'Number\' />', true, SP.AddFieldOptions.defaultValue);
var colStyle = condition_list.get_fields().addFieldAsXml('<Field NumLines=\'4\' Description=\'The CSS to apply to when the condition is met. Leave blank to remove formatting. Example syntax: background-color:darkred; color:white; font-weight:bold;\' DisplayName=\'Style\' Type=\'Note\' />', true, SP.AddFieldOptions.defaultValue);
var colScope = condition_list.get_fields().addFieldAsXml('<Field Description=\'The scope to which the style should be applied. Choose Row, Cell, or specify a column name.\' Type=\'Choice\' DisplayName=\'Scope\' Format=\'Dropdown\' FillInChoice=\'TRUE\'><Default>Cell</Default><CHOICES><CHOICE>Cell</CHOICE><CHOICE>Row</CHOICE></CHOICES></Field>', true, SP.AddFieldOptions.defaultValue);
var colPriority = condition_list.get_fields().addFieldAsXml('<Field Description=\'Priority determines which styles are applied in case of overlapping conditions. Higher numbers are applied later.\' DisplayName=\'Priority\' Type=\'Number\' />', true, SP.AddFieldOptions.defaultValue);
var colUrl = condition_list.get_fields().addFieldAsXml('<Field Description=\'Page where this rule should be applied\' DisplayName=\'URL\' Type=\'Text\'/>', true, SP.AddFieldOptions.defaultValue);
clientContext.executeQueryAsync(
Function.createDelegate(this, function () { getConditions(); }),
Function.createDelegate(this, function (sender, args) { document.getElementById("_conditional_formatting").innerHTML = ("An error occcurred while trying to apply conditional formatting to the list for you. Error details: " + args.get_message() + " " + args.get_stackTrace()); document.getElementById("_conditional_formatting_link").style.display = "inline-block"; }));
}
));
}
/* This method is called when the Add Rule button is clicked. */
function Add_Conditional_Formatting() {
/* Create a new item with only the URL and Priority fields filled out */
var currUrl = document.location.pathname;
var clientContext = new SP.ClientContext();
var itemCreateInfo = new SP.ListItemCreationInformation();
var newItem = clientContext.get_web().get_lists().getByTitle(conditionalFormattingList).addItem(itemCreateInfo);
newItem.set_item('URL', currUrl);
/* Give the new item a priority that will put it at the end of the list. This is kind of a hack since the highest priority is not necessarily the rulecount. */
newItem.set_item('Priority', document.getElementById("_conditional_formatting_rules").children.length + 1);
newItem.update();
clientContext.load(newItem);
clientContext.executeQueryAsync(Function.createDelegate(this, function () {
getConditions(); /* Reload to refresh the rules list after adding the item */
}), Function.createDelegate(this, function (sender, args) { alert(args.get_message()); }));
}
/* This method is called when the Edit Item dialog box is closed. It refreshes the page it the item was saved. */
function refreshPageConditions(result) { if (result != SP.UI.DialogResult.cancel) { window.location.replace(document.location.href) } }
ExecuteOrDelayUntilScriptLoaded(function () {
getConditions();
/* If there are any collapsible sections on the page, keep checking to see whether formatting needs to be reapplied */
this.cfl.TableRowCount = 0;
if (document.querySelector("img[alt='expand']") != null) {
setInterval(function () {
var tempTableRowCount = document.querySelectorAll("tr").length;
if (tempTableRowCount != this.cfl.TableRowCount) {
/* Only reapply formatting if the count of table rows is different than it was previously */
this.cfl.TableRowCount = tempTableRowCount;
getConditions(false) /* Passing false reapplies loaded rules without re-querying the SharePoint list */
}
}, 1000)
}
}, "SP.JS");
</script>

In MDI mode, Dynamic change menu caption which without ID

The old question, is for menu on dialog, to change the menu caption which no id
How do I dynamic change MENU text which without ID
the code is
////////////////////////////////////////////////////////
//CMenu* pMenu = CMenu::FromHandle(GetSkinMenu(m_pMainWnd->m_hWnd))->GetSubMenu(1);
HMENU hMenu;
hMenu=LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU_S8521));
//CMenu* pMenu = CMenu::FromHandle(hMenu);
CMenu* pMenu = GetMenu();
int i, nCou = pMenu->GetMenuItemCount();
UINT uID;
CString strMenu;
for (i = 0; i < nCou; i++)
{
uID = pMenu->GetMenuItemID(i);
if (uID == 0) // separator
{
//TRACE(_T("----------------------\n"));
continue;
}
//pMenu->GetMenuString(i, ss, MF_BYPOSITION);
if (uID == (UINT)-1)
{
//TRACE(_T("Popup '%s' "), ss);
if(i == 0)
{
strMenu = theApp.mLang.structMenuLang.strMenuFile;
}
if(i == 1)
{
strMenu = theApp.mLang.structMenuLang.strMenuSet;
}
if(i == 2)
{
strMenu = theApp.mLang.structMenuLang.strMenuLanguage;
}
if(i == 3)
{
strMenu = theApp.mLang.structMenuLang.strMenuHelp;
}
pMenu->ModifyMenu(i, MF_BYPOSITION|MF_STRING|MF_ENABLED, 0, strMenu);
//TRACE(_T("modified to '%s' "), ss);
}
//else
// TRACE(_T("Item '%s', ID=%d "), ss, uID);
//TRACE(_T("\n"));
}
//Invalidate(true);
//UpdateWindow();
this->SetMenu(pMenu);
Now I want to change the MID menu caption which also no id,
the keyword code is
this->SetMenu(pMenu);
then the menu will reflash. My question is On MDI Menu, how do I reflash the menu caption
, In out command window i find the TRACE message is right, but the UI no change.
ok, I get method to solve it using
CMenu menu;
menu.LoadMenu(IDR_MENU_MAIN);
AfxGetMainWnd()->SetMenu(pMenu);
AfxGetMainWnd()->DrawMenuBar();
pMenu->Detach();

Saving Magento Barcode image in excel

I am trying to save generate and save the barcode in excel. However, I am having problem saving the image in the correct format. The image is saved in the last column. But, I am not sure how save it.
hope someone can help. Code as below:
<?php
require_once '../app/Mage.php';
umask(0);
Mage::app();
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND);
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=exportMyEANCodes.csv");
$eanPrefixCode="0123456";
$storeId = Mage::app()->getStore()->getId();
$product = Mage::getModel('catalog/product');
$products = $product->getCollection()->addStoreFilter($storeId)->getAllIds();
echo '"sku","ean","barcode"'. "\n";
foreach($products as $productid)
{
$product = Mage::getModel('catalog/product')->load($productid);
$sku = $product->getSku();
$ean=ean13_check_digit($eanPrefixCode. str_pad($product->getId(), 5, "0", STR_PAD_LEFT));
$bc = new barCode();
//$bc->build($ean);
$output='"'. $sku. '","'. $ean. '","'.$bc->build($ean).'"';
echo $output. "\n";
}
$bc = new barCode();
$bc->build($ean);
function ean13_check_digit($digits){
$digits =(string)$digits;
$even_sum = $digits{1} + $digits{3} + $digits{5} + $digits{7} + $digits{9} + $digits{11};
$even_sum_three = $even_sum * 3;
$odd_sum = $digits{0} + $digits{2} + $digits{4} + $digits{6} + $digits{8} + $digits{10};
$total_sum = $even_sum_three + $odd_sum;
$next_ten = (ceil($total_sum/10))*10;
$check_digit = $next_ten - $total_sum;
return $digits . $check_digit;
}
class barCode
{
public $bcHeight, $bcThinWidth, $bcThickWidth, $bcFontSize, $mode;
function __construct($mode='gif', $height=50, $thin=2, $thick=3, $fSize=2)
{
$this->bcHeight = $height;
$this->bcThinWidth = $thin;
$this->bcThickWidth = $this->bcThinWidth * $thick;
$this->fontSize = $fSize;
$this->mode = $mode;
$this->outMode = array('gif'=>'gif', 'png'=>'png', 'jpeg'=>'jpeg', 'wbmp'=>'vnd.wap.wbmp');
$this->codeMap = array(
'0'=>'010000101', '1'=>'100100001', '2'=>'001100001', '3'=>'101100000',
'4'=>'000110001', '5'=>'100110000', '6'=>'001110000', '7'=>'000100101',
'8'=>'100100100', '9'=>'001100100', 'A'=>'100001001', 'B'=>'001001001',
'C'=>'101001000', 'D'=>'000011001', 'E'=>'100011000', 'F'=>'001011000',
'G'=>'000001101', 'H'=>'100001100', 'I'=>'001001100', 'J'=>'000011100',
'K'=>'100000011', 'L'=>'001000011', 'M'=>'101000010', 'N'=>'000010011',
'O'=>'100010010', 'P'=>'001010010', 'Q'=>'000000111', 'R'=>'100000110',
'S'=>'001000110', 'T'=>'000010110', 'U'=>'110000001', 'V'=>'011000001',
'W'=>'111000000', 'X'=>'010010001', 'Y'=>'110010000', 'Z'=>'011010000',
' '=>'011000100', '$'=>'010101000', '%'=>'000101010', '*'=>'010010100',
'+'=>'010001010', '-'=>'000110100', '.'=>'110000100', '/'=>'010100010'
);
}
public function build($text='', $showText=true, $fileName=null)
{
if (trim($text) <= ' ')
throw new exception('barCode::build - must be passed text to operate');
if (!$fileType = $this->outMode[$this->mode])
throw new exception("barCode::build - unrecognized output format ({$this->mode})");
if (!function_exists("image{$this->mode}"))
throw new exception("barCode::build - unsupported output format ({$this->mode} - check phpinfo)");
$text = strtoupper($text);
$dispText = "* $text *";
$text = "*$text*"; // adds start and stop chars
$textLen = strlen($text);
$barcodeWidth = $textLen * (2 * $this->bcThinWidth + 3 * $this->bcThickWidth) - $this->bcThinWidth;
$im = imagecreate($barcodeWidth, $this->bcHeight);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white);
$xpos = 0;
for ($idx=0; $idx<$textLen; $idx++)
{
if (!$char = $text[$idx]) $char = '-';
for ($ptr=0; $ptr<=8; $ptr++)
{
$elementWidth = ($this->codeMap[$char][$ptr]) ? $this->bcThickWidth : $this->bcThinWidth;
if (($ptr + 1) % 2)
imagefilledrectangle($im, $xpos, 0, $xpos + $elementWidth-1, $this->bcHeight, $black);
$xpos += $elementWidth;
}
$xpos += $this->bcThinWidth;
}
if ($showText)
{
$pxWid = imagefontwidth($this->fontSize) * strlen($dispText) + 10;
$pxHt = imagefontheight($this->fontSize) + 2;
$bigCenter = $barcodeWidth / 2;
$textCenter = $pxWid / 2;
imagefilledrectangle($im, $bigCenter - $textCenter, $this->bcHeight - $pxHt, $bigCenter + $textCenter, $this->bcHeight, $white);
imagestring($im, $this->fontSize, ($bigCenter - $textCenter) + 5, ($this->bcHeight - $pxHt) + 1, $dispText, $black);
}
$badMode = false;
if (!$fileName) header("Content-type: image/{$fileType}");
switch($this->mode)
{
case 'gif':
imagegif($im, $fileName);
break;
case 'png':
imagepng($im, $fileName);
break;
case 'jpeg':
imagejpeg($im, $fileName);
break;
case 'wbmp':
imagewbmp($im, $fileName);
break;
default:
$badMode = true;
}
imagedestroy($im);
if ($badMode)
throw new Exception("barCode: Unknown Graphics Type '{$this->mode}'");
}
}
?>
I did some testing and I, too, saw a lot of those same characters!
Perhaps an alternative method: Have your script output the desired CSV file, but in the 3rd field, make a URL. You could make a small script in var/export/sku.php:
<?php
require_once '../../app/Mage.php';
umask(0);
Mage::app();
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND);
if( isset($_GET['sku']) && strlen($_GET['sku']) > 5 ) {
header('Content-Type: image/jpeg');
$barcodeOptions = array('text' => $_GET['sku']);
$rendererOptions = array();
$imageResource = Zend_Barcode::draw(
'code39', 'image', $barcodeOptions, $rendererOptions
);
imagejpeg($imageResource);
} ?>
Then in your script, you have (sku),ean,http://yoursite.com/var/export/sku.php?sku=(sku) There is a way to have the spreadsheet load the images -- though I haven't done this personally, I have seen links displayed as embedded images.
My sample above outputs a code39 barcode, which is scannable. You can replace with your own image generation. This is why I asked if you saw barcodes, as I haven't output rendered images like this before.

Read Check Box, Radio Button Name and values from PDF using iText Sharp

I have a fillable PDF contains CheckBoxes and RadioButtons and TextBox.
How do i get the CheckBox Name and its value also how do we know that it is a checkbox / Radio Button?
i'm using iTextSharp and have look at my below code
PdfReader pdfReader = new PdfReader(FileName);
pdfReader.SelectPages("37");
MemoryStream oStream = new MemoryStream();
PdfStamper stamper = new PdfStamper(pdfReader, oStream);
AcroFields form = stamper.AcroFields;
if (form.Fields.Count() > 0)
{
IDictionary<string,AcroFields.Item> oDic= form.Fields;
foreach (string FieldName in oDic.Keys)
{
//FieldName - CheckBox name; i need to confirm that is a Checkbox...
}
foreach (AcroFields.Item oItem in oDic.Values)
{
// how do we get check box values
}
}
The following code may help you out, if you still need it. It only works for AcroForms
int BUTTON = 1;
int CHECK_BOX = 2;
int RADIO_BUTTON = 3;
int TEXT_FIELD = 4;
int LIST_BOX = 5;
int COMBO_BOX = 6;
PdfReader pdfReader = new PdfReader(path);
AcroFields af = pdfReader.AcroFields;
foreach (var field in af.Fields)
{
bool isRadio = RADIO_BUTTON == af.GetFieldType(field.Key));
}
Edit:
Also, field.Key is the name of the field and field.Value is the value at it.
For checkboxes, if(field.Value == "Yes") then it is selected... if it is anything else, it is not selected.
Edit:
And I just found how tro get Radio Button options, if you are needing them.
myKey k = new myKey(field.Key, af.GetField(field.Key), af.GetFieldType(field.Key));
if (k.isRadio())
{
try { k.options.AddRange(af.GetAppearanceStates(k.key)); }
catch { }
}
Keys.Add(k);
Radio buttons, checkbox and buttons are all actually the same type of field but with different flags set. You can see the flags in the PDF Spec section 12.7.4.2.1 Table 226.
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
For a given Field you want to get the Widgets associated with it. Usually this is just one but can be more so you should account for this.
PdfDictionary w = f.Value.GetWidget(0);
Button fields will have their field type (/Ft) set to /Btn so check for that
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN)) {continue;/*Skipping non-buttons*/ }
For the current Widget get the optional field flags (/Ff) value or use zero if it doesn't exist.
int ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
Then just some simple math:
if ((ff & ffRadio) == ffRadio) {
//Is Radio
} else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton)) {
//Is Checkbox
} else {
//Regular button
}
Below is a full-working C# WinForm 2011 app targeting iTextSharp 5.2.0 that shows off all of the above looking at a file called Test.pdf living on your desktop. Just add some logic to the conditionals to handle each button type.
using System;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
PdfReader reader = new PdfReader(testFile);
var fields = reader.AcroFields;
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
int ff;
//Loop through each field
foreach (var f in fields.Fields) {
//Get the widgets for the field (note, this could return more than 1, this should be checked)
PdfDictionary w = f.Value.GetWidget(0);
//See if it is a button-like object (/Ft == /Btn)
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN)) { continue;/*Skipping non-buttons*/ }
//Get the optional field flags, if they don't exist then just use zero
ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
if ((ff & ffRadio) == ffRadio) {
//Is Radio
} else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton)) {
//Is Checkbox
} else {
//Regular button
}
}
this.Close();
}
}
}
C# with System.Linq included
for radio buttons , get which option is selected from all the options in radio form, print also all the choice options by their specified name in Adobe Acrobat Pro
AcroFields fields = reader.AcroFields;
List<string> fldNames = new List<string>(fields.Fields.Keys);
if (fldNames.Count > 0) //am gasit cel putin un acroform
{
foreach (string fldname in fldNames)
{
int tip = fields.GetFieldType(fldname);
if (tip == 3) //choice / radio
{
Console.WriteLine("radio form");
string[] valori = fields.GetListSelection(fldname);
foreach (string s in valori)
Console.WriteLine(s + " ");
Console.WriteLine("selected from radio form options");
string[] valori2 = fields.GetAppearanceStates(fldname);
//Console.WriteLine(valori2.Length);
var val2 = (from string c in valori2
where (c.ToLower().CompareTo("off") != 0)
select c).ToList();
if (val2.Count > 0)
foreach (string s2 in val2)
Console.WriteLine(s2 + " ");
}
}
}

Resources