How to change Element innerHtml to Dart SDK 0.7.1 - dart

I am using dart-message https://github.com/mkozhukh/dart-message. It has function
...
MessageBox(String text, String header, String css){
_box = new DivElement();
...
_box.onClick.listen(_clickHandler);
if (header != null)
html.write("<div class='dhtmlx_popup_title'>$header</div>");
html.write("<div class='dhtmlx_popup_text'><span>$text</span></div>");
html.write("<div class='dhtmlx_popup_controls'>");
}
String addButton(String text, String result){
if (html != null){
html.write("<div class='dhtmlx_popup_button' result='$result' ><div>$text</div></div>");
} else
throw new Exception(".addButton must be used before .show");
}
_clickHandler(Event event){
String result = event.target.attributes["result"];
if (result == null)
result = event.target.parent.attributes["result"];
hide(result); //<=== ERROR result alway return null
}
And
Future<String> show(){
if (html != null){
//finalize html initialization
html.write("</div>");
_box.innerHtml = html.toString(); //<===== ERROR after line : Removing disallowed attribute <DIV result="ok">
html = null;
}
...
}
...
How to change this code to SDK 0.7.1.
Thanks you very much.

I changed code
_box.innerHtml = html.toString();
==>
_box.setInnerHtml(html.toString(), treeSanitizer : new NullTreeSanitizer());
and it work.

Related

What should I return from MVC controller in case of an error to make sure DropZone will pick it up

I am using using DropZone JS with MVC. The ActionMethod that saves the images is using a try catch. Now what would I need to return from the ActionMethod in case of an error so the front end will pick that up and show the error mark to the user instead of showing everything went successful.
Is it built in with DropZone or do I need to bind it to event such as complete? If so, how?
An example of the DropZone JS complete event
this.on("complete", function (file, response) {
// If an error has occurred, mark the item as failed
if (response.code != 200){
}
// If it went through successful, show that to the user
if (response.code == 200){
}
});
If this would work, in MVC I could just return HttStatusCodeResult such as
return new HttpStatusCodeResult(HttpStatusCode.BadRequest) and return new HttpStatusCodeResult(HttpStatusCode.Ok)
UPDATED - ActionMethod
[HttpPost]
public ActionResult SaveImages()
{
bool isSavedSuccessfully = true;
string fName = "";
try
{
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
if (HttpPostedFileBaseExtensions.IsImage(file))
{
//Save file content goes here
fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\", Server.MapPath(#"\")));
string pathString = Path.Combine(originalDirectory.ToString(), "Temp");
var fileName1 = Path.GetFileName(file.FileName);
bool isExists = Directory.Exists(pathString);
if (!isExists)
Directory.CreateDirectory(pathString);
var path = string.Format("{0}\\{1}", pathString, file.FileName);
file.SaveAs(path);
_testRepository.EditMainPicture("test", pathString, "imageText", 1);
}
}
}
}
catch (Exception ex)
{
// TODO Add error logging!!
isSavedSuccessfully = false;
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
return new HttpStatusCodeResult(HttpStatusCode.Ok);
}
For some reason if anything else fails within this method, DropZone will not pick it up and it will mark as the file has been successfully uploaded. I want it to show an error if anything fails within the ActionMethod
You'll need to listen for the error event
An error occured. Receives the errorMessage as second parameter and if the error was due to the XMLHttpRequest the xhr object as third.
Example
dropzone.on("error", function(file, errorMesage, xhr) { ... });

Showing Error Value Cannot be null. While Adding Task from Gantt Chart for ASP.NET MVC with dhtmlxGantt

