releasing content by role within a D2L topic - javascript

I'm trying to release content by role within a topic in D2L's LMS. Is this possible using Javascript? Something like, "if {RoleName}=Student, then display this, else display that"...? I realize I can restrict/release content by role on a topic level, but I'm trying to do so within a topic and thus can't use release conditions. Any ideas?

You can control that functionality directly through the Content tool interface without needing to add in JavaScript. If you don't have access to that in Content, talk to your site administrator.

A roundabout way to do this would be to parse the QueryString to get the OU, then make a Valence request to find out the user role in the course. It would take a lot of work to get all the pieces connected for what seems like a really simple use case. This is the strategy I'm using for tools I've made that get embedded right in D2L pages.
If Replacement Strings worked properly then you could use a combination of them and JavaScript. But since the replacement happens at save time rather than render time in most places, they're really not usable for your scenario.
Desire2Learn Replace Strings in Content
Another option would be to create your own custom widget and put it on the course home page. Since Replacement Strings work properly in widgets, you could read the value of the {rolename} replacement string and store it in a cookie. Then, in your pages you would read the value of the cookie to create your conditionals.

Related

Add some characters to the end of URL

I use a WordPress theme that has a number of custom post types. When I search for these post types, in the results page, the display order is from the oldest post to the newest post, but I want the newer posts to be displayed first.
I didn't design this template, so I don't know how to code it.
I found that by putting orderby=new at the end of the URL of the site, the display order is fixed.
Is there a way to automatically add this phrase to the end of the URL when someone enters the results page?
The links are like this: mydomain.com/activites/?location_name=paris&location_id=&taxonomy%5Bst_tour_type%5D= to the phrase mydomain.com/activites/? It is constant in all searches and after that, it changes based on the term that the user searches for.
The word location is the post type and the rest of the parts that come in the url are taxonomy.
immediate answer:
Write the link to the page accordingly. All other solutions will require changing some of the code or settings.
From my understanding of your question the cleanest solution is probably just to include a link back to the page itself with an added &orderby=new
Label the link in a way that makes it obvious to the user what it does. In this case I would assume ordering some type of content by release or entry date.
recommended solution:
Change the script in way that makes that order the default. It seems to be what you ideally "want". But can't do. As implied by the question.
janky solution:
Add a redirect. It's the same thing I said before but automatic without user input. The only benefit to this is being able to avoid touching existing code. And apply to all users as default.
roundabout solution, that will make maintenance a nightmare long term:
Rewrite rules in your web server. If you don't have access to that: try .htaccess
But since this modifies the behavior in a not immediately obvious way if is missing. And this will be easily missed by merit of being a hidden file and this type of config override not always being allowed. This might lead to non intuitive problems in the future.

Get data from another HTML page

