How to work with Interlization concept in javascript or jQuery - javascript

In my project i am using Interlization by using spring mvc it's Working fine .But I want to show some alret() message to end user according to Selected Language .How i do this any one help me.I am using hidden Fields in my view layer but some performance issue is occur so any way to read properties file data by using javascript or jQuery

You can use nested objects. For example:
// Init a dictionary
var messages = {
en : {},
es : {}
};
// Populate
messages.en['welcome'] = 'welcome';
messages.es['welcome'] = 'bienvenido';
// Test
var lang = 'es';
alert(messages[lang]['welcome']);

Related

Alfresco javascript get custom DataList's properties

I have written one rule(execute script) on datalist, so that whenever any new item is added, it should send an email to the respective user.
In email I want to add custom properties value e.g. employee_first_name
I've tried to get datalist using
var dataLists = siteName.getContainer("dataLists");
But it gives an error as follows:
"getContainer" method is not available.
The script given in Alfresco javascript get custom DataList works perfectly in Javascript console.
Your siteName variable is probably a string, which does not have a method called "getContainer". That's why you are seeing that message.
Here's a code snippet that fetches the data list container object given a site ID (site short name):
var siteId = "jtp-test-site-1";
var siteInfo = siteService.getSite(siteId);
var dataLists = siteInfo.getContainer("dataLists");
print(dataLists.name);
Notice the use of the built-in root-scoped object, siteService, that fetches the site info for a given site.
You can run that in the JavaScript Console and it will output the name of that folder, which is "datalists".

Accessing objects/rows created in ASP.NET from Javascript

I create a table dynamically and add rows, labels etc to it.
I want to be able to access those rows to make either visible or hidden AND access labels to change content on the fly. So far the table and all info is created with no problem. I spent days trying to access the data from JS, but I keep getting NULL etc on objects using ALERT to test it. Here's a snippet example of my code...
ASP.NET (C#) code
mTable = new HtmlTable();
mTable.ID = "mTable";
aCell = new HtmlTableCell();
aLabel = new Label();
aLabel.ID = "aLabel";
aLabel.Text = "TEST";
aCell.Controls.Add(aLabel);
aRow = new HtmlTableRow();
aRow.ID = "r" + x;
aRow.Cells.Add(aCell);
mTable.Controls.Add(aRow);
Ive put the following code in a SCRIPT FILE etc and ive tried many styles.
alert(document.getElementById('<%=aLabel.ClientID%>'));
If you are using plain vanilla javascript, please look at the code sample here: How do I iterate through table rows and cells in javascript?
The code sample in the above link gets the table by id, which in your case is 'mTable' (from your c# code)
var table = document.getElementById('mTable');
// will return you a reference to the table object on the page
You also have to place the code to call your javascript function that accesses data on the 'mTable' on the document load event

Creating a drop down list in asp.net mvc3

I am working on Simple Web Application using asp.net MVC4
I wonder to know how to create a drop down list in asp.net mvc4
In my application , I don't wanna use "ID_Sous_Type " but I wanna load a list from "Sous_Type" class
http://i.stack.imgur.com/qf1C4.jpg
I wrote this code in my index method :
var GenreLst = new List<string>();
var GenreQry = from d in secdb.SousTypes
orderby d.ID_Sous_Type
select d.Nom_Sous_Type;
GenreLst.AddRange(GenreQry.Distinct());
ViewBag.types = new SelectList(GenreLst); //Can't load this
In my View :
#Html.DropDownList("types")
UPDATE !
I am working on a form to retrieve data and save it in my table
I have two tables , Task and TaskType
For Task , The creation page is being like that .
http://i.stack.imgur.com/qf1C4.jpg
For the last field "ID_Sous_Type" , I would like to load list (from other table TaskType) to give a good user interface where the user can choose an appropriate type in better way (giving ID_Sous_Type is not that understandable )
For that , I would like to load the names of (TaskType) in Dropdown List
In my index controller :
I created .
var GenreLst = new List();
//Here i got all the names from TaskType table
var GenreQry = from d in secdb.SousTypes
orderby d.ID_Sous_Type
select d.Nom_Sous_Type;
GenreLst.AddRange(GenreQry.Distinct());
Then I added Ranges to easily get it
but I couldn't "Bind" it in Dropdown list , I wonder to know HOW !!
If i understand correctly your ViewBag.types is missing some vital information and that's why it's returning your list. It should be something like :
ViewBag.GenreId = new SelectList(db.Genres, "GenreId","Name");
See this article on the official .net site it should help you understand dropdown lists better.
http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-5

Parameter passing between different JavaScript libraries

In my Application, I have a grid made in extjs, on click of every row I need to pass selected cell values of that row to another JavaScript library. So to do so, I am considering html as a bridge, if I can somehow get the value in html then I think passing rest won't be tough job. In this regard, I have couple of questions
Am I correct in the way of my thinking?
If so, can anyone suggest me how to pass parameters from extjs to html?
I am retrieving the cell values from Extjs grid using this code
var grid = Ext.getCmp('lineGridChart');
var selectedRecords= grid.getView().getSelectionModel().getSelection();
myWTN = selectedRecords[0].get('wtn');
myMOU = selectedRecords[0].get('avg');
myWING = selectedRecords[0].get('wing');
myPDU = selectedRecords[0].get('pdu');
I need to pass those values to d3 or a simple jquery.
You can use localstorage...
Or just:
myData = selectedRecords[0].getData();
Update:
myData = {
data: {},
set: function(data) {
myData.data = data;
// You jquery logik
}
};
myData.set(selectedRecords[0].getData());

Databinding to Windows 8 ListView

I'm having massive problems with databinding to a ListView in a Windows 8 app using Javascript.
Inside the "activated" event on default.js I have written some code to get some data from a web service and push it into an array. This bit works OK and the array is populated.
The problem I have is that the app won't recognise the data. I have this code in a page called inspections.html:
data-win-options="{itemTemplate: select('#imageTextListCollectionTemplate'),
itemDataSource: dataList.dataSource,
layout: {type: WinJS.UI.ListLayout}}
and then in the "activated" event I declare:
var dataList = new Array();
and push the data from the web service into this array. But at runtime I get an error that says something along the lines of "can't find dataSource on undefined dataList".
I've done some of the examples on the MS website and in one of them it creates a dummy dataset and references it from a namespace. I kinda think that what I'm missing here is a namespace too but I don't know what the namespace for default.js is. Or maybe I'm wrong and it's something totally different.
Please help - this is so fundamental (and should be easy) but I can't get my head around it.
Do you want to create datalist in HTML or javascript?
It seems you want to create it from JavaScript. Assuming that you have already pushed your data into array from your webservice, you only need to call:
var dataList = new WinJS.Binding.List(array);
now accessing dataList.dataSource is perfectly valid.
Also, to create the datalist you don't always need an array. You could probably start with an empty list and then keep inserting data directly into the data list from web services, like:
var dataList = new WinJS.Binding.List([]);
dataList.push(value1);
dataList.push(value2);
...
Hope it helps. Let me know if you have any more questions.
If you are getting troubled by assigning datasource in HTML side
Prefer js side like
var list = new WinJS.Binding.List(array here);
listView.itemDataSource = list.dataSource;
by using this you can easily go through the data which you are binding to ListView.

Categories

Resources