Showing Error Value Cannot be null. While Adding Task from Gantt Chart for ASP.NET MVC with dhtmlxGantt.
An exception of type ‘System.ArgumentNullException’ occurred in mscorlib.dll but was not handled in user code.
Additional Information :Value cannot be null
LINK : dhtmlx Link for Gantt Chart
Heres My Code :
public static List<GanttRequest> Parse(FormCollection form, string ganttMode)
{
// save current culture and change it to InvariantCulture for data parsing
var currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
var dataActions = new List<GanttRequest>();
var prefixes = form["ids"].Split(',');
foreach (var prefix in prefixes)
{
var request = new GanttRequest();
// lambda expression for form data parsing
Func<string, string> parse = x => form[String.Format("{0}_{1}", prefix, x)];
request.Mode = (GanttMode)Enum.Parse(typeof(GanttMode), ganttMode, true);
request.Action = (GanttAction)Enum.Parse(typeof(GanttAction), parse("!nativeeditor_status"), true);
request.SourceId = Int64.Parse(parse("id"));
// parse gantt task
if (request.Action != GanttAction.Deleted && request.Mode == GanttMode.Tasks)
{
//--HERE SHOWING ERROR VALUE CANNOT BE NULL--//
request.UpdatedTask = new GanttTasks()
{
GanttTaskId = (request.Action == GanttAction.Updated) ? (int)request.SourceId : 0,
Text = parse("text"),
StartDate = DateTime.Parse(parse("start_date")),
Duration = Int32.Parse(parse("duration")),
Progress = Decimal.Parse(parse("progress")),
ParentId = (parse("parent") != "0") ? Int32.Parse(parse("parent")) : (int?)null,
SortOrder = (parse("order") != null) ? Int32.Parse(parse("order")) : 0,
Type = parse("type")
};
}
// parse gantt link
else if (request.Action != GanttAction.Deleted && request.Mode == GanttMode.Links)
{
request.UpdatedLink = new GanttLinks()
{
GanttLinkId = (request.Action == GanttAction.Updated) ? (int)request.SourceId : 0,
SourceTaskId = Int32.Parse(parse("source")),
TargetTaskId = Int32.Parse(parse("target")),
Type = parse("type")
};
}
dataActions.Add(request);
}
// return current culture back
Thread.CurrentThread.CurrentCulture = currentCulture;
return dataActions;
}
}
I Referred to link provided above and done as stated. But while adding value its shows value cannot be null.
Try setting a default value for task.progress on the client side,
JS:
gantt.attachEvent("onTaskCreated", function(task){
task.progress = 0;
return true;
});
Client doesn't set the default value for progress property of a newly created task, so when you insert task on a backend progress value is null.
And since backend code doesn't validate the value, probably the error fires on this line:
Progress = Decimal.Parse(parse("progress")),
Setting a default value on the client, as shown above, or checking for null on the server should fix the issue

Display result matching optgroup using select2

I'm using select2 with Bootstrap 3.
Now I would like to know whether it is possible to display all optgroup items if the search matches the optgroup name while still being able to search for items as well. If this is possible, how can I do it?
The above answers don't seem to work out of the box with Select2 4.0 so if you're hunting for that, check this out: https://github.com/select2/select2/issues/3034
(Use the function like this: $("#example").select2({matcher: modelMatcher});)
function modelMatcher (params, data) {
data.parentText = data.parentText || "";
// Always return the object if there is nothing to compare
if ($.trim(params.term) === '') {
return data;
}
// Do a recursive check for options with children
if (data.children && data.children.length > 0) {
// Clone the data object if there are children
// This is required as we modify the object to remove any non-matches
var match = $.extend(true, {}, data);
// Check each child of the option
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
child.parentText += data.parentText + " " + data.text;
var matches = modelMatcher(params, child);
// If there wasn't a match, remove the object in the array
if (matches == null) {
match.children.splice(c, 1);
}
}
// If any children matched, return the new object
if (match.children.length > 0) {
return match;
}
// If there were no matching children, check just the plain object
return modelMatcher(params, match);
}
// If the typed-in term matches the text of this term, or the text from any
// parent term, then it's a match.
var original = (data.parentText + ' ' + data.text).toUpperCase();
var term = params.term.toUpperCase();
// Check if the text contains the term
if (original.indexOf(term) > -1) {
return data;
}
// If it doesn't contain the term, don't return anything
return null;
}
Actually found the solution by modifying the matcher opt
$("#myselect").select2({
matcher: function(term, text, opt){
return text.toUpperCase().indexOf(term.toUpperCase())>=0 || opt.parent("optgroup").attr("label").toUpperCase().indexOf(term.toUpperCase())>=0
}
});
Under the premise that the label attribute has been set in each optgroup.
Found a solution from select2/issues/3034
Tested with select2 v.4
$("select").select2({
matcher(params, data) {
const originalMatcher = $.fn.select2.defaults.defaults.matcher;
const result = originalMatcher(params, data);
if (
result &&
data.children &&
result.children &&
data.children.length
) {
if (
data.children.length !== result.children.length &&
data.text.toLowerCase().includes(params.term.toLowerCase())
) {
result.children = data.children;
}
return result;
}
return null;
},
});
A few minor changes to people suggested code, less repetitive and copes when there are no parent optgroups:
$('select').select2({
matcher: function(term, text, opt){
var matcher = opt.parent('select').select2.defaults.matcher;
return matcher(term, text) || (opt.parent('optgroup').length && matcher(term, opt.parent('optgroup').attr("label")));
}
});

Add Sales Tax Item using QBFC

