How can i set a session variable in jquery? - asp.net-mvc-3

Can anyone help me how to set a session variable in Jquery. Actually My requirement is like this:-
I am having a popup in html file. When i click the link, the popup opens. However, if i set the session expire , the popup should not open. So, when i click on the link, if session expires, the popup should not open but should redirect to targeted page. How can i do this?? My TL told me to google this but didn't found actually what i required. He suggested me to set session in Jquery. Is there any alternative for this?? As i am a newbie to Jquery, any code snippets are higly appreciated.please help me..

If you are needing to do this in .NET MVC you can do it as such. Below is a an example:
Controller:
if (Session["pageInitCounter"] == null)
{
Session["pageInitCounter"] = 1;
}
else
{
int counter = Convert.ToInt32(Session["pageInitCounter"]);
counter++;
Session["pageInitCounter"] = counter;
}
View:
#Html.Hidden("pageInitCounter", Session["pageInitCounter"])
Javascript:
alert($("#pageInitCounter").val());

You may try using localStorage like below.
$(document).ready(function() {
var notSeen = localStorage['seen'];
if (!notSeen) {
// open popup
localStorage['seen'] = "yes";
}
});
Alternatively, use may as well try using a hidden field for this purpose.
Please visit the below links for more information. This should satisfy your requirement
http://forums.asp.net/t/1499296.aspx
http://forums.asp.net/t/1672519.aspx/1

Related

Dynamics CRM form saving

I want to know if its possible in Dynamics to stop it from saving the last form you were in?
For example, I go to the main form of an entity, then go to the second form and Dynamics saves that I was last in the second form. I don't want it to do that - so that when i open a record i'll be navigated to the main form and not the second form.
So Dynamics' default behaviour is to save the last form you were in - I want to prevent it from doing that. I appreciate this is the way that Dynamics works but wanted to know if anybody has found any good workarounds.
Thanks :)
You could try to use the function Xrm.Page.ui.formSelector; OnLoad to dynamically set the form every time you load a record from the entity.
This user preference is stored for each Session by CRM in browser LocalStorageCache itself. Unfortunately this cannot be turned off by any User settings or System settings.
Read more
Use this snippet to navigate back to default Form that you want.
var form = Xrm.Page.ui.formSelector.getCurrentItem();
if (form != null) {
var formId = form.getId();
var formLabel = form.getLabel();
}
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items) {
var form = items[i];
var formId = form.getId();
var formLabel = form.getLabel();
if (formLabel == "Required Form Name") {
form.navigate();
return;
}
}

Getting session's remaining time for expiry in liferay

I am using liferay 6.1, In a particular jsp, when a session expires and when some button is clicked it loads the login page within the jsp instead of redirecting.
My code would look like this,
var liferaySession = Liferay.Session._currentTime;
if(liferaySession == '0'){
// reload page
}
else{
// navigate to othr page.
}
The same was working fine in liferay 5.
THnks in advance
I solved by using the following code.
Liferay.on('sessionExpired',
function(event) {
liferaySession = 0;
} );

ckeditor make dialog element readonly or disable

I need to be able to make the URL input field in the Link Dialog window readonly or disable it. The field gets populated when the user selects a file from the server.
Another user posted this link as a solution, http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.dialog.uiElement.html#disable but there is no example and I can't figure out how to implement it.
In the onLoad handler of the dialog you can disable it this way:
this.getContentElement("info", "url").disable();
this is what I ended up doing. I wrote it in my js file instead of the plugin file, but I dont think that would make a difference. I am using inline ckeditor version 4.0.2
CKEDITOR.on('dialogDefinition', function(event) {
var dialogName = event.data.name;
var dialogDefinition = event.data.definition;
//some code here
if(dialogName == 'flash'){ // flash dialog box name
//some code here
dialogDefinition.onShow = function () {
this.getContentElement("info","width").disable(); // info is the name of the tab and width is the id of the element inside the tab
this.getContentElement("info","height").disable();
}
}
});
You can disable url field by just one line
CKEDITOR.dialog.getCurrent().getContentElement('info','txtUrl').disable()
I got it. I added this.getInputElement().setAttribute( 'readOnly', true ); to the onload funciton in ckeditor\plugins\links\dialogs\link.js. Before I was adding it to ckeditor\_source\plugins\links\dialogs\link.js. I'd still like an example of how to use the CKEDITOR.ui.dialog.uiElement disable feature, if anyone has one.

Linking Directly to a Tab using Prototype

