# JavaScript
This guide will walk you through the basics of using some features of the CaSS Library in Javascript. We'll use the Developer Console in your web browser.
Links for distributions of the library may be found in the Links page inside the developer guide.
# Browser
- Navigate here (opens new window). Chrome is what this was built under, but any Javascript console should work. This sample page has the CaSS library loaded, meaning you'll be able to use it directly within the browser's console.
- Open the Developer Tools (F12) and switch to the Console.
- Clear the console using something resembling đ«.
- Type the following:
EcRepository.get(
"https://sandbox.cassproject.org/api/custom/data/schema.cassproject.org.0.2.Framework/ce4c0e41-f24c-407d-95af-047bfee429bf"
);
- After a few seconds, an object should appear on the console with the framework data. Browse the data a bit before continuing.
Now letâs do something a bit more interesting, and Create, Update, Read, then Delete a new competency.
- First, we need an identity to work under. Type the following:
EcIdentityManager.ids
- If the array has identities in it, youâre good to go (skip to step 5). If not, you need to log in.
m = new EcRemoteIdentityManager();
m.server = repo.selectedServer; //Sets the identity server endpoint to the repository endpoint
m.configureFromServer(console.log,console.log); //This retrieves username and password salts from the server.
- We can now begin the login process.
m.startLogin("test","test"); //Creates the hashes for storage and retrieval of keys.
m.fetch(console.log,console.log); //This retrieves the identities and encryption keys from the server.
- Now check again to make sure the identity is available for use.
EcIdentityManager.ids
- Now letâs instantiate a new competency.
c = new EcCompetency();
- Viewing the competency, we can see it has no owner, no id, nothing except for a type. This object is not ready to be saved. Letâs make it so.
c.generateId(repo.selectedServer); //This generates a new ID that sets the objectâs home to sandbox.
c.addOwner(EcIdentityManager.ids[0].ppk.toPk()); //This adds us as the owner.
c;
- An object isnât useful without data, so letâs populate it with some useful data.
c.name = "Creating Competencies by hand using CASS.";
c.description = "Subject can create competencies using CASS in the Javascript Console.";
- Lets examine our object one more time and then save it.
c;
c.save(console.log,console.log);
- Now navigate to your new objectâs URL (in a new tab!)
window.open(c.shortId());
- Finally, delete the object.
c._delete(console.log,console.log);
- Refreshing the tab, the object has been deleted. However, the object is versioned, so if you perform the following, it will continue to exist. Examine the difference between the IDs. Note that the version portion of the URL will update automatically upon save. (compare it to the ID in step 6)
c.id; // Refers to the the immutable version of the object at that version.
c.shortId(); // Refers to the latest version of the object.
window.open(c.id);
- Examine some of the other functions that exist and see how they operate.
f = new EcFramework();
f.addCompetency(c.shortId());
f;
# JavaScript Library
If you'd like to use the JavaScript library, there are several ways of obtaining (or linking to) it:
- GitHub (opens new window)
- A CDN (opens new window)
- NPM: npm install cassproject (opens new window)
Check out the Links page for a compilation of all relevant links in one location.
If youâre just looking to retrieve competencies or frameworks, here are some examples:
EcFramework.get("https://sandbox.cassproject.org/api/custom/data/schema.cassproject.org.0.2.Framework/ce4c0e41-f24c-407d-95af-047bfee429bf",
function(framework){
alert(framework.name);
},
function(error){
console.log(error);
}
);
EcCompetency.get("https://sandbox.cassproject.org/api/custom/data/schema.cassproject.org.0.2.Competency/onet:1.A.1",
function(competency){
alert(competency.name);
},
function(error){
console.log(error);
}
);
If you see the alert, youâre ready to go. Check out the other guides for more information.
â CaSS Installation Node.js â