Is there any way to add Sales Tax Item using QBFC?
Example:
Sales Tax A
4%
Sales Tax B
10%
I can add it easily from Quickbooks, but I need a way to add from external application using QBFC.
Any help will be greatly appreciated.
You can find a good example in the On Screen Reference.
At the top of the screen choose ItemSalesTaxAdd from the "Select Message" dropdown. From there click on the C# tab and you will see the following sample code:
//The following sample code is generated as an illustration of
//Creating requests and parsing responses ONLY
//This code is NOT intended to show best practices or ideal code
//Use at your most careful discretion
using System;
using System.Net;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Interop.QBFC10;
namespace com.intuit.idn.samples
{
public class Sample
{
public void DoItemSalesTaxAdd()
{
bool sessionBegun = false;
bool connectionOpen = false;
QBSessionManager sessionManager = null;
try
{
//Create the session Manager object
sessionManager = new QBSessionManager();
//Create the message set request object to hold our request
IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US",1,.0);
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
BuildItemSalesTaxAddRq(requestMsgSet);
//Connect to QuickBooks and begin a session
sessionManager.OpenConnection("","Sample Code from OSR");
connectionOpen = true;
sessionManager.BeginSession("", ENOpenMode.omDontCare);
sessionBegun = true;
//Send the request and get the response from QuickBooks
IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
//End the session and close the connection to QuickBooks
sessionManager.EndSession();
sessionBegun = false;
sessionManager.CloseConnection();
connectionOpen = false;
WalkItemSalesTaxAddRs(responseMsgSet);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error");
if (sessionBegun)
{
sessionManager.EndSession();
}
if (connectionOpen)
{
sessionManager.CloseConnection();
}
}
}
void BuildItemSalesTaxAddRq(IMsgSetRequest requestMsgSet)
{
IItemSalesTaxAdd ItemSalesTaxAddRq= requestMsgSet.AppendItemSalesTaxAddRq();
//Set field value for Name
ItemSalesTaxAddRq.Name.SetValue("ab");
//Set field value for BarCodeValue
ItemSalesTaxAddRq.BarCode.BarCodeValue.SetValue("ab");
//Set field value for AssignEvenIfUsed
ItemSalesTaxAddRq.BarCode.AssignEvenIfUsed.SetValue(true);
//Set field value for AllowOverride
ItemSalesTaxAddRq.BarCode.AllowOverride.SetValue(true);
//Set field value for IsActive
ItemSalesTaxAddRq.IsActive.SetValue(true);
//Set field value for ListID
ItemSalesTaxAddRq.ClassRef.ListID.SetValue("200000-1011023419");
//Set field value for FullName
ItemSalesTaxAddRq.ClassRef.FullName.SetValue("ab");
//Set field value for ItemDesc
ItemSalesTaxAddRq.ItemDesc.SetValue("ab");
//Set field value for TaxRate
ItemSalesTaxAddRq.TaxRate.SetValue(20.00);
//Set field value for ListID
ItemSalesTaxAddRq.TaxVendorRef.ListID.SetValue("200000-1011023419");
//Set field value for FullName
ItemSalesTaxAddRq.TaxVendorRef.FullName.SetValue("ab");
//Set field value for ExternalGUID
ItemSalesTaxAddRq.ExternalGUID.SetValue(Guid.NewGuid().ToString());
//Set field value for IncludeRetElementList
//May create more than one of these if needed
ItemSalesTaxAddRq.IncludeRetElementList.Add("ab");
}
void WalkItemSalesTaxAddRs(IMsgSetResponse responseMsgSet)
{
if (responseMsgSet == null) return;
IResponseList responseList = responseMsgSet.ResponseList;
if (responseList == null) return;
//if we sent only one request, there is only one response, we'll walk the list for this sample
for (int i=0; i<responseList.Count; i++)
{
IResponse response = responseList.GetAt(i);
//check the status code of the response, 0=ok, >0 is warning
if (response.StatusCode >= 0)
{
//the request-specific response is in the details, make sure we have some
if (response.Detail != null)
{
//make sure the response is the type we're expecting
ENResponseType responseType = (ENResponseType)response.Type.GetValue();
if (responseType == ENResponseType.rtItemSalesTaxAddRs)
{
//upcast to more specific type here, this is safe because we checked with response.Type check above
IItemSalesTaxRet ItemSalesTaxRet = (IItemSalesTaxRet)response.Detail;
WalkItemSalesTaxRet(ItemSalesTaxRet);
}
}
}
}
}
void WalkItemSalesTaxRet(IItemSalesTaxRet ItemSalesTaxRet)
{
if (ItemSalesTaxRet == null) return;
//Go through all the elements of IItemSalesTaxRet
//Get value of ListID
string ListID1 = (string)ItemSalesTaxRet.ListID.GetValue();
//Get value of TimeCreated
DateTime TimeCreated2 = (DateTime)ItemSalesTaxRet.TimeCreated.GetValue();
//Get value of TimeModified
DateTime TimeModified3 = (DateTime)ItemSalesTaxRet.TimeModified.GetValue();
//Get value of EditSequence
string EditSequence4 = (string)ItemSalesTaxRet.EditSequence.GetValue();
//Get value of Name
string Name5 = (string)ItemSalesTaxRet.Name.GetValue();
//Get value of BarCodeValue
if (ItemSalesTaxRet.BarCodeValue != null)
{
string BarCodeValue6 = (string)ItemSalesTaxRet.BarCodeValue.GetValue();
}
//Get value of IsActive
if (ItemSalesTaxRet.IsActive != null)
{
bool IsActive7 = (bool)ItemSalesTaxRet.IsActive.GetValue();
}
if (ItemSalesTaxRet.ClassRef != null)
{
//Get value of ListID
if (ItemSalesTaxRet.ClassRef.ListID != null)
{
string ListID8 = (string)ItemSalesTaxRet.ClassRef.ListID.GetValue();
}
//Get value of FullName
if (ItemSalesTaxRet.ClassRef.FullName != null)
{
string FullName9 = (string)ItemSalesTaxRet.ClassRef.FullName.GetValue();
}
}
//Get value of ItemDesc
if (ItemSalesTaxRet.ItemDesc != null)
{
string ItemDesc10 = (string)ItemSalesTaxRet.ItemDesc.GetValue();
}
//Get value of TaxRate
if (ItemSalesTaxRet.TaxRate != null)
{
double TaxRate11 = (double)ItemSalesTaxRet.TaxRate.GetValue();
}
if (ItemSalesTaxRet.TaxVendorRef != null)
{
//Get value of ListID
if (ItemSalesTaxRet.TaxVendorRef.ListID != null)
{
string ListID12 = (string)ItemSalesTaxRet.TaxVendorRef.ListID.GetValue();
}
//Get value of FullName
if (ItemSalesTaxRet.TaxVendorRef.FullName != null)
{
string FullName13 = (string)ItemSalesTaxRet.TaxVendorRef.FullName.GetValue();
}
}
//Get value of ExternalGUID
if (ItemSalesTaxRet.ExternalGUID != null)
{
string ExternalGUID14 = (string)ItemSalesTaxRet.ExternalGUID.GetValue();
}
if (ItemSalesTaxRet.DataExtRetList != null)
{
for (int i15 = 0; i15 < ItemSalesTaxRet.DataExtRetList.Count; i15++)
{
IDataExtRet DataExtRet = ItemSalesTaxRet.DataExtRetList.GetAt(i15);
//Get value of OwnerID
if (DataExtRet.OwnerID != null)
{
string OwnerID16 = (string)DataExtRet.OwnerID.GetValue();
}
//Get value of DataExtName
string DataExtName17 = (string)DataExtRet.DataExtName.GetValue();
//Get value of DataExtType
ENDataExtType DataExtType18 = (ENDataExtType)DataExtRet.DataExtType.GetValue();
//Get value of DataExtValue
string DataExtValue19 = (string)DataExtRet.DataExtValue.GetValue();
}
}
}
}
}
You can add each tax item as a line item. Make sure you set the invoice to a 0 tax, so tax is not calculated on top of tax.
You would have line item sales tax A and another line item sales tax B.

