Restricting The Viewing of Forms Per User - javascript

Please could someone assist with the following:
I'm trying to restrict the viewing of forms using bootstrap and Meteor. In other words, user A logs in and creates a simple (or 2, or 3...) form using a modal which then displays in the html on a panel. How do I ensure that when user B logs in, he only sees his particular forms and not "user A's" forms?
I haven't included any code as I haven't started working on this problem as yet.
Thank you.

That's something you need to deal with using your publications/subscriptions. See here and here for learning ressources.
Basically, what should happen is that when user A creates a form (or any object), you store it into a collection along with the user id (Meteor.userId()). You subscribe to a publication in your page where you send only the items belonging to the current user Id.
That should solve your problem, and make you ready for all the similar (and common) cases where you need to disclose selected information only, depending on the context or the user. Moreover, it means that your users will be able to find back the items they left in their previous sessions.

Related

Allowing user to rearrange entries in Django admin site and how to store that new custom order to survive page refresh?

I have HTML and JavaScript in place that allows a user to move Django database entries (displayed in a table) up and down. However, is there a way that I can store this new order that the user has customized so that it will show up any time the user navigates back to that specific page view? I think get_queryset is what is causing the page (after refreshing) to switch back to the basic filtering. But, I have no good ideas on how to override it or avoid it to accomplish this task. Any help would be much appreciated!
I would suggest using ready solutions: django-admin-sortable or django-admin-sortable2. As for me, I have successfully used second solution and it works. One important note about it is to run ./manage.py reorder my_app.models.MyModel after adding new order field as mentioned here.

Is it possible to use Javascript to temporarily store data while User adjusts, and then pass as Hash to Rails Controller?

