Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 18th, 2016, 12:54 PM
randy.willey@efi.com randy.willey@efi.com is offline
Junior Community Member
 
Join Date: Apr 2009
Location: Ohio
Posts: 32
Default FusionPro Rule Template Updates

I have clients that use the Change Phone Format Rule template constantly. However, many of them need to convert the template to JavaScript and edit the base rule because two of the formatting options do not include a space between the area code and the phone number. Is there a way to modify the base rule in the template itself to include the space in these formats so that the JavaScript doesn't need to be updated every time the template is used?
Attached Images
File Type: png PhoneFormat.png (29.6 KB, 9 views)
Reply With Quote
  #2  
Old January 18th, 2016, 01:34 PM
dreimer dreimer is offline
Senior Contributor
 
Join Date: Oct 2010
Location: Shakopee, MN
Posts: 495
Default Re: FusionPro Rule Template Updates

I think you could add the JavaScript edited the way you want to the RulesTemplate JScript Script File.
__________________
Don Reimer - JavaScript Novice

MAC OS 10.14.6 Acrobat DC FP Creator 12.0.1
Reply With Quote
  #3  
Old January 18th, 2016, 03:04 PM
randy.willey@efi.com randy.willey@efi.com is offline
Junior Community Member
 
Join Date: Apr 2009
Location: Ohio
Posts: 32
Default Re: FusionPro Rule Template Updates

Thanks. Where is the RulesTemplate Script Script File located so that I can edit it?
Reply With Quote
  #4  
Old January 18th, 2016, 03:05 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 957
Default Re: FusionPro Rule Template Updates

Quote:
Originally Posted by randy.willey@efi.com View Post
I have clients that use the Change Phone Format Rule template constantly. However, many of them need to convert the template to JavaScript and edit the base rule because two of the formatting options do not include a space between the area code and the phone number. Is there a way to modify the base rule in the template itself to include the space in these formats so that the JavaScript doesn't need to be updated every time the template is used?
You shouldn't have to convert the entire rule and edit the original JavaScript code to add a space. You could simply create a "wrapper" rule to return the modified string:
Code:
return Rule("Change phone format Rule").replace(')', ') ');
I guess if you really wanted to, you could update the XML that creates that rule (though I would recommend creating a new file instead). In addition to making it a new "rule" I would also strongly recommend adding a checkbox to the rule to toggle the space rather than add the space to the source and end up in the same predicament when you decide a space isn't needed. The resulting file would be placed in "/Library/Application Support/PTI/FusionPro/Plug-ins/TemplateXML" on each of the machines you want to add the new rule to.

HTML Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<template_rule name="*MODIFIED* Change phone rule" version="1.0" type="text" taggedtext="false">
<rulename language="en-US">[MODIFIED] Change phone format Rule</rulename>
<rulename language="de">Regel zum Ändern des Telefonformats</rulename>
<rulename language="fr">Règle Changer le format téléphonique</rulename>
<rulename language="es">Regla Cambiar formato de teléfono</rulename>
<rulename language="it">Regola modifica formato numero di telefono</rulename>
<Comment language="en-US">This rule has been MODIFIED to change the value of a phone number field to a particular format of your choice.</Comment>
<Comment language="de">Mit dieser Regel wird der Wert eines Telefonnummernfeldes in ein Format Ihrer Wahl geändert.</Comment>
<Comment language="fr">Cette règle va changer la valeur d’un champ de numéro de téléphone en un format particulier de votre choix.</Comment>
<Comment language="es">Esta regla cambiará el valor del campo de un número de teléfono a un formato que usted elija.</Comment>
<Comment language="it">La regola consente di cambiare il valore di un campo numero di telefono in un campo con qualsiasi formato.</Comment>
<Description language="en-US">Please specify the appropriate values.</Description>
<Description language="de">Geben Sie die entsprechenden Werte an.</Description>
<Description language="fr">Veuillez spécifier les valeurs appropriées.</Description>
<Description language="es">Especifique los valores que correspondan.</Description>
<Description language="it">Specificare i valori appropriati.</Description>

