How Can Set Icon for each node by c# Ajax Response in Jstree? - ajax

How Can Set Icon for each node by c# Ajax Response in Jstree?
in this line see Ajax jstree :
Webmethod is not fired by jsTree
the ajax jstree successfully run, but how can show Icon for each node ?
in this line :
_GG_JSTree.icons = ""; How Can set icons?
private static List<GG_JSTree> AddChildNodes(int _ParentID, int NumOfChildren, string ParentName)
{
List<GG_JSTree> GG_JSTreeArray = new List<GG_JSTree>();
int n = 10;
for (int i = 0; i < NumOfChildren; i++)
{
int CurrChildId = (_ParentID == 0) ? n : ((_ParentID * 10) + i);
GG_JSTree _GG_JSTree = new GG_JSTree();
_GG_JSTree.data = (_ParentID == 0) ? "root" + "-Child" + i.ToString() : ParentName + CurrChildId.ToString() + i.ToString();
_GG_JSTree.state = "closed"; //For async to work
_GG_JSTree.icons = ""; How Can set?
_GG_JSTree.IdServerUse = (int)CurrChildId;
_GG_JSTree.children = null;
_GG_JSTree.attr = new GG_JSTreeAttribute { id = CurrChildId.ToString(), selected = false };
GG_JSTreeArray.Add(_GG_JSTree);
n = n + 10;
}
return GG_JSTreeArray;
}

Take a look at the format spec:
https://github.com/vakata/jstree#the-required-json-format
The property name is icon, not icons.
( state should be an object, no a string, etc.
As for the icon property it is explained in the above link:
icon - a string which will be used for the node's icon - this can either be a path to a file, or a className (or list of classNames), which you can style in your CSS (font icons also work).
Basically - just take a deeper look at the docs and you should be fine.

try following
_GG_JSTree.icon = "glyphicon glyphicon-heart";
if u use bootstrap to show heart icon
'icon' defined in 'Type' plugin section may override this.

Related

How can I save and load textbox values, checkbox states, dropdown menu selections, etc., into a .txt file?

I am trying to implement a simple save-load function in my application, which would save the states of various GUI elements in my application (textboxes, checkboxes, dropdown menus, and so on) to a custom-named .txt file, and then load them back the next time user runs my application. I do not want to use My.Settings, because it is a portable application, and therefore the settings file has to be next to the executable. Also because my application is an editor, and the settings have to be bound by name to the current file the user is working with.
Write permissions is not an issue. I want to code this in a way so that I would only have to write down the names of the GUI elements to be mentioned once in my code, preferably in a list. Like this (pseudo-code):
'list
Dim ElementsToSave() as Object = {
Textbox1.text,
Checkbox1.Checked,
DropDownMenu1.SelectedItem,
.....
}
'save-load sub
Sub SaveLoad(Elements as Object, mode as string)
If mode = "save" then
For each Element in Elements
??? 'save each element state to .txt file
Next
If mode = "load" then
For each Element in Elements
??? 'load each element state from .txt file
Next
End if
End sub
'call
SaveLoad(ElementsToSave, "save")
'or
SaveLoad(ElementsToSave, "load")
I hope this conveys what I'm trying to achieve. Can anyone give any advice on how to make this work, please?
EDIT: I forgot to mention. It would be very nice if each value in the .txt file would be saved with a key that refers to a specific element, so that if I add more GUI elements in my application in the future, or re-arrange them, this save-load sub would always choose the correct value from the .txt file for a specific element.
using System.IO;
...
private enum ControlProperty
{
None = 0,
Text = 1,
Checked = 2,
SelectedValue = 3
}
private string GetSettingsFile()
{
FileInfo fi = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);
string path = Path.Combine(fi.Directory.FullName, "settings.txt");
return path;
}
private void test()
{
SaveSettings();
LoadSettings();
}
private void SaveSettings()
{
object[] vals = new object[] { this.Textbox1, ControlProperty.Text, this.Textbox1.Text, this.Checkbox1, ControlProperty.Checked, this.Checkbox1.Checked, this.Menu1, ControlProperty.SelectedValue, this.Menu1.SelectedValue };
string txt = "";
for (int i = 0; i < vals.Length; i += 3)
{
string controlID = (vals[i] as Control).ID;
ControlProperty property = (ControlProperty)vals[i + 1];
object state = vals[i + 2];
txt += controlID + ":" + property.ToString() + ":" + state.ToString() + "\n";
}
string file = GetSettingsFile();
File.WriteAllText(file, txt);
}
private void LoadSettings()
{
string file = GetSettingsFile();
string[] lines = File.ReadAllLines(file);
foreach (string s in lines)
{
string[] parts = s.Split(':');
if (parts.Length < 3) continue;
string id = parts[0];
var c = this.form1.FindControl(id);
ControlProperty prop = ControlProperty.None;
Enum.TryParse<ControlProperty>(parts[1], out prop);
string state = parts[2];
if (c is TextBox && prop == ControlProperty.Text)
{
TextBox t = c as TextBox;
t.Text = state;
}
else if (c is CheckBox && prop == ControlProperty.Checked)
{
CheckBox chk = c as CheckBox;
chk.Checked = state == "True";
}
else if (c is Menu && prop == ControlProperty.SelectedValue)
{
Menu m = c as Menu;
foreach (MenuItem menuItem in m.Items)
{
if (menuItem.Value == state)
{
menuItem.Selected = true;
}
}
}
}
}

