cancel
Showing results for 
Search instead for 
Did you mean: 

How can I disable the 'User Status' feature?

filmchris
Champ in-the-making
Champ in-the-making
I am trying to find the file which controls the display of the User Status update box in the user profile drop-down box at the top-right of the page ("What are you doing?").

The closest I've found is:
/{apache-tomcat}/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/header/header.inc.ftl

But when I remove the appropriate sections from this file, it renders my documentlibrary and sites drop-down in the header useless. And there are no errors in the alfresco.log when this happens, so it's nearly impossible to figure out what's going on.

I extended header.inc.ftl and performed the following replacements:

Replaced this:

<#if item.type = "user">
<li class="user-menuitem HEADER-MARKER">
   <#if user.properties.avatar??>
      <#assign avatar>${url.context}/proxy/alfresco/api/node/${user.properties.avatar?replace('://','/')}/content/thumbnails/avatar?c=force</#assign>
   <#else>
      <#assign avatar>${url.context}/res/components/images/no-user-photo-64.png</#assign>
   </#if>
   <a class="avatar" ${attrHref} tabindex="0"><img src="${avatar}" alt="avatar" /></a>
   <span class="user-status">
      <textarea id="${id}-statusText" tabindex="0">${userStatus?html}</textarea>
      <div id="${id}-statusTime" class="user-status-time" title="${userStatusTime?html}"></div>
      <div>
         <span id="${id}-submitStatus" class="yui-button yui-push-button">
            <span class="first-child">
               <button type="button" tabindex="0" title="${msg("header.submit-status.description")}"><span>${msg("header.submit-status.label")}</span></button>
            </span>
         </span>
      </div>
   </span>
</li>
<#else>
   <#assign attrTarget><#if item.type = "external-link">target="_blank"</#if></#assign>
<li><span ${attrStyle}><a ${attrTitle} ${attrHref} tabindex="0" ${attrTarget!""}>${msg(item.label!"")}</a></span>
   <#if item.type = "container"><@subMenu item /></#if>
</li>
</#if>
With this:

<#if item.type = "user">
<li class="user-menuitem HEADER-MARKER">
   <#if user.properties.avatar??>
      <#assign avatar>${url.context}/proxy/alfresco/api/node/${user.properties.avatar?replace('://','/')}/content/thumbnails/avatar?c=force</#assign>
   <#else>
      <#assign avatar>${url.context}/res/components/images/no-user-photo-64.png</#assign>
   </#if>
   <a class="avatar" ${attrHref} tabindex="0"><img src="${avatar}" alt="avatar" /></a>
</li>
<#else>
   <#assign attrTarget><#if item.type = "external-link">target="_blank"</#if></#assign>
<li><span ${attrStyle}><a ${attrTitle} ${attrHref} tabindex="0" ${attrTarget!""}>${msg(item.label!"")}</a></span>
   <#if item.type = "container"><@subMenu item /></#if>
</li>
</#if>

But no dice. The contents of the documentlibrary do not load with this modification in place – it's just a blank area. My "Sites" drop-down menu in the header also fails to work. I can load the site dashboard just fine, however.

I've tried removing one line at at time, restarting and checking, but no matter what I do, if I remove ANYTHING from that section the page fails to load properly. The user drop-down looks great, however - the status box and update button are gone.

I'm not sure if there's another file elsewhere that depends on something in this script, but I'm stuck. Any advice, suggestions or assistance would definitely be appreciated.

Thanks in advance.
Chris
4 REPLIES 4

mikeh
Star Contributor
Star Contributor
You'll need to remove the JavaScript code in header.js which controls that part of the UI.

Thanks,
Mike

katamanov
Champ in-the-making
Champ in-the-making
Hello!
I have removed the "User status" item, by removing appropriate item in share-config-custom.xml.
<!–<item type="user" id="status">{userprofilepage}</item>–>


<alfresco-config>
    <config replace="true">

        <header>
            <app-items>
               ….
               ….
               ….
            </app-items>
            <user-items>
                <item type="container" id="user" icon="" description="">
                    <container-group id="usermenu" label="">
                        <!–<item type="user" id="status">{userprofilepage}</item>–>
                        <item type="link" id="my-profile">{userprofilepage}</item>
                        <item type="link" id="change-password" condition="user.capabilities.isMutable">/user/change-password</item>
                        <item type="external-link" id="help">{share-help}</item>
                        <item type="link" id="logout" condition="!context.externalAuthentication">/dologout</item>
                    </container-group>
                </item>
            </user-items>
            <dependencies>
                <css src="/modules/create-site.css" />
                <css src="/modules/header/sites.css" />
                <js src="/modules/create-site.js" />
                <js src="/modules/header/sites.js" />
                <js src="/scripts/jsButton.js" />
            </dependencies>
        </header>
    </config>