I am making an on-line shop for selling magazines, and I need to show the image of the magazine. For that, I would like to show the same image that is shown in the website of the company that distributes the magazines.
For that, it would be easy with an absolute path, like this:
<img src="http://www.remotewebsite.com/image.jpg" />
But, it is not possible in my case, because the name of the image changes everytime there is a new magazine.
In Javascript, it is possible to get the path of an image with this code:
var strImage = document.getElementById('Image').src;
But, is it possible to use something similar to get the path of an image if it is in another HTML page?
Assuming that you know how to find the correct image in the magazine website's DOM (otherwise, forget it):
the magazine website must explicitly allow clients showing your website to fetch their content by enabling CORS
you fetch their HTML -> gets you a stream of text
parse it with DOMParser -> gets you a Document
using your knowledge or their layout (or good heuristics, if you're feeling lucky), use regular DOM navigation to find the image and get its src attribute
I'm not going to detail any of those steps (there are already lots of SO answers around), especially since you haven't described a specific issue you may have with the technical part.
You can, but it is inefficient. You would have to do a request to load all the HTML of that other page and then in that HTML find the image you are looking for.
It can be achieved (using XMLHttpRequest or fetch), but I would maybe try to find a more efficient way.
What you are asking for is technically possible, and other answers have already gone into the details about how you could accomplish this.
What I'd like to go over in this answer is how you probably should architect this given the requirements that you described. Keep in mind that what I am describing is one way to do this, there are certainly other correct methods as well.
Create a database on the server where your app will live. A simple MySQL DB will work, but you could use anything. Create a table called magazine, with a column url. Your code would pull the url from this DB. Whenever the magazine URL changes, just update the DB and the code itself won't need to be changed.
Your front-end code needs some sort of way to access the DB. One possible solution is a REST API. This code would query the DB for the latest values (in your case magazine URLs), and make them accessible to your web page. This could be done in a myriad of different languages/frameworks, here's a good tutorial on doing something like this in Node.js and express (which is what I'd personally use).
Finally, your front-end code needs to call your REST API to get the updated URLs. This needs to be done with some kind of JavaScript based language. jQuery would make this really easy, something like this:
$(document).ready(function() {
$.Get("http://uri_to_your_rest_api", function(data) {
$("#myImage").attr("scr", data.url);
}
});
Assuming you had HTML like this:
<img id="myImage" src="">
And there you go - You have a webpage that pulls the image sources dynamically from your database.
Now if you're just dipping your toes into web development, this may seem a bit overwhelming. But I promise you, in the long run it'll be easier then trying to parse code from an HTML page :)

Sharepoint - How to: dynamic Url for Note on Noteboard

I'm quite new to SharePoint (about 1 week into it actually) and I'm attempting to mirror certain functionality that my company has with other products. Currently I'm working on how to duplicate the tasking environment in Box.com. Essentially it's just an email link that goes to a webpage where users can view an image and comments related to that image side by side.
I can dynamically load the image based on url parameters using just Javascript so that part is not a problem. As far as the comments part goes I've been trying to use a Noteboard WebPart, and then my desire is to have the "Url for Note" property to change dependent on the same URL parameter. I've looked over the Javascript Object Model and Class Library on MSDN but the hierarchy seems to stop at WebPart so I'm not finding anything that will allow me to update the Url for Note property.
I've read comments saying that there's a lot of exploration involved with this so I've tried the following:
-loading the javascript files into VisualStudio to use intellisense for looking up functions and properties in the SP.js files.
-console.log() on: WebPartDefinitionCollection, WebPartDefinition, WebPart, and methods .get_objectData(), get_properties() on all the previous
-embedding script in the "Builder" on the Url for Note property (where it says "click to use Builder" - I'm still not sure what more this offers than just a bigger textbox to put in the URL path)
I'm certain I've missed something obvious here but am gaining information very slowly now that I've exhausted the usual suspects. I very much appreciate any more resources or information anyone has and am willing to accept that I may be approaching this incorrectly if someone has accomplished this before.
Normally I'd keep going through whatever info I could find but I'm currently on a trial period and start school back up again soon so I won't have as much time with it. Apologies if this seems impatient, I'm just not sure where else to look at the moment.
Did you check out the API libraries like SPServices or SharepointPlus? They could help you doing what you want...
For example with SharepointPlus you could:
Create a Sharepoint List with a "Note" column and whatever you need to record
When the user goes to the page with the image you just show a TEXTAREA input with a SAVE button
When the user hits the SAVE button it will save the Note to the related list using $SP().list("Your list").add()
And you can easily retrieve the information (to show them to the user if he goes back to the page) with $SP().list("Your list").get()
If I understood your problem, that way it may be easier for you to deal with a customized page :-)

allowing guests and members of site to see who is online/logged in using ajax, php/pdo, css, html