How to change SharePoint List Views Style using CSOM Programmatically in C#

I have created list view using below code
ViewCreationInformation creationInfo = new ViewCreationInformation();
creationInfo.Title ="MyView";
creationInfo.RowLimit = 10;
creationInfo.ViewFields = viewFields.ToArray();
creationInfo.ViewTypeKind = "HTML";
viewCollection.Add(creationInfo);
context.ExecuteQuery();
I want to change the style using CSOM. But there is no option to change the style using client DLL.Though I tried to update ListViewXML is not getting updated.Kindly help me on this.
////Please add below code with your code
//// Update view style
/*
* 0-Basic Table
* 14-Document Details
* 15-Newsletter
* 16-Newsletter, no lines
* 17-Shaded
* 20-Preview Pane
*/
ViewCollection oView = list.Views;
int styleId = 17;
foreach (View v in oView)
{
if (v.Title == "MyView")
{
ctx.Load(v);
ctx.ExecuteQuery();
XmlDocument doc = new XmlDocument();
doc.LoadXml(v.ListViewXml);
XmlElement element = (XmlElement)doc.SelectSingleNode("//View//ViewStyle");
if (element == null)
{
element = doc.CreateElement("ViewStyle");
element.SetAttribute("ID", styleId.ToString());
doc.DocumentElement.AppendChild(element);
}
else
{
element.SetAttribute("ID", styleId.ToString());
}
v.ListViewXml = doc.FirstChild.InnerXml;
v.Update();
ctx.ExecuteQuery();
break;
}
}

Get variable from web page with javascript in C++ Builder