ScriptBundle not including other script depending on the ordering

I'm trying to combine all scripts into one.. I have two folders, the main folder 'scripts' and the other 'scripts/other'.
When I try:
BundleTable.Bundles.Add(new ScriptBundle("~/scripts/all").Include("~/Scripts/*.js", "~/Scripts/other/*.js"));
scripts from 'scripts/other' are not included.
but when I invert the order:
BundleTable.Bundles.Add(new ScriptBundle("~/scripts/all").Include("~/Scripts/other/*.js", "~/Scripts/*.js"));
it works!!
Someone can tell me why?
Can you try calling the IncludeDirectory methods directly and seeing if you see the same issue?
ScriptBundle("~/scripts/all").IncludeDirectory("~/Scripts", "*.js").IncludeDirectory("~/Scripts/other", "*.js"));
If this works, then it's possible we have a bug here.
I don't know what is happening, but this is the code inside the System.Web.Optimization.Bundle:
// System.Web.Optimization.Bundle
public Bundle Include(params string[] virtualPaths)
{
for (int i = 0; i < virtualPaths.Length; i++)
{
string text = virtualPaths[i];
Exception ex = Bundle.ValidateVirtualPath(text, "virtualPaths");
if (ex != null)
{
throw ex;
}
if (text.Contains('*'))
{
int num = text.LastIndexOf('/');
string text2 = text.Substring(0, num);
if (text2.Contains('*'))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, OptimizationResources.InvalidPattern, new object[]
{
text
}), "virtualPaths");
}
string text3 = "";
if (num < text.Length - 1)
{
text3 = text.Substring(num + 1);
}
PatternType patternType = PatternHelper.GetPatternType(text3);
ex = PatternHelper.ValidatePattern(patternType, text3, "virtualPaths");
if (ex != null)
{
throw ex;
}
this.IncludeDirectory(text2, text3);
}
else
{
this.IncludeFile(text);
}
}
return this;
}

Resources