I have searched all over the net, and can't find a solution to this. I have no experience in AJAX but know it will be needed to perform this function as I believe it would be better than just using pure javascript.
I have a list of members who registered on my site, list is on a separate page --> on that list for each member, there is either a green dot (signifies if member is online) and if the user is offline (grey dot shows). I have that as a placeholder at the moment using only css and html. The <online /> and <offline /> are within the <h2> tag almost like a <span> tag. Is there a way to auto-update this to show who is actually logged in/out in real-time and without using NodeJS and/or SocketIO?
The html looks like this:
<h2>Billy <online title="Online" /></h2>
Where the <online title="Online" /> will then display the green dot next to their name if online (logged in). If they are not logged in, the html should look like this:
<h2>Billy <offline title="Offline" /></h2>
Where the <offline title="Offline" /> will then display the grey dot next to their name if offline (logged out).
Like I also mentioned, I have no experience in AJAX but am pretty sure it's something I'd need to perform an auto-update/refresh time just for this section alone - so NOT for the entire page...And I am a little familiar with PHP, so I would base a query using SESSION_[ID] to see/gather information on who is logged in and who isn't.
If anyone could help, I'd greatly appreciate it, I've been searchin' for days on how to accomplish this and cannot find anything...
Demo of what I currently have: http://jsfiddle.net/tZpk6/
While I am not all JS fancy, the basics of this is to simply update a table in your database with the latest time that someone was logged in or performed an action - then when you are displaying the information about users, you simply query that table - anyone in say the last five or ten minutes who had some kind of activity is considered "Online" - and others... well aren't.
Your script can't really use session IDs - as they are unique and only visible to the user who is running the code. By that I mean, that although you might have a dozen users on your site, all of whom are using a session variable, they cannot interact with one another. Each user (and by that I mean the code running) can only access their own session variables. If you want them to be able to see each other, it has to be done via an intermediary device such as a database, or a file - or an actual application that is constantly running - written in Java or C# or the like, which is ALWAYS running and being passed data from the PHP code.
So basically, although you can apply AJAX to check constantly for the updates, the data in the background is pretty much always done via a simple table that you can implement either on page reload or get a bit fancier and check it on a regular basis via scripts running inside your page.

Adjust static value into dynamic (javascript) value possible in Sharepoint allitems.aspx page?

<SharePoint:SPDataSource runat="server" IncludeHidden="true" SelectCommand="<View><Query><OrderBy><FieldRef Name="EventDate"/></OrderBy><Where><Contains><FieldRef Name="lawyer_x0020_1"/><Value Type="Note">F. Sanches</Value></Contains></Where></Query></View>" id="datasource1" DataSourceMode="List" UseInternalName="true"><InsertParameters><asp:Parameter DefaultValue="{ANUMBER}" Name="ListID"></asp:Parameter>
SharePoint WSS 3.0
This codeline is just one line of the allitems.aspx of a sharepoint list item (SharePoint created it himself). It only displays items where lawyer 1 = F. Sanches. Before I start messing around with the .ASPX page I wonder if it possible to change F. Sanches (in the code) into a dynamical variable (from a javascript value or something else that can be used to place the javascript value in there dynamically). If I put any javascript code in the line it will not work.
P.S. Ignore ANUMBER part in code.
Let say to make it simple I have javascript variable like this (now static but with my other code it is dynamic). It would be an achievement if it would place a static javascript variable.
<SCRIPT type=text/javascript>javaVAR = "P. Janssen";</script>
Eventually I would like to filter with OR operator
If Yes --> how?
If No --> Thank you!
The easiest way to add a filter to a standard list view is to use query string filters - add
?FilterField1=Lawyer&FilterValue1=F. Sanches
to the url. If you are working with a note field, it probably won't work directly, but you may find it easier to set up a field that does work than to make the server side chages you would need to modify the query directly.
Another approach that might work would be adding filter web parts to the page - I haven't worked with those much myself, but in theory they should be able to do what you want.
I don't think JavaScript will work since JavaScript is client side and SPDataSource is server side.
However, you should be able to use a control via ControlParameter. There are good examples here and here. Once the parameters are working, OR operators will definitely be supported within the CAML of the SelectCommand.

Categories

Resources