At a high level, building an application that allows User to request Items from other Users located in the same county as the requesting User. User and Item are both models with associated databases.
On the request page, I'm trying to build 3 components.
1) A map that shows
A marker for each other User
When clicked on, the marker displays a popup that lists the Items that that User has. The requesting user can click on each Item to add it to the list of Items s/he would like to request
2) A set of search fields that allows the requesting user to filter the markers for Users and Items on the map, for example, perhaps by dates_available.
3) A "cart" (not literally since this is not about e-commerce) that shows the Items the requesting User has currently added, with a final submit button. Note, dates_available should not only be a search field, but also part of this Request
A not perfect example is this screenshot from Getaround:
I'm pretty new to coding in general, so always want to think through plugins, APIs, shortcuts, etc. The below is just for reference, but if you have comments on how to implement this better, PLEASE do tell me! Right now, I am currently thinking of using:
For the map:
Openlayers.org
Gmaps.js
For the search (which is really a filtering capability):
Ransack gem (https://github.com/activerecord-hackery/ransack)
THE KEY QUESTION
For the "cart" and the click Item to add to "queue" part, I realize that while I can do this in Rails purely, it might be less of a positive UX experience since the page would constantly re-render every time a new item were added, not to mention it'd potentially result in excessive pings to the database or records to be created. I'm thinking of using Javascript to basically make the "cart/queue" a staging area for temporary storage, where the User populates it with whatever Items s/he wants and edits as needed, but it's not until the final submit click that the entire group of Items is passed as a Hash to the Rails Controller to be saved.
Now, since I don't really know JS very well, any resources on how to do this (easy plug-in solutions, other considerations I may have missed) or if it's not possible (in which case pray tell) would be greatly appreciated.
Thanks!
You may try Javascript localStorage.
localStorage.myTempValue = "my temp value";
or
localStorage("key", "value");
You can store object:
var person = { name: "xxxxx", age: 35 };
localStorage.Person = person;
Hope my answer may trigger an idea in you!

block web parts in sharepoint from certain users

I'm looking to see if it's possible to block certain data in web parts from loading or showing for certain users?
I have a SharePoint page that was written in asp.net and JavaScript. What i have is a page that runs several queries and displays them as separate web parts. I would like to be able to block certain web parts that show financial information to only show for the managers group.
I am able to just hide the web part from showing at all but that isn't necessarily helpful.
any help at all would be greatly appreciated.
thank you!
I would create a hidden div that contains the users access level (or I guess you could use an array to hold / define unique users who should or shouldnt be able to to 'see' the parts)... then just write a function that reads the hidden field and based on the user who is viewing the page, show or hide the content based on the id of the web content element / part.
I would probably try to do this on the server side though before the content in question is sent to the dom.
good luck
A possible solution could be is to hide the webparts using audiences. Edit the page, edit the webpart, navigate to the properties, in the Advanced section you'll find something called "Target Audiences". Either use an existing audience (which you can create in the user profile service application) or enter a SharePoint group name (like the site members, of something alike 'managers'). Members of that group/audience will see the webpart then. Other users will not see the webpart.
Notice that this is not a security measurement. E.g. it's just preventing the rendering of the webpart, it's not preventing users from accessing the data if they know where it comes from.
Read more here: http://office.microsoft.com/en-us/sharepoint-server-help/target-content-to-specific-audiences-HA010169053.aspx

Save the state of page. Cookie or session?

I have a little web app (which only has 1 page) that allows user to input and select some options. The input texts and selections will be displayed in another div in the form of table. You may want to refer to the example here: http://jsfiddle.net/xaKXM/5/
In this fiddle, you can type anything and after you clicked submit it will get the text input and append them to another table #configtableTable
$('#labels #labelTable tr:last').after(addmore);
$('#configtable #configtableTable tr:last').after(displaymore);
I'm using cherrypy as a mini web server (and thus major codes are written in python) and i know that it has session here but i have no idea how to use it at all as the example given is not really what i want to see.
FYI, i'm not using PHP at all and everything is in a single page. i simply show and hide them. But I want the page to remain as showing #configtableTable and hiding #labelTable even after refresh. Note that the fiddle is just part of the web app which will only show all these after getting a reply from another device.
Not sure about cookie because all the links i've found seem broken. How about jQuery session? Is it applicable in my case? I need some examples of application though :(
okay, to conclude my questions:
1. can i save the page state after refresh? and how? which of the methods mention above is worth trying? is there any examples for me to refer? or any other suggestions?
2. can i simply DISABLE refresh or back after reaching a page?
Thanks everyone in advance :)
Don't disable Refresh and / or back navigation. It's a terrible idea - user's have a certain expectation of what actions those buttons will perform and modifying that leads to a bad user experience.
As for saving state, while you could use session or cookies, if you don't need that data server side, you can save the state on client side as well.
For example, you could use localStorage
Alternatively, you could create an object out of the data in the table, JSON.stringify() it and append it to the url like this: example.com#stateData.
In case of either option, at page load, you'd have to check if there is state data. if you find there is, then use it to recreate the table, instead of displaying the form.
The disadvantage of the first, is that not all browsers support localStorage.
The disadvantage of the second is that URLs have a length limit and so this solution won't necessarily work for you if you're expecting large amounts of data.
EDIT
It appears that Midori does support most HTML5 features including localStorage however, it's turned off by default.. (I'm trying to find a better reference). If you can, just point Midori to html5test to see what HTML5 features it supports.

How to uniquely identify a webpage in javascript not using the URL

I have a bit of an interesting situation.
I have an application that uses an MVC framework to deliver the view to the user.
This is great for the overall design perspective.
There is a wrinkle though.
At certain times a user could be doing something on a page and they would be required to go to another page to perform a look-up service. I need to be able to uniquely identify each page that they go to and I am not able to use the URL, because all the subsequent pages that I visit from the parent page have the same URL.
Just an fyi, I care about this because I'm attempting to store the last known scrolling position on each page in cookies.
Example -
They are working on Page A.
They click a link from A and they are taken to page B.
On Page B they enter some values and click Search which will query a DB
A list of results is returned.
They can then select to "Return Value" of one of those search results.
The value is then returned to Page A.
When I run the following on each page (A and B) -
alert("${channelUrl}");
They are an exact match!
What else can I do to determine what page I am on within my javascript without resorting doing any sort of server side AJAX calls etc...?
Is what I am asking even possible?
Currently I am attempting to solve this problem by counting up the number of text fields on the page and appending that to my cookie name. This is not ideal, especially if a user visits a page that happens to have the same number of text fields.
Thanks.
One common way to handle this sort of thing is to open the second page in a new window. With this approach the parent and child windows know which is which (the child refers to parent as window.opener, and the parent refers to the child via the return value of the open call) so there's no need to manage URLs or anything to keep track.
People often use the part of the url after # to keep track of where you are under the a single URL. This is built-in supported with My Section which takes you to the element with id "my-section", but you can use libraries that take control of this section of the URL in other ways.

Categories

Resources