Picture of Chuck Lorenz
Manually locking a menu item
by Chuck Lorenz - Wednesday, 16 August 2017, 3:44 PM
 

What is the best way to lock a menu item that should remain locked the duration of the course?

I have a client who has a plan for a project that includes about a dozen menu items. However, these items will be built in phases. Since the titles of these future topics are already finalized, the client has the desire to have the items appear in the menu. They will appear with styling that indicates they are “under construction,” and they will not be clickable.

I want to be able to mark contentObjects as “locked” via JSON in a location as logical as contentObjects.json. I want to avoid forcing a developer to jump into a javascript file in the future when these menu items are ready to be enabled. Almost all the functionality I require is available in Adapt’s locking model. I’d like to have all my styling based on the “locked” class. The piece that is missing (I believe) is being able to set the value of “_isLocked” from the contentObject. Should I add this javascript code? Or is there a clever and better way to invoke locking, say by adding an invisible dummy contentObject that is referenced in "_lockedBy" but that is unreachable/inaccessible? (I was unsuccessful in my attempts at this.)

I have experimented with adding the following attributes directly to the contentObject JSON:
"_isAvailable": false – removes the item completely; cannot be referenced in "_lockedBy"
"_isHidden": true – no effect; same as unlocked item
"_isEnabled": false – no effect; same as unlocked item

I am working in the framework with box-menu. Tracking course completion by an LMS is not a requirement.

Picture of Dan Storey
Re: Manually locking a menu item
by Dan Storey - Wednesday, 16 August 2017, 4:28 PM
 

Can you not simply add "_isLocked": true to the content object in the JSON file?

Picture of Matt Leathes
Re: Manually locking a menu item
by Matt Leathes - Wednesday, 16 August 2017, 4:42 PM
 

I was going to suggest this needed a bit of customisation but I think Dan's solution might do the job... certainly seems to work from an initial (not very thorough, mind!) test.

As an aside, should the first bullet point here not say 'true' rather than 'false'? It also seems a bit confusing having that first on that page, it feels more like it should be at the bottom in a section about 'Developing your own locking system'...

Picture of Chuck Lorenz
Re: Manually locking a menu item
by Chuck Lorenz - Wednesday, 16 August 2017, 5:32 PM
 

I failed to mention that I had tested "_isLocked": true.  In my project, it effects nothing. It does not lock the menu item; it does not add the "locked" class. Should it? Framework v2.1.3.

To me it is the logical code and logical location. Just didn't want to jump in and add code to the core if there was an established way achieving this.

Picture of Matt Leathes
Re: Manually locking a menu item
by Matt Leathes - Wednesday, 16 August 2017, 6:35 PM
 

It certainly worked fine for me using framework v2.1.3... it's a copy I downloaded towards the end of June specifically for testing out the odd thing like this. All I did was add "_isLocked": true to the entry for co-10 in contentObjects.json

One question - are you otherwise using locking in this project? I've only tested it when this is the only locking mechanism in place i.e. there's no _lockType property set in course.json or anywhere else.

Picture of Chuck Lorenz
Re: Manually locking a menu item
by Chuck Lorenz - Wednesday, 16 August 2017, 7:26 PM
 

This is encouraging.
The project was set up for me, so I have "inherited" some of the code base. My guess is that there is locking code in the menu that is interfering. But knowing the behavior that you and Dan report is default will make it easier to sort out.
Thank you.

Picture of Dan Storey
Re: Manually locking a menu item
by Dan Storey - Wednesday, 16 August 2017, 9:16 PM
 

If all else fails then this is a nice little hack!

Make sure you have "_lockType": "custom" in course.json

Then add "_lockedBy": ["id"] 

where "id" is the id of an article, block, or component contained within the locked content object - there'll be no way to unlock it then! :)

Picture of Chuck Lorenz
Re: Manually locking a menu item
by Chuck Lorenz - Thursday, 17 August 2017, 2:24 PM
 

Indeed my troubles were springing from attempting to use both "_isLocked": true and _lockType. By eliminating the use of _lockType (and _lockedBy), the expected behavior returned. Thanks for your help guys!

I have updated the wiki article to warn against mixing the two techniques.