How to pass parameters to local Prettydiff.com - javascript

I've downloaded a copy of PrettyDiff to embed in my own local application, so I can compare two AJAX loaded files that are in two variables.
Unfortunately, I can't seem to make prettydiff work. Here's how I try :
var example1 = getFile('exemple1.txt');
var example2 = getFile('exemple2.txt');
var output = prettydiff("/*prettydiff.com api.lang: 8, api.mode: diff, api.diffview: inline, api.source:example1, api.diff: example2 */");
document.getElementById("output").innerHTML = output[0];
All I get is "Error: Source sample is missing.".
I've also tried to make an "api" variable that I fill with the parameters, but that doesn't work either.
The documentation doesn't give any example on how to pass the parameters (options, source and diff texts).
Anyone knows ?

Ok, I found out a way to get it working. I still don't know the fuss about the parameters as comments as specified in the docs, but you can create a js object and pass all your parameters :
var api = new Object();
api.mode = "diff";
api.diffview = "inline";
api.lang = 8;
api.source = example1;
api.diff = example2;
var output = prettydiff(api);

You can use prettydiff option like this.
const prettydiff = require("prettydiff");
let options = prettydiff.options;
options.source = content_Old;
options.diff = content_New;
options.diff_format = "html";
options.lang = "script";
options.color = "white";
options.diff_space_ignore = false;
options.diff_view = "sidebyside";
options.lexer = "script";
options.sourcelabel = "Original File";
options.difflabel = "Updated File";
options.mode = "diff";
options.parse_format = "htmltable";
options.list_options = true;
options.crlf = false;
options.force_indent = true;
outputHtml = prettydiff();

Related

How to add CC using java script in ASP.net

function SendMail(to,body,sub)
{
var theApp ;
var theMailItem ;
var subject = sub;
var msg = body;
var theApp = new ActiveXObject("Outlook.Application")
var theMailItem = theApp.CreateItem(0);
theMailItem.to = to;
theMailItem.Subject = (subject);
theMailItem.Body = (msg);
theMailItem.send();
}
I'm using above code to send mails from the client machine, but in this i would like to add cc could anyone kindly help me on this or if there is any other methods to send mails from client side help is appreciated. Thanks in advance
The mail item has a CC property. Just set it before send.
theMailItem.CC = "carbon copy recipient goes here";
Also, have in mind that the property names are case sensitive. So change to to To and send to Send
var theApp = new ActiveXObject("Outlook.Application");
var objNS = theApp.GetNameSpace('MAPI');
var theMailItem = theApp.CreateItem(0);
theMailItem.cc = cc;
theMailItem.to = to;
theMailItem.Subject = (subject);
theMailItem.Body = (msg);
theMailItem.send();
I have added this line, var objNS = theApp.GetNameSpace('MAPI'); You should now be able to find the cc attribute.

JScript to Javascript Conversion

The code below is a web service call to ICEPortal which is in JScript.NET format. Currently Iceportal doesn't have a webservice call using javascript. Has anybody done this using javascript? I need your help to convert the code below to javascript format.
// JScript.NET
var h:ICEPortal.ICEWebService = new ICEPortal.ICEWebService();
var myHeader:ICEPortal.ICEAuthHeader = new ICEPortal.ICEAuthHeader();
myHeader.Username = "distrib#distrib.com";
myHeader.Password = "password";
h.ICEAuthHeaderValue = myHeader;
var brochure:ICEPortal.Brochure;
var ErrorMsg;
var result = h.GetBrochure("MyMappedID", ErrorMsg, brochure);
I think you just need to remove the type definitions (in bold below):
var myHeader :ICEPortal.ICEAuthHeader = new ICEPortal.ICEAuthHeader();)
No idea what the ICEPortal classes are, but if they are available to your Javascript in the global namespace, the following should work. I've added these stubs in for the ICEPortal to test and it works fine for me in Chrome.
You'll obviously want to remove the stubs.
// stubbing out ICEPortal(s)
ICEPortal = {};
ICEPortal.ICEWebService = function() { return true; };
ICEPortal.ICEAuthHeader = function() { return true; };
ICEPortal.ICEWebService.prototype.GetBrochure = function() { return true; };
// end stubbing ICEPortal(s)
var h = new ICEPortal.ICEWebService();
var myHeader = new ICEPortal.ICEAuthHeader();
myHeader.Username = "distrib#distrib.com";
myHeader.Password = "password";
h.ICEAuthHeaderValue = myHeader;
var brochure;
var ErrorMsg;
var result = h.GetBrochure("MyMappedID", ErrorMsg, brochure);

Get String Value of Blob Passed to e.parameter in Apps Script