</alfresco-config>

As the result a have an exception in header.js function  configureMyStatus: function Header_configureMyStatus()
Uncaught TypeError: Cannot read property 'value' of null header.js:350
Header_configureMyStatus header.js:350
Header_onReady header.js:136
Base_onReadyWrapper alfresco.js:7510
executeItem event-debug.js:1698
_tryPreloadAttach event-debug.js:1727
f yuiloader-debug.js:1113

in line
this._currentStatus = this.widgets.statusBox.value; 

i think is is a bug, because i used standard extension mechanism to switch off existing functionality, but someone forget to chech for null.
in my opinion code should be

this.widgets.statusBox = Dom.get(this.id + "-statusText");
if (this.widgetn.statusBox == null){
return;
}

So, How can I disable the "User Status" feature, without editing header.js file?
What i'm doing wrong?

boumbh
Champ in-the-making
Champ in-the-making
This issue is easy to solve on a 4.2.f, here is how I did.

<strong>Context:</strong> Alfresco 4.2.f, project Maven from the org.alfresco.maven.archetype:alfresco-amp-archetype:1.1.1 archetype, I put everything in the embedded JAR when possible.

Create a module extension for share (see this blog <a>http://blogs.alfresco.com/wp/developer/2013/09/04/customizing-the-share-header-menu-part-1/</a> for more details). Here is my extension file:

<em>src/main/resources/alfresco/site-data/extensions/my-custom-extension.xml</em>


<extension>
  <modules>
    <module>
      <id>Main module of my custom extension</id>
      <version>${project.version}</version>
      <auto-deploy>true</auto-deploy>
      <customizations>
        <customization>
          <!– Order matters here! target before source, always! –>
          <targetPackageRoot>org.alfresco</targetPackageRoot>
          <sourcePackageRoot>my-custom.main</sourcePackageRoot>
        </customization>
      </customizations>
    </module>
  </modules>
</extension>


In the share header of your module package, create this Javascript. It will be called after its equivalent (see header comment below).

<em>src/main/resources/alfresco/site-webscripts/my-custom/main/share/header/share-header.get.js</em>

<javascript>
/** Customization of the header menu
*
* CALLED AFTER: webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js
*
* The header menu is built after a Javascript model object. The model object
* itself is built in the original share-header.get.js
*
* In order to customize the header menu, this script modifies the model object.
*/

/* Example:
// Change home item link
var homeItem = widgetUtils.findObject(model.jsonModel, "id", "HEADER_HOME");
if (homeItem != null) {
   homeItem.config.targetUrl = "my-new-home";
}
*/

// Issue https://issues.alfresco.com/jira/browse/ALF-19930:
// The method deleteObjectFromArray provided by Alfresco does not work
// widgetUtils.deleteObjectFromArray(model.jsonModel, "id", "HEADER_XXX");
// The workaround consists in defining a function removeItemsFromHeaderMenu…
/**
* Run through a widgets model object containing the definition of the Share
* header menu and remove every item which id is in the itemIdArray list.
* @param obj          widgets model object containing the definition of
*                   the Share header menu
* @param itemIdArray   List of ids of items to be removed from obj
* @param wrappingArray   For internal use
* @param objIndex      For internal use
*/
function removeItemsFromHeaderMenu(obj, itemIdArray, wrappingArray, objIndex) {
   // Parameter checks
   if (obj === undefined || obj === null) return false;
   if (wrappingArray === undefined) wrappingArray = null;
   if (objIndex === undefined) objIndex = null;
   
   if (Object.prototype.toString.apply(obj) === "[object Object]") {
      // Check if the Object is of the items to remove:
      // - It must have an id which is in the itemIdArray list
      // - It must be inside an array (for structural reasons)
      //       wrappingArray = the array
      //       objIndex = the index of obj in wrappingArray
      var idInList = false;
      if (obj.hasOwnProperty("id")) {
         for (var i = 0; i < itemIdArray.length; i++) {
            if (itemIdArray === obj.id) {
               idInList = true;
               break;
            }
         }
      }
      if (idInList) {
         if (wrappingArray !== null && objIndex !== null) {
            // Remove obj (=wrappingArray[objIndex]) from the widgets model
            wrappingArray.splice(objIndex, 1);
         } else {
            logger.debug("Unexpected match outside of array structure: "
                        + jsonUtils.toJSONString(obj));
         }
      } else {
         for (var key in obj) {
            if (obj.hasOwnProperty(key)) {
               // Recursive call, down a level in the widgets model
               removeItemsFromHeaderMenu(obj[key], itemIdArray);
            }
         }
      }
   } else if (Object.prototype.toString.apply(obj) === "[object Array]") {
      // Backward iteration because we are slicing the obj array
      // Explanations: http://stackoverflow.com/questions/9882284/looping-through-array-and-removing-items-without-breaking...
      var i = obj.length;
      while (i–) {
         // Recursive call, down a level in the widgets model
         //       obj <- obj
         //       wrappingArray <- obj
         //      objIndex <- i
         // Therfore, obj == wrappingArray
         removeItemsFromHeaderMenu(obj, itemIdArray, obj, i);
      }
   }
}

/* Example: disable a lot of stuff
var itemsToRemove = [ "HEADER_TASKS", "HEADER_MY_FILES",
      "HEADER_SHARED_FILES", "HEADER_SITES_MENU", "HEADER_PEOPLE",
      "HEADER_USER_MENU_SET_STATUS", "HEADER_USER_MENU_PROFILE",
      "HEADER_USER_MENU_HELP", "HEADER_LEAVE_SITE", "HEADER_USER_STATUS" ];

// Display repository item only when the user is admin
if (!user.isAdmin) {
   itemsToRemove.push("HEADER_REPOSITORY");
   itemsToRemove.push("HEADER_SITE_CONFIGURATION_DROPDOWN");
}
*/

// Disable "User Status" feature
var itemsToRemove = [ "HEADER_USER_STATUS" ];

removeItemsFromHeaderMenu(model.jsonModel.widgets, itemsToRemove);
</javascript>

Note: I commented this Javascript for my own understanding, you still can remove the extra comments you don't use.

deepak1987
Star Contributor
Star Contributor
Hi,

copy share-header.lib.js in tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/share/imports folder and comment the code in getUserMenuWidgets() method as below:

<javascript>

/* *********************************************************************************
*                                                                                 *
* USER MENU WIDGETS                                                               *
*                                                                                 *
***********************************************************************************/

function getUserMenuWidgets()
{
   var userMenuWidgets = [
   
      // Disable getUserStatusWidget() method and "HEADER_USER_MENU_SET_STATUS" Widget
      /* 
      getUserStatusWidget(),

      {
         id: "HEADER_USER_MENU_SET_STATUS",
         name: "alfresco/header/AlfMenuItem",
         config:
         {
            id: "HEADER_USER_MENU_SET_STATUS",
            label: "set_status.label",
            iconClass: "alf-user-status-icon",
            publishTopic: "ALF_SET_USER_STATUS"
         }
      },
        */
      {
         id: "HEADER_USER_MENU_PROFILE",
         name: "alfresco/header/AlfMenuItem",
         config:
         {
            id: "HEADER_USER_MENU_PROFILE",
            label: "my_profile.label",
            iconClass: "alf-user-profile-icon",
            targetUrl: "user/" + encodeURIComponent(user.name) + "/profile"
         }
      }
   ];
   if (user.capabilities.isMutable)
   {
      userMenuWidgets.push({
         id: "HEADER_USER_MENU_PASSWORD",
         name: "alfresco/header/AlfMenuItem",
         config:
         {
            id: "HEADER_USER_MENU_CHANGE_PASSWORD",
            label: "change_password.label",
            iconClass: "alf-user-password-icon",
            targetUrl: "user/" + encodeURIComponent(user.name) + "/change-password"
         }
      });
   }
   userMenuWidgets.push({
         id: "HEADER_USER_MENU_HELP",
         name: "alfresco/header/AlfMenuItem",
         config:
         {
            id: "HEADER_USER_MENU_HELP",
            label: "help.label",
            iconClass: "alf-user-help-icon",
            targetUrl: getHelpLink(),
            targetUrlType: "FULL_PATH",
            targetUrlLocation: "NEW"
         }
      });
   if (!context.externalAuthentication)
   {
      userMenuWidgets.push({
         id: "HEADER_USER_MENU_LOGOUT",
         name: "alfresco/header/AlfMenuItem",
         config:
         {
            id: "HEADER_USER_MENU_LOGOUT",
            label: "logout.label",
            iconClass: "alf-user-logout-icon",
            targetUrl: "dologout"
         }
      });
   }
   return userMenuWidgets;
}

</javascript>



Now, to import this share-header.lib.js file in share-header.get.js file, copy share-header.get.js file in tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/share/header folder and import alfresco/web-extension/site-webscripts/org/alfresco/share/imports/share-header.lib.js file as shown below:


<javascript>

<import resource="classpath:alfresco/web-extension/site-webscripts/org/alfresco/share/imports/share-header.lib.js">

model.jsonModel = {
   rootNodeId: "share-header",
   services: getHeaderServices(),
   widgets: [
      {
         id: "SHARE_VERTICAL_LAYOUT",
         name: "alfresco/layout/VerticalWidgets",
         config:
         {
            widgets: getHeaderModel()
         }
      }
   ]
};


</javascript>


Refresh the Share Web Script from http://host-nameSmiley Tongueort-number/share/service/index or Restart the server.

Hope this helps.