<fieldlist>
  <field type="FIELDLIST" required="true">
    <fieldname>Var1</fieldname>
    <prompt language="en-US">Choose the phone field:</prompt>
    <prompt language="de">Feld "Telefon" wählen:</prompt>
    <prompt language="fr">Choisissez le champ de téléphone :</prompt>
    <prompt language="es">Elija el campo de teléfono:</prompt>
    <prompt language="it">Scegliere il campo telefono:</prompt>
    <value></value>
  </field>
   
 <field type="PICKLIST" subtype="ListBox" required="true">
     <fieldname>CaseSelection</fieldname>
     <prompt language="en-US">Choose the format:</prompt>
     <prompt language="de">Wählen Sie das Format:</prompt>
     <prompt language="fr">Choisissez le format :</prompt>
     <prompt language="es">Elija el formato:</prompt>
     <prompt language="it">Scegliere il formato:</prompt>
     <value></value>
    <picklist>
        <item><prompt>123.456.7890</prompt><value>Format 1</value></item>
        <item><prompt>123-456-7890</prompt><value>Format 2</value></item>
        <item><prompt>(123)456-7890</prompt><value>Format 3</value></item>
        <item><prompt>(123)456.7890</prompt><value>Format 4</value></item>
    </picklist>
 </field>
 
  <field type="CHECKBOX">
    <fieldname>includeSpace</fieldname>
    <prompt language="en-US">Space after area code when using parentheses?</prompt>
    <prompt language="de">De ruimte na het netnummer bij het gebruik van haakjes?</prompt>
    <prompt language="fr">Espace après le code de la zone lors de l'utilisation parenthèses?</prompt>
    <prompt language="es">¿Espacio después de código de área al utilizar paréntesis?</prompt>
    <prompt language="it">Spazio dopo prefisso quando si utilizza parentesi?</prompt>
    <value>0</value>
  </field>
	
</fieldlist>
	
<code>
	
	
if(CaseSelection == "Format 1")
{
var formatStyle01 = "$1.$2"; 			//simple 7 digit phone
var formatStyle02 = "$1.$2.$3";			//simple 10 digit phone
var formatStyle03 = "+$1 $2.$3.$4";		//10 digit phone starts with 1
var formatStyle04 = "$1.$2.$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 $2.$3.$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1.$2 ext.$3";		//7 digit phone with extension
	
var thisNumber = Field(Var1);
	
return formatNumber(Trim(thisNumber));
}
	
	
	
	
	
if(CaseSelection == "Format 2")
{
var formatStyle01 = "$1-$2"; 			//simple 7 digit phone
var formatStyle02 = "$1-$2-$3";			//simple 10 digit phone
var formatStyle03 = "+$1 $2-$3-$4";		//10 digit phone starts with 1
var formatStyle04 = "$1-$2-$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 $2-$3-$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1-$2 ext.$3";		//7 digit phone with extension
	
var thisNumber = Field(Var1);
	
return formatNumber(Trim(thisNumber));
}
	
	
	
	
	
if(CaseSelection == "Format 3")
{
var formatStyle01 = "$1-$2"; 			//simple 7 digit phone
var formatStyle02 = "($1)$2-$3";			//simple 10 digit phone
var formatStyle03 = "+$1 ($2)$3-$4";		//10 digit phone starts with 1
var formatStyle04 = "($1)$2-$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 ($2)$3-$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1-$2 ext.$3";		//7 digit phone with extension
	
var thisNumber = Field(Var1);
	
return formatNumber(Trim(thisNumber));
}
	
	
	
	
	
	
if(CaseSelection == "Format 4")
{
var formatStyle01 = "$1.$2"; 			//simple 7 digit phone
var formatStyle02 = "($1)$2.$3";			//simple 10 digit phone
var formatStyle03 = "+$1 ($2)$3.$4";		//10 digit phone starts with 1
var formatStyle04 = "($1)$2.$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 ($2)$3.$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1.$2 ext.$3";		//7 digit phone with extension
	
var thisNumber = Field(Var1);
	
return formatNumber(Trim(thisNumber));
}
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE ///////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
	
return formatNumber(Trim(thisNumber));
	