I'm using this code to get a blob passed to a function:
function submit(e){
var arrayBlob = e.parameter.arrayBlob;
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
This is the error I get:
Execution failed: TypeError: Can not find getDataAsString function in
the Blob object.'arrayBlob'
How do I get the string value of this blob?
Here is my code:
function showList(folderID) {
var folder = DocsList.getFolderById(folderID);
var files = folder.getFiles();
var arrayList = [];
for (var file in files) {
file = files[file];
var thesesName = file.getName();
var thesesId = file.getId();
var thesesDoc = DocumentApp.openById(thesesId);
for (var child = 0; child < thesesDoc.getNumChildren(); child++){
var thesesFirstParagraph = thesesDoc.getChild(child);
var thesesType = thesesFirstParagraph.getText();
if (thesesType != ''){
var newArray = [thesesName, thesesType, thesesId];
arrayList.push(newArray);
break;
}
}
}
arrayList.sort();
var result = userProperties.getProperty('savedArray');
arrayList = JSON.stringify(arrayList);
var arrayBlob = Utilities.newBlob(arrayList);
Logger.log("arrayBlob #1 = " + arrayBlob.getDataAsString()); // Here it`s OK
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setWidth(550).setHeight(450);
var panel = app.createVerticalPanel()
.setId('panel');
panel.add(app.createHidden('arrayBlob', arrayBlob));
var label = app.createLabel("Selecione os itens desejados").setStyleAttribute("fontSize", 18);
app.add(label);
arrayList = JSON.parse(arrayList);
panel.add(app.createHidden('checkbox_total', arrayList.length));
for(var i = 0; i < arrayList.length; i++){
var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(arrayList[i][0]);
Logger.log("arrayList[i][0] = " + arrayList[i][0]);
Logger.log("arrayList[i] ====> " + arrayList[i]);
panel.add(checkbox);
}
var handler = app.createServerHandler('submit').addCallbackElement(panel);
panel.add(app.createButton('Submit', handler));
var scroll = app.createScrollPanel().setPixelSize(500, 400);
scroll.add(panel);
app.add(scroll);
mydoc.show(app);
}
function submit(e){
var arrayBlob = e.parameter.arrayBlob;
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
// Continues...
}
I'd like the solution worked with more than one user simultaneous using the script.
Update:
Add a global variable OUTSIDE of any function:
var arrayBlob = Utilities.newBlob("dummy data");
function showList(folderID) {
Code here ....
};
Check that the code has access to the blob:
function submit(e){
Logger.log("arrayBlob.getDataAsString(): " + arrayBlob.getDataAsString());
//More Code . . .
}
This solution eliminates the need of embedding a hidden element in the dialog box with a value of the blob.
You won't need this line:
panel.add(app.createHidden('arrayBlob', arrayBlob));
There are other changes I'd make to the code, but I simply want to show the main issue.
Old Info:
In the function showList(), the method getDataAsString() works on the blob named arrayBlob.
Logger.log("arrayBlob #1 = " + arrayBlob.getDataAsString()); // Here it`s OK
In the function, submit(), the same method does not work.
var arrayBlob = e.parameter.arrayBlob;
In the function showList(), the code is assigning a newBlob to the variable arrayBlob. So arrayBlob is available to have the getDataAsString() method used on it.
var arrayBlob = Utilities.newBlob(arrayList);
In the function, submit(), you are trying to pass the arrayBlob blob variable into the submit() function, and reference it with e.parameter.
If you put a Logger.log() statement in the submit() function.
function submit(e){
Logger.log('e: ' + e);
Logger.log('e.parameter` + e.parameter);
var arrayBlob = e.parameter.arrayBlob;
Those Logger.log statements should show something in them. If there is nothing in e.parameter, then there is nothing for the .getDataAsString() to work on.
It looks like you are putting the arrayBlob into a hidden panel.
panel.add(app.createHidden('arrayBlob', arrayBlob));
But when the object is getting passed to the submit(e) function, the arrayBlob might not be getting put into that object.
So, what I'm saying is, the:
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
Line may be perfectly good, but there is no arrayBlob there to work on. This hasn't fixed your problem, but do you think I'm understanding part of what is going on?
I'm not sure why you are using Blob's here at all, you could simply work with JSON instead.
However, if you have a reason to use Blobs, you can pass the JSON data through your form and create the Blob in your handler, as the modified code below does:
function showList(folderID) {
var folder = DocsList.getFolderById(folderID);
var files = folder.getFiles();
var arrayList = [];
for (var file in files) {
file = files[file];
var thesesName = file.getName();
var thesesId = file.getId();
var thesesDoc = DocumentApp.openById(thesesId);
for (var child = 0; child < thesesDoc.getNumChildren(); child++){
var thesesFirstParagraph = thesesDoc.getChild(child);
var thesesType = thesesFirstParagraph.getText();
if (thesesType != ''){
var newArray = [thesesName, thesesType, thesesId];
arrayList.push(newArray);
break;
}
}
}
arrayList.sort();
var result = UserProperties.getProperty('savedArray');
//get JSON data pass through form.
var arrayBlob = JSON.stringify(arrayList);
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setWidth(550).setHeight(450);
var panel = app.createVerticalPanel()
.setId('panel');
//include JSON Data in the form.
panel.add(app.createHidden('arrayBlob', arrayBlob));
var label = app.createLabel("Selecione os itens desejados").setStyleAttribute("fontSize", 18);
app.add(label);
panel.add(app.createHidden('checkbox_total', arrayList.length));
for(var i = 0; i < arrayList.length; i++){
var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(arrayList[i][0]);
Logger.log("arrayList[i][0] = " + arrayList[i][0]);
Logger.log("arrayList[i] ====> " + arrayList[i]);
panel.add(checkbox);
}
var handler = app.createServerHandler('submit').addCallbackElement(panel);
panel.add(app.createButton('Submit', handler));
var scroll = app.createScrollPanel().setPixelSize(500, 400);
scroll.add(panel);
app.add(scroll);
mydoc.show(app);
}
function submit(e){
var arrayBlob = Utilities.newBlob(e.parameter.arrayBlob);
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
// Continues...
}
In the method you were using originally, the Blob itself was never included in the form, you were simply passing the string "Blob" around.
This is because the function createHidden(name, value); expects two strings as parameters, so it calls ".toString()" on the arrayBlob object, which returns the string "Blob".

JSON get data (swf) to HTML5

So my swf file request an url request (pr2hub.com/get_player_info_2.php?name=NAME)
And my swf use this datas to change movieclip's frames, colors.
I converted it to HTML5, but It's not work.
Original SWF is work:
http://tulyita.hu/games/pr2setspreview.html?users=sothal
HTML5 not work:
http://tulyita.hu/games/pr2setspreview.swf.html?users=sothal
The errors:
The ActionScript class JSON is not supported.
The ActionScript method JSON.parse() is not supported.
Can someone help this with me? AS3 Flash Code:
var loadedDataType:String;
var allowedToLoad:Boolean = false;
var pr2loaderInfo:String;
var pr2data:Object;
function loadPR2data():void
{
var urlRequest:URLRequest = new URLRequest("http://pr2hub.com/get_player_info_2.php?name=" + userName);
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.load(urlRequest);
}
function completeHandler(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
pr2loaderInfo = loader.data;
pr2data = JSON.parse(loader.data);
loadRequest_function();
}
function loadRequest_function():void
{
loadHatFrame = pr2data.hat;
loadHatColor1 = pr2data.hatColor;
loadHatColor2 = pr2data.hatColor2;
loadHeadFrame = pr2data.head;
loadHeadColor1 = pr2data.headColor;
loadHeadColor2 = pr2data.headColor2;
loadBodyFrame = pr2data.body;
loadBodyColor1 = pr2data.bodyColor;
loadBodyColor2 = pr2data.bodyColor2;
loadFeetFrame = pr2data.feet;
loadFeetColor1 = pr2data.feetColor;
loadFeetColor2 = pr2data.feetColor2;
}
You need to import JSON first (add corelib.swc if not yet part of the project):
import com.adobe.serialization.json.JSON;
and then :
pr2data = JSON.decode( value );
You can find corelib here : https://github.com/mikechambers/as3corelib#readme

Use JScript to insert Price List on Quote onOpen in Microsoft Dynamics CRM 2011

Here is my code, I get an object error onLoad. Please help.
function Setlook()
{
var lookup = new Object();
var lookupValue = new Array();
lookup.id = "7b31D4D998-F124-E111-96C3-1CC1DEEA";
lookup.entityType = 1022;
lookup.name = "Default";
lookupValue[0] = lookup;
Xrm.Page.getAttribute(“pricelevelid”).setValue(lookupValue);
}
The code itself looks correct, but the GUID of the lookup doesn't. It doesn't have the right format nor does it have the right number of characters (32). Fixing that should eliminate the error.
Here is the proper syntax, the important thing is to have the correct .typename
function Setlook()
{
var value = new Array();
value[0] = new Object();
value[0].id = '{31D4D998-F124-E111-96C3-1CC1DEE8EC2D}';
value[0].name = 'Default';
value[0].typename = 'pricelevel';
Xrm.Page.getAttribute("pricelevelid").setValue(value);
}

Categories

Resources