I'm using Magento to build a storefront - I'm not used to Prototype, but that's what they use by default, so I'm trying to play nice. I have used the tabs setup provided in the Modern theme (built by the Magento team), and I've integrated it into my theme and it works great.
Where I need help is in directly linking to a specific tab - I've created a tab to house the product reviews, and that works fine, but there are links higher up on the page that link to reviews - however, they are linking to another page, which I would rather not use. I'm not familiar with the prototype being used, and I don't know what the link would look like to link to the tab - I'd like the experience to be something similar to:
1) Click on the link
2) The reviews tab opens and the page moves you down to it - like a run-of-the-mill anchor.
The href value of the tab is simply:
javascript:void(0);
The javascript that runs the operation is this:
Varien.Tabs = Class.create();
Varien.Tabs.prototype = {
initialize: function(selector) {
var self=this;
$$(selector+' a').each(this.initTab.bind(this));
},
initTab: function(el) {
el.href = 'javascript:void(0)';
if ($(el.parentNode).hasClassName('active')) {
this.showContent(el);
}
el.observe('click', this.showContent.bind(this, el));
},
showContent: function(a) {
var li = $(a.parentNode), ul = $(li.parentNode);
ul.select('li', 'ol').each(function(el){
var contents = $(el.id+'_contents');
if (el==li) {
el.addClassName('active');
contents.show();
} else {
el.removeClassName('active');
contents.hide();
}
});
}
}
new Varien.Tabs('.product-tabs');
My guess is that I need to invoke the showContent function and just force it to use the reviews tab, but I'm not quite sure how to do this. If anyone could shed some light on it, I'd appreciate it.
Thanks.
Not entirely the right answer, ie it cheats a bit, but we solved this by using jQuery's 'click()' function to simulate the tab click.
ie
Gave the reviews tab title anchor an id of 'tab-reviews-tab' and in our link at the top of the page added the following JS:
jQuery('#tab-reviews-tab').click();
Obviously it would be silly to include jQuery just for this, but if you're using it for something else already, sticking to what you know can work!
If someone is still interested in a solution, here is a hint to the same question:
souce link http://www.magentocommerce.com/boards/viewthread/59930/#t262411
Hope this can help u.
The answer to your question is on gist and ipaste.
Here's this summary:
You need to save the Varien.Tabs object in a var so replace the new Varien.Tabs('.product-tabs'); with var csTabs = new Varien.Tabs('.product-tabs');
If you are only doing this one time just create link as such:
<a href="#" onclick="javascript:csTabs.showContent($$('#product_tabs_email_or_other_id a')[0]);" >The Link</a>
If you expect to do this often just add a new method to the Varien.Tabs (at line 75)
openTab: function(b) {
var controlledLink = $$("#"+b+" a")[0];
this.showContent(controlledLink);
}
Now your links work like this:
Email
Further Info

How to make full CKEditor re-initialization?

Please help me - I need to make full re-initialization of CKeditor. I don't want to make re-initialization of instances of CKeditor, but I want fully reload it. Is there any way to implement it?
I tried to made next:
delete window.CKEDITOR;
and then:
//clear for old sources
$('script[src*="/includes/contentEditor/ckeditor/"]').each(function() {
$(this).remove();
});
$('link[href*="/includes/contentEditor/ckeditor/"]').each(function() {
$(this).remove();
});
//load CKeditor again
contentEditor.loadjscssfile('/includes/contentEditor/ckeditor/ckeditor.js', 'js');
contentEditor.loadjscssfile('/includes/contentEditor/ckeditor/adapters/jquery.js', 'js');
My method loads editor but some plugins does not work after reloading. Thanks for any help!
I have plugins and I don't need to fully reinitialize CKEditor either, just instances, are you doing it properly?
To remove my instance (my textarea is referenced by ID txt_postMsg):
$('#btn_cancelPost').click(function(){
CKEDITOR.remove(CKEDITOR.instances.txt_postMsg);
$('#txt_postMsg').remove();
$('#cke_txt_postMsg').remove();
});
Then I re-create the textarea, and after a 50ms timeout I call the constructor with the textarea again, plugins reload fine. We have some pretty complex plugins for flash/image editing so maybe there's an issue with your plugin?
My version:
$$("textarea._cke").each(function(Z) {
if (typeof(CKEDITOR.instances[Z.id]) == 'undefined') {
CKEDITOR.replace(Z.id, { customConfig : "yourconfig.js"});
} else {
CKEDITOR.instances[Z.id].destroy(true);
CKEDITOR.replace(Z.id, { customConfig : "yourconfig.js"});
}
});
try something like
for(var instanceName in CKEDITOR.instances)
CKEDITOR.remove(CKEDITOR.instances[instanceName]);
CKEDITOR.replaceAll();
AlfonsoML
I use CKeditor for dynamically edit different part of site. When I click on some area of the site it shows popup with CKeditor with content of this area above this area. When I save it I destroy instance of this editor, but if while editing I use link plugin CKeditor can't show editor without page refreshing. Chrome says - Uncaught TypeError: Cannot call method 'split' of undefined, Mozilla - x.config.skin is undefined(I try to set config.skin and it show another error - z is undefined).
I hope the full re-init can help.
P.S. Sorry I can find how to answer on your comment...
I've been looking for a way to re-initialize the editor and the only solution that I end up is to delete the instance and create a new ID.
Here's my code.
var editor = 'myeditor'
var instance = CKEDITOR.instances[editor];
if(typeof instance != 'undefined')
{
instance.destroy();
$(".cke_editor_" + editor).remove();
//make a new id
editor = (Math.random().toString(36).substr(2, 10););
}
CKEDITOR.replace(editor,
{
}
It's not perfect but it works.
Hope this helps.
This is my solution:
var editor = CKEDITOR.instances[your_ckeditor_id];
editor.mode = 'source';
editor.setMode('wysiwyg');
OR
var editor = CKEDITOR.instances[your_ckeditor_id];
editor.setData(editor.getData());

Resources