function formatNumber(number01){
	
var format = [formatStyle01,formatStyle02,formatStyle03,formatStyle04,formatStyle05,formatStyle06].map(function(s){ return includeSpace ? s.replace(')', ') ') : s; });

var pattern01 = /^(\d{3})[^\d]*(\d{4})$/;   						
//   //2201727 or 220-1727 or 220- 1727
	var pattern02 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;   				
// 8002201727 or 800-220-1727 or (800)220-1727 or (800) 220-1727
	var pattern03 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;   			
// 18002201727 or 1-800-220-1727 or +1 (800) 220-1727
	var pattern04 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;		
// 800-220-1727 ext 12345 or (800) 220-1727 ext 12345
	var pattern05 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;	
// 1-800-220-1727 ext 12345 or +1 (800) 220-1727 ext 12345
	var pattern06 = /^(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;   				
// 2201727 ext 1234 or 220-1727 ext 1234 or 220- 1727 ext 1234
	var patternEndExt = /(.)[x#n](.)/;
	var patternStart1 = /^[\D]*[1]/;
	
	if(number01.match(pattern01)){
		number01 = number01.replace(pattern01, format[0]);
		return number01;
	} else if(number01.match(pattern02)){
		number01 = number01.replace(pattern02, format[1]);
		return number01;
	} else if(number01.match(pattern03)){
		if (number01.match(patternStart1)){
			number01 = number01.replace(pattern03, format[2]);
			return number01;
		} else {
			return number01;
		}
	} else if(number01.match(pattern04)){
			number01 = number01.replace(pattern04, format[3]);
			return number01; 
	} else if(number01.match(pattern05)){
			number01 = number01.replace(pattern05, format[4]);
			return number01;
	}  else if(number01.match(pattern06)){
			number01 = number01.replace(pattern06, format[5]);
			return number01;
	} else {
		//return "no match any pattern";
		return number01;
	}	
}
	
	
	
	
	
</code>
</template_rule>
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #5  
Old January 18th, 2016, 03:22 PM
randy.willey@efi.com randy.willey@efi.com is offline
Junior Community Member
 
Join Date: Apr 2009
Location: Ohio
Posts: 32
Default Re: FusionPro Rule Template Updates

I located the RuleTemplates.English.js file. However, this file appears to only contain the base JavaScript for the rules of Type "JavaScript". None of the rules listed as "XML Template" are included, which is what the Change Phone Number Format rule is.
Reply With Quote
  #6  
Old January 18th, 2016, 03:58 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,671
Default Re: FusionPro Rule Template Updates

Quote:
Originally Posted by randy.willey@efi.com View Post
Thanks. Where is the RulesTemplate Script Script File located so that I can edit it?
The XML template rules aren't in the RuleTemplates.English.js file; they're in the TemplateXML folder. Its location is platform specific:
  • On Mac: /Library/Application Support/PTI/FusionPro/Plug-ins/TemplateXML
  • On Windows (64-bit): C:\Program Files (x86)\PTI\FusionPro\Plug-ins\TemplateXML
  • On Windows (32-bit): C:\Program Files\PTI\FusionPro\Plug-ins\TemplateXML
However, I don't recommend editing the files there. For one thing, if you re-install or install a new version of FusionPro, your changes will be overwritten. Instead, I recommend adding a new file in there. You can copy and paste the existing "Change phone format.xml" file with a new name; just remember that, in addition to the changes you want to make to the rule syntax, you need to also update the <template_rule> tag on line 2 to give the rule a unique name, perhaps something like "Randy's Change phone format Rule".
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; January 18th, 2016 at 04:03 PM..
Reply With Quote
  #7  
Old January 18th, 2016, 04:24 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,671
Default Re: FusionPro Rule Template Updates

Quote:
Originally Posted by step View Post
I would also strongly recommend adding a checkbox to the rule to toggle the space rather than add the space to the source and end up in the same predicament when you decide a space isn't needed.
Sure, although if you're going to do that, why not just have an option to specify the delimiter (dash, dot, or something else), and another option to specify whether to use parentheses for the area code, and then the option for the space? Frankly, there's a lot about our built-in XML template rule that could be improved; it's on my rainy day list.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #8  
Old January 18th, 2016, 05:12 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 957
Default Re: FusionPro Rule Template Updates

Quote:
Originally Posted by Dan Korn View Post
Sure, although if you're going to do that, why not just have an option to specify the delimiter (dash, dot, or something else), and another option to specify whether to use parentheses for the area code, and then the option for the space? Frankly, there's a lot about our built-in XML template rule that could be improved; it's on my rainy day list.
I suppose I'm just hesitant to alter those templates too much. (Though you could argue that simply adding a space to the replacement strings would have kept the code closer to the original than the changes that I made do.) But your comment reminded me of this gif.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #9  
Old March 3rd, 2016, 04:45 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: FusionPro Rule Template Updates

Great question, Randy!

As one of those clients of yours who use the phone format rule constantly - and constantly update it - I'm definitely going to make a new copy of the rule with our common formats. Thanks Don, Ste and Dan for the thoughts on how to go about it.
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:56 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.