I have a MiFi modem (Huawei e5776) which comes with its own web page that displays total traffic per month. I want to extract this value and display a meter in the icon tray. I'm sure this is possible in C++ Builder (or Delphi) but even though I'm pretty experienced in using C++ Builder, I am not in anything web related. Can someone give me some pointers how to do this? I assume I need to run the script and then extract the variable somewhere, how do I do this?
Thanks.
PS: I'd add the contents of the page but can't see a way to attach a document. Here's the first few lines..
// JavaScript Document
var g_monitoring_traffic_statistics = null;
var g_wlan_security_settings = null;
var g_wlan_basic_settings = null;
var g_connection_trafficresponse = null;
//Prefix string of ssid2 of Multi-SSID
var g_prefixWifiSsid = "ssid2_";
function getTrafficInfo(bit) {
var final_number = 0;
var final_str = "";
if(g_monitoring_dumeter_kb > bit) {
final_number = formatFloat(parseFloat(bit), 2);
final_str = final_number + " B";
}
else if(g_monitoring_dumeter_kb <= bit && g_monitoring_dumeter_mb > bit) {
final_number = formatFloat(parseFloat(bit) / g_monitoring_dumeter_kb, 2);
final_str = final_number + " KB";
}
else if(g_monitoring_dumeter_mb <= bit && g_monitoring_dumeter_gb > bit) {
final_number = formatFloat((parseFloat(bit) / g_monitoring_dumeter_mb), 2);
final_str = final_number + " MB";
}
else if(g_monitoring_dumeter_gb <= bit && g_monitoring_dumeter_tb > bit) {
final_number = formatFloat((parseFloat(bit) / g_monitoring_dumeter_gb), 2);
final_str = final_number + " GB";
}
else {
final_number = formatFloat((parseFloat(bit) / g_monitoring_dumeter_tb), 2);
final_str = final_number + " TB";
}
return final_str;
}
I suggest you to use a great html wrapper (named BCB HTML) for mshtml writed specially for C++Builder; With this wrapper you can execute java script inside C++ Builder cpp codes:
THTMLDocument document;
document.create();
document.write(
"<html><body><script>"
"function myFunc(n)"
"{"
"return n * n;"
"}"
"</script></body></html>");
document.parentWindow.execScript("alert(myFunc(3))", "javascript");
For your jscript:
String value = document.parentWindow.execScript("getTrafficInfo(1024)", "javascript");
Also it is possible to handle html events inside BCB, access html objects , ...
you can download it from here.
To use this source add html.cpp to your project.
If you use TWebBrowser to load a html page, you need just define document in global scope and write below code to connect/attach document variable to WebBrowser1->Document:
void __fastcall TForm1::WebBrowser1DocumentComplete(TObject *ASender,
const IDispatch *pDisp, const OleVariant &URL)
{
document.documentFromVariant(WebBrowser1->Document);
String value = document.parentWindow.execScript("getTrafficInfo(1024)", "javascript");
}

Applying rules in Telerik MVC Grid Filter

