Is there any way to get absolute WCMMode of the page? - aem

I am struggling with a problem which can be solved by getting absolute WCMMode of the page.
By absolute WCMMode, I mean the WCMMode independent of the components.
For example, generally if we try to get the WCMMode of a component then it returns "EDIT" only if the component is configurable at that page. If a component is not configurable at a particular page, then it returns WCMMode value as "PREVIEW".
> <%=WCMMode.fromRequest(slingRequest)%>
The problem can be solved by checking on the behaviour of sidekick. But this way is a bit risky.
> CQ.WCM.isSidekickReady() &&
> CQ.WCM.getContentWindow().CQ.WCM.areEditablesReady()
Is there any other way to get this problem solved?
Please share your ideas.

Generally in an authoring environment you should be able to get away by checking if a component is in Edit Mode or Preview Mode.
<%
WCMMode wcmMode = WCMMode.fromRequest(slingRequest)
if(wcmMode.equals(WCMMode.EDIT) || wcmMode.equals(WCMMode.PREVIEW))
{
// do your stuff.
}
%>
Other than this is no other way to determining the absolute WCMMode which you are looking for. It would be great if you can tell me your case and what you are looking for.

Related

Opening the VSC settings window from code

I'm working on a Visual Studio Code extension, where some settings are required for it to work properly. Right now, in case the user has forgotten something, I'm showing a warning message indicating this, and telling them to fix this property in the settings. I would, however, like to add a button that opens the settings page of that property.
However, after looking around for over an hour, I can't seem to find any support for this in the Api, or anyone else asking this question (which I find a bit weird?). If it really doesn't exist, I'd still expect at least 1 other person asking this somewhere, but as far as I can see there's absolutely nothing.
Is it possible to open the settings window (preferably even filtering them down to only my extension's properties/the one property that has to be filled in) from code?
Thanks in advance
I found it out myself after digging through the keybinds window. You can use the following to open the settings:
vscode.commands.executeCommand("workbench.action.openSettings2");
I did not, however, find how to pass a search query into it to open a specific place in the settings.
EDIT: You can use openSettings & add the search query as an extra argument to executeCommand. For example - if your property is defined as my.extension.property in package.json, you can use this:
vscode.commands.executeCommand("workbench.action.openSettings", "my.extension.property");

Get bean->id when in _headerModuleList.tpl (suiteCRM, SugarCRM CE)

I'm trying to adjust the nav bar at the very top when inside a specific bean, but I can't figure out how to read the current module name/bean->id
(or if it's even possible).
As a workaround I thought of indicating a custom header, but in meta we can only put custom headerTPL, example
$viewdefs[mod][DetailView][templateMeta][form][headerTpl] => 'custom/themes/SuiteP/tpls/headerModuleList_c.tpl',
But we can't indicate a custom headerMODULELIST it seems
Would appreciate your help
You can USE Jquery as well with ajax enabled or even ajax disabled modules. This is beneficial for you only if you need these values at Browser Side.
Anyhow,
Try these
$("input:hidden[name='record']").val()
$("input:hidden[name='module']").val()
For going more specific you can access it by Parent Form ID
$("form#formDetailView input:hidden[name='module']").val()
$("form#formDetailView input:hidden[name='record']").val()
For Server Side you can try this thing to get URL and you can parse it accordingly
$url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
In the end the only thing that worked for me is disabling the AjaxUI which loads the page partially and makes any sort of complex modification to the header navigation pretty difficult
Once disabled you can just call $_REQUEST in _headerModuleList.tpl to get all the details you need

Is there any way to find out whether we have opened page in Touch UI or classic UI in javascript

Is there any way to find out whether we have opened this page in Touch UI or classic UI in javascript
like we have in classic UI to find out whether page is in edit mode or design mode.
CQ.WCM.editMode
Please suggest.
If you are not restricting to determine ui mode within javascript, here are other ways:
If you have a model class for your component, check for this
condition:
AuthoringUIMode.TOUCH.equals(AuthoringUIMode.fromRequest(getRequest()))
To check from JSP, use this code:
Placeholder.isAuthoringUIModeTouch(slingRequest)
You can simply read the cookie value of cq-authoring-mode. It can either be CLASSIC or TOUCH.
var isTouch = $.cookie('cq-authoring-mode') === 'TOUCH'
The other way would be to look for an outstanding JS objects like Granite.UI. This might be painful in the future when the clientlib that created the object will be attached to the other mode (e.g. via an AEM hotfix or unconsciously during the development).
var isTouch = Granite.UI != null

GWT 2.7: Warn users they are using an unsupported browser

I recently upgraded my application to GWT 2.7 from GWT 2.5. This has caused me to drop support for IE6 and IE7.
I would like to provide users with IE6 or IE7 with a warning that their browser is outdated and will not work. At the moment if you go to the app with one of those browsers, you get a blank screen.
I know there are a couple ways that I could hack something together but I would rather use the GWT way, rather than some hack. Is there a GWT hook for unsupported browsers?
Option (hack) One
Drop this into my main.html:
if(document.documentMode === 6 || document.documentMode === 7){
myUnsupportedBrowserWarningFunction();
}
Potential problem with this is that if someone is using a browser that GWT doesn't recognise and I don't recognise (mobile opera? Some other browser), they will still get a blank page.
Option (hack) Two
GWT looks for the compiled JS here:
gwt/myApp/ASDFKLSDJFLSFDJSLDFJLSJDFSDES.cache.js
When someone is using an unsupported browser the following is requested (and is not found):
gwt/myApp/undefined.cache.js
It would be possible to create undefined.cache.js and put your unsupported browser code there. This is obviously a brittle solution and will break with future GWT updates.
Option Three
A recent patch (available in GWT 2.7) allows you to provide a default
permutation (e.g. safari) if GWT can not detect the browser and with
deferred binding you can display a warning that the provided app might not
work correctly as the browser is generally unsupported by GWT.
-- J.
Source
I don't want to set a default permutation for unsupported browsers. I want the site to not work and to display a warning. So this solution doesn't really provide what I am looking for.
Similar Questions & Posts
The same question was asked for an eariler version of GWT in 2009. I hope that GWT has added some kind of hook or best practice in the last 6 years.
More info on setting a default (fallback) permutation
You should be able to use onLoadErrorFn for that: https://code.google.com/p/google-web-toolkit/issues/detail?id=8135
<script>
function gwtLoadError(errMsg) {
// GWT app couldn't load, reason in errorMsg
}
</script>
<meta name="gwt:onLoadErrorFn" content="gwtLoadError">
or possibly onPropertyErrorFn:
<script>
function gwtPropError(propName, allowedValues, actualValue) {
if (propName == 'user.agent') {
// unsupported browser
}
}
</script>
<meta name="gwt:onPropertyErrorFn" content="gwtPropError">
(I don't think user.agent.runtimeWarning would help in this case, but maybe have a look)
There is an easy way:
Conditional Comments
<!--[if lt IE 8]>
<p>You are using an unsupportet browser. Please perform an update</p>
<![endif]-->
I think Option 3 may be the best one, but there is a problem: This will start the actual application (which still may be incompatible).
If this is an issue and you want a clear warning, you can rewrite the permutation selection script (You would need to update the script with the upcoming GWT releases)
You will need to copy this source:
https://gwt.googlesource.com/gwt/+/2.7.0/user/src/com/google/gwt/useragent/rebind/UserAgentPropertyGenerator.java
You could add something like:
$wnd.Location.replace('nosupported.html');
between line 90 and 91

Dynamically loaded javascript doesn't show in sources panel?

For example, I have an ajax request and it returns <script src='buggy.js'></script>.
Problem is, it doesn't show up in sources or resources panel. That means I can't do all the cool stuffs like adding breakpoint and inspecting the elements as they run.
I could only see the source of the js file under the Network panel.
Is there anyway to make chrome add them to the sources panel?
Or how do you guys go about debugging dynamically added scripts?
Using Canary.
I was having the same problem, and I found a workaround that is better than the deliberate exception. It does still require changing the code as opposed to just setting a breakpoint inside the chrome dev tools.
I tried using the "//# sourceURL=dynamicScript.js" that was suggested as a workaround by the OP, but it still wasn't showing up for me unless it already existed in my tabs from a previous time when it produced an exception.
Coding a "debugger;" line forced it to break at that location. Then once it was in my tabs in the Sources panel, I could set breakpoints like normal and remove the "debugger;" line.
Please refer to https://developer.chrome.com/devtools/docs/javascript-debugging#breakpoints-dynamic-javascript
(Original link is broken-- archived link below)
http://web.archive.org/web/20141016164821/https://developer.chrome.com/devtools/docs/javascript-debugging#breakpoints-dynamic-javascript ("Breakpoints in Dynamic JavaScript").