I'm using Telerik MVC Grid, and need to apply filter rules below, but it seems only apply to the first two column, and ignore all the rest of the columns.
Here JS Code : ( assume grid is $("#grid").data("tgrid") )
function extTelerikGridFilter(grid, value) {
if (!$.isArray(grid.columns)) throw "Error : First Parameter accept only array.";
var colLength = grid.columns.length - 1;
var filterText = "";
var tempArr = new Array();
for (var i = 0; i < grid.columns.length; i++) {
filterText = filterText + "substringof({0},'{1}')".replace("{0}", grid.columns[i].member).replace("{1}", value);
if (colLength > 0) {
filterText = filterText + "~or~";
colLength = colLength - 1;
}
}
console.log(filterText);
grid.filter(filterText);
}
Result of console.log(filterText) :
substringof(Doc_No,'Opriyandi')~or~substringof(Type,'Opriyandi')~or~substringof(Request_By,'Opriyandi')~or~substringof(Request_Date,'Opriyandi')~or~substringof(Department,'Opriyandi')~or~substringof(Plant,'Opriyandi')~or~substringof(Description,'Opriyandi')~or~substringof(IT_Support,'Opriyandi')~or~substringof(Status,'Opriyandi')
Look before and after applying the filters in attachment.
Is this some kind of bug or perhaps i did something wrong.. Thank You.
*Using Telerik MVC 2011.3.1229
*Please ask me if you need additional information regarding my issue. :)
Attachment :
- BeforeApplyingFilter.png
- AfterApplyingFilter
I had this problem too. After some experiments, I found that we should bracket every expression starting from the head.
So, your filter string would look like this:
(((((((((substringof(Doc_No,'Opriyandi'))~or~substringof(Type,'Opriyandi'))~or~substringof(Request_By,'Opriyandi'))~or~substringof(Request_Date,'Opriyandi'))~or~substringof(Department,'Opriyandi'))~or~substringof(Plant,'Opriyandi'))~or~substringof(Description,'Opriyandi'))~or~substringof(IT_Support,'Opriyandi'))~or~substringof(Status,'Opriyandi'))
You can modify your code:
..
for (var i = 0; i < grid.columns.length; i++) {
--> filterText = "(" + filterText + "substringof({0},'{1}')".replace("{0}", grid.columns[i].member).replace("{1}", value) + ")"; <--
if (colLength > 0) {
filterText = filterText + "~or~";
colLength = colLength - 1;
}
..
PS I'm using 2011.3.1306
PS2 I wrote the article about custom filtering - please see link.

A Dual Ajax ListBox

Do you guys know of any .net controls with 2 listboxes that can move items from left to right and vice versa?!
Like a dual listbox type of thing.
I have already looked at http://ajaxlistbox.codeplex.com/ it seems to be pretty sweet.
just want to know any suggestions.
Here's a way:
Make two ListBoxes, the first shows all available item, the second shows what the user chooses. You also need a TextBox to hold a copy of the chosen items, since it is not possible to retrieve ListBox items in C# if they were added via javascript. Make the TextBox hidden, so the user cannot accidentally mess up the items.
Click an item in the first listbox and it appears in the second "chosen" listbox. Click on chosen item in the second list and it disappears. You could alter this so items are removed from the first list after being chosen.
I call AddJavascript from my Page_Load method.
ListBoxFilteredProfiles is my first TextBox, ListBoxSelectedProfiles is the second.
private void AddJavascript()
{
// This javascript function adds the item selected in one listbox to another listbox.
// Duplicates are not allowed, items are inserted in alphabetical order.
string OnChangeProfileListBoxJavascript =
#"<script language=JavaScript>
<!--
function OnChangeSelectedProfiles()
{
var Target = document.getElementById('" + ListBoxSelectedProfiles.ID + #"');
var Source = document.getElementById('" + ListBoxFilteredProfiles.ID + #"');
var TB = document.getElementById('" + TextBoxProfiles .ID + #"');
if ((Source != null) && (Target != null)) {
var newOption = new Option(); // a new ListItem
newOption.text = Source.options[ Source.options.selectedIndex ].text;
newOption.value = Source.options[ Source.options.selectedIndex ].value;
var jj = 0;
for( jj = 0; jj < Target.options.length; ++jj ) {
if ( newOption.text == Target.options[ jj ].text ) { return true; } // don't add if already in the list
if ( newOption.text < Target.options[ jj ].text ) { break; } // add the new item at this position
}
for( var kk = Target.options.length; kk > jj; --kk ) { // bump the remaining list items up one position
var bumpItem = new Option();
bumpItem.text = Target.options[ kk-1 ].text; // copy the preceding item
bumpItem.value = Target.options[ kk-1 ].value;
Target.options[ kk ] = bumpItem;
}
Target.options[ jj ] = newOption; // Append the item in Target
if (TB != null) {
// Copy all the selected profiles into the hidden textbox. The C# codebehind gets the selections from the textbox because listbox values added via javascript are not accessible.
TB.value = '';
for( var jj= 0; jj < Target.options.length; ++jj ) { TB.value = TB.value + Target.options[ jj ].value + '\n'; }
}
}
}
// -->
</script> ";
// This javascript function removes an item from a listbox.
string OnChangeRemoveListBoxItemJavascript =
#"<script language=JavaScript>
<!--
function OnChangeRemoveProfile()
{
var Target = document.getElementById('" + ListBoxSelectedProfiles.ID + #"');
var TB = document.getElementById('" + TextBoxProfiles.ID + #"');
Target.remove( Target.options.selectedIndex );
TB.value = '';
// Copy all the selected profiles into the hidden textbox. The C# codebehind gets the selections from the textbox because listbox values added via javascript are not accessible.
for( var jj= 0; jj < Target.options.length; ++jj ) { TB.value = TB.value + Target.options[ jj ].value + '\n'; }
}
// -->
</script> ";
ClientScript.RegisterStartupScript( typeof(Page), "OnChangeSelectedProfiles", OnChangeProfileListBoxJavascript );
ClientScript.RegisterStartupScript( typeof(Page), "OnChangeRemoveProfile", OnChangeRemoveListBoxItemJavascript );
ListBoxFilteredProfiles.Attributes.Add("onchange", "OnChangeSelectedProfiles()" );
ListBoxSelectedProfiles.Attributes.Add("onchange", "OnChangeRemoveProfile()" );
}

Resources