Wity

Untitled

Oct 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Copyright (C) 2005-2012 Alfresco Software Limited.
  3.  *
  4.  * This file is part of Alfresco
  5.  *
  6.  * Alfresco is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU Lesser General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * Alfresco is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public License
  17.  * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  
  20. /**
  21.  * @module DocumentLibrary
  22.  */
  23.  
  24. /**
  25.  * Table view extension of DocumentListViewRenderer component.
  26.  *
  27.  * @namespace Alfresco
  28.  * @class Alfresco.DocumentListTableViewRenderer
  29.  * @extends Alfresco.DocumentListViewRenderer
  30.  */
  31. (function()
  32. {
  33.    /**
  34.     * YUI Library aliases
  35.     */
  36.    var Dom = YAHOO.util.Dom,
  37.        Event = YAHOO.util.Event,
  38.        Anim = YAHOO.util.Anim;
  39.    
  40.    /**
  41.     * Alfresco Slingshot aliases
  42.     */
  43.    var $html = Alfresco.util.encodeHTML,
  44.       $isValueSet = Alfresco.util.isValueSet;
  45.    
  46.    var DND_CONTAINER_ID = 'ygddfdiv';
  47.    
  48.    /**
  49.     * TableViewRenderer constructor.
  50.     *
  51.     * @param name {String} The name of the TableViewRenderer
  52.     * @return {Alfresco.DocumentListTableViewRenderer} The new TableViewRenderer instance
  53.     * @constructor
  54.     */
  55.  
  56.    // -------------------------TOHLE
  57.  
  58.  
  59.  
  60. Alfresco.DocumentListTableViewRenderer = function(name, parentDocumentList, commonComponentStyle, jsonConfig) {
  61.       Alfresco.DocumentListTableViewRenderer.superclass.constructor.call(this, name, parentDocumentList, commonComponentStyle);this.actionsSplitAtModifier = 0;
  62. if (jsonConfig != null)
  63. {
  64.         this.jsonConfig = jsonConfig;
  65. this.additionalJsonConfig = YAHOO.lang.JSON.parse(jsonConfig);
  66. }
  67. else
  68. {
  69.          this.additionalJsonConfig = {};
  70. }
  71. YAHOO.Bubbling.fire("registerRenderer", {
  72.      propertyName: "test:castka",                
  73.      renderer: function attachments_renderer(record, label){ //funkce 2
  74.                
  75.                     var jsNode = record.jsNode,
  76.                     properties = jsNode.properties;
  77.  
  78.                     var finalValue = properties['test:castka'];                    
  79.                     // Zavolání funkce na separaci mezer
  80.                     finalValue = numberWithSpaces(finalValue);
  81.  
  82.                     return '<div id="castka" style="text-align: right">' + finalValue + " " + "Kč" + '</div>';
  83.   }
  84. });
  85.  
  86. YAHOO.Bubbling.fire("registerRenderer", {
  87.      propertyName: "test:datum",               
  88.         renderer: function datum_renderer(record, label){ //funkce 1
  89.              
  90.                    var jsNode = record.jsNode,
  91.                    properties = jsNode.properties;
  92.   
  93.                     var finalValue = properties['test:datum'];
  94.                    
  95.                     /*  finalValue = new Date(finalValue).toLocaleString();
  96.                         finalValue = finalValue.substring(0,11);
  97.                         console.log(finalValue);
  98.                     */
  99.  
  100.                     var datum = new Date().toLocaleString();
  101.                     datum = datum.substring(0,11);
  102.                                      
  103.                     return '<div id="datum" style="text-align: center">' + datum + '</div>';
  104.                     }
  105.                   });
  106.  
  107. return this;                                        
  108. };
  109.  
  110.   function numberWithSpaces(x) {
  111.     return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); //funkce na separaci mezer
  112.   };
  113.  
  114.    /**
  115.     * Extend from Alfresco.DocumentListViewRenderer
  116.     */
  117.    YAHOO.extend(Alfresco.DocumentListTableViewRenderer, Alfresco.DocumentListViewRenderer);
  118.    
  119.    /**
  120.     * @method getConfigWidth
  121.     * @param propColumn {object}
  122.     */
  123.    Alfresco.DocumentListTableViewRenderer.prototype.getConfigWidth = function(propColumn)
  124.    {
  125.       var width = null;
  126.       var rawWidth = propColumn.width;
  127.       if (rawWidth != null)
  128.       {
  129.          width = parseInt(rawWidth);
  130.          if (width === NaN)
  131.          {
  132.             width = null;
  133.          }
  134.       }
  135.       return width;
  136.    };
  137.    
  138.    /**
  139.     * @see Alfresco.DocumentListViewRenderer.renderView
  140.     */
  141.    Alfresco.DocumentListTableViewRenderer.prototype.renderView = function DL_SVR_renderView(scope, sRequest, oResponse, oPayload)
  142.    {
  143.       // Add a class to help with CSS selectors...
  144.       var container = Dom.get(scope.id + this.parentElementIdSuffix);
  145.       Dom.addClass(container, 'alf-table');
  146.      
  147.       var viewRendererInstance = this;
  148.      
  149.       scope.widgets.dataTable.set('draggableColumns', false);
  150.      
  151.       var container = Dom.get(scope.id + this.parentElementIdSuffix);
  152.       var oRecordSet = scope.widgets.dataTable.getRecordSet();
  153.       Dom.addClass(container, 'alf-table');
  154.       Dom.removeClass(Dom.get(scope.id + "-table-config-button-container"), 'hidden');
  155.      
  156.       // Always hide the fileName column...
  157.       // This has been done due to time-constraints and the issues surrounding the other views (most notably the detailed
  158.       // and simple views) changing the widths of the fileName field. The simplest solution was to just always hide this
  159.       // field and rely on the JSON blob to add in columns that identify the item.
  160.       scope.widgets.dataTable.hideColumn("fileName");
  161.      
  162.       // Not all of the columns are properties, the selector, indicators and actions are not properties and
  163.       // need to be handled by specific configuration defined in the JSON BLOB...
  164.       if (this.additionalJsonConfig != null)
  165.       {
  166.          // Add/remove actions column as appropriate
  167.          if (this.additionalJsonConfig.actions != null && this.additionalJsonConfig.actions.show == "false")
  168.          {
  169.             scope.widgets.dataTable.hideColumn("actions");
  170.          }
  171.          else
  172.          {
  173.             scope.widgets.dataTable.showColumn("actions");
  174.          }
  175.          
  176.          // Add/remove the indicators column...
  177.          if (this.additionalJsonConfig.indicators != null && this.additionalJsonConfig.indicators.show == "false")
  178.          {
  179.             scope.widgets.dataTable.hideColumn("status");
  180.          }
  181.          else
  182.          {
  183.             scope.widgets.dataTable.showColumn("status");
  184.          }
  185.          
  186.          // Add/remove the selection box column...
  187.          if (this.additionalJsonConfig.selector != null && this.additionalJsonConfig.selector.show == "false")
  188.          {
  189.             scope.widgets.dataTable.hideColumn("nodeRef");
  190.          }
  191.          else
  192.          {
  193.             scope.widgets.dataTable.showColumn("nodeRef");
  194.          }
  195.          
  196.          // Add/remove the thumbnail column...
  197.          if (this.additionalJsonConfig.thumbnail != null && this.additionalJsonConfig.thumbnail.show == "false")
  198.          {
  199.             scope.widgets.dataTable.hideColumn("thumbnail");
  200.          }
  201.          else
  202.          {
  203.             scope.widgets.dataTable.showColumn("thumbnail");
  204.          }
  205.          
  206.          // If a JSON blob has been provided then is should define the columns that need to be
  207.          // rendered in the detailed view. Iterate over this configuration and add in the columns
  208.          // defined making use of the data provided...
  209.          if (this.additionalJsonConfig.propertyColumns != null &&
  210.              this.additionalJsonConfig.propertyColumns.length != null)
  211.          {
  212.             for (var i=0; i<this.additionalJsonConfig.propertyColumns.length; i++)
  213.             {
  214.                var propColumn = this.additionalJsonConfig.propertyColumns[i];
  215.                if (propColumn.property != null)
  216.                {
  217.                   var width = null;
  218.                   var rawWidth = propColumn.width;
  219.                   if (rawWidth != null)
  220.                   {
  221.                      width = parseInt(rawWidth);
  222.                      if (width === NaN)
  223.                      {
  224.                         width = null;
  225.                      }
  226.                   }
  227.                  
  228.                   var columnDef = {
  229.                      key: propColumn.property,
  230.                      label: propColumn.property,
  231.                      formatter: (propColumn.link == "true") ? this.fnRenderCellLinkProperty() : this.fnRenderCellProperty(),
  232.                      sortable: true,
  233.                      width: this.getConfigWidth(propColumn)
  234.                   };
  235.                   if (propColumn.label != null)
  236.                   {
  237.                      columnDef.label = scope.msg(propColumn.label);
  238.                   }
  239.                   scope.widgets.dataTable.insertColumn(columnDef);
  240.                }
  241.             }
  242.          }
  243.          
  244.          // In order to ensure that the actions column always appears at the end we're goign to remove it and
  245.          // then re-insert it. This is necessary because attempts at inserting the additional columns before
  246.          // the actions column always resulted in unexplainable errors and this was the quickest solution to the
  247.          // problem. It is however only necessary when the actions column is going to be displayed and in
  248.          // actual fact causes more errors if this is attempted after the actions column is hidden...
  249.          if (this.additionalJsonConfig.actions == null || this.additionalJsonConfig.actions.show == "true")
  250.          {
  251.             var actionsColumn = scope.widgets.dataTable.removeColumn("actions");
  252.             scope.widgets.dataTable.insertColumn(actionsColumn);
  253.          }
  254.          
  255.          // Get the current sort data...
  256.          var oSortedBy = scope.widgets.dataTable.get("sortedBy") || {};
  257.          var oState = scope.widgets.dataTable.getState();
  258.          
  259.          YAHOO.util.Dom.setStyle(scope.id + this.parentElementIdSuffix, 'display', '');
  260.          scope.widgets.dataTable.onDataReturnInitializeTable.call(scope.widgets.dataTable, sRequest, oResponse, oPayload);
  261.          
  262.          // Reset the sort state...
  263.          scope.widgets.dataTable.set('sortedBy', oState.sortedBy);
  264.       }
  265.    };
  266.    
  267.    /**
  268.     * @see Alfresco.DocumentListViewRenderer.renderCellThumbnail
  269.     */
  270.    Alfresco.DocumentListTableViewRenderer.prototype.renderCellThumbnail = function DL_SVR_renderCellThumbnail(scope, elCell, oRecord, oColumn, oData)
  271.    {
  272.       var record = oRecord.getData(),
  273.       node = record.jsNode,
  274.       properties = node.properties,
  275.       name = record.displayName,
  276.       isContainer = node.isContainer,
  277.       isLink = node.isLink,
  278.       extn = name.substring(name.lastIndexOf(".")),
  279.       imgId = node.nodeRef.nodeRef; // DD added
  280.    
  281.       var containerTarget; // This will only get set if thumbnail represents a container
  282.      
  283.       oColumn.width = 16;
  284.      
  285.       if (YAHOO.env.ua.ie > 0)
  286.       {
  287.          try
  288.          {
  289.             scope.widgets.dataTable._elThead.children[0].children[2].children[0].style.width = "16px";
  290.          }
  291.          catch (e)
  292.          {
  293.             // Deliberately swallowing any generated exceptions without remorse.
  294.          }
  295.          
  296.       }
  297.      
  298.       Dom.setStyle(elCell, "width", oColumn.width + "px");
  299.       Dom.setStyle(elCell.parentNode, "width", oColumn.width + "px");
  300.    
  301.       if (isContainer)
  302.       {
  303.          elCell.innerHTML = '<span class="folder-small">' + (isLink ? '<span class="link"></span>' : '') + (scope.dragAndDropEnabled ? '<span class="droppable"></span>' : '') + Alfresco.DocumentList.generateFileFolderLinkMarkup(scope, record) + '<img id="' + imgId + '" src="' + this.getFolderIcon(record.node) + '" /></a>';
  304.       }
  305.       else
  306.       {
  307.          var id = scope.id + '-preview-' + oRecord.getId();
  308.          elCell.innerHTML = '<span id="' + id + '" class="thumbnail">' + (isLink ? '<span class="link"></span>' : '') + Alfresco.DocumentList.generateFileFolderLinkMarkup(scope, record) + '<img id="' + imgId + '" src="' + Alfresco.DocumentList.generateThumbnailUrl(record) + '" alt="' + extn + '" title="' + $html(name) + '" /></a></span>';
  309.          
  310.          // Preview tooltip
  311.          scope.previewTooltips.push(id);
  312.       }
  313.    };
  314.    /**
  315.     * Default icon resource path string for this view.
  316.     * @returns {String}
  317.     */
  318.    Alfresco.DocumentListTableViewRenderer.prototype.getDefaultFolderIcon = function DL_SVR_getDefaultFolderIcon()
  319.    {
  320.       return "components/documentlibrary/images/folder-32.png";
  321.    };
  322.    /**
  323.     * Default icon size for this view.
  324.     * @returns {String}
  325.     */
  326.    Alfresco.DocumentListTableViewRenderer.prototype.getIconSize = function DL_SVR_getIconSize()
  327.    {
  328.       return "32x32";
  329.    };
  330.    
  331.    /**
  332.     * @see Alfresco.DocumentListViewRenderer.destroyView
  333.     */
  334.    Alfresco.DocumentListTableViewRenderer.prototype.destroyView = function DL_SVR_destroyView(scope, sRequest, oResponse, oPayload)
  335.    {
  336.       Alfresco.DocumentListTableViewRenderer.superclass.destroyView.call(this, scope, sRequest, oResponse, oPayload);
  337.      
  338.       // This gets called even before the view has first been created, so we need to ensure we have the original
  339.       // set of columns so that they can be restored for the benefit of other views...
  340.       if (!this.originalColumnDefinitions)
  341.       {
  342.          // Save the originalColumnDefinitions
  343.          this.originalColumnDefinitions = [];
  344.          var columnDefinitions = scope.widgets.dataTable.getColumnSet().getDefinitions();
  345.          for (var i = 0; i < columnDefinitions.length; i++)
  346.          {
  347.             this.originalColumnDefinitions[i] = columnDefinitions[i];
  348.          }
  349.       }
  350.      
  351.       var container = Dom.get(scope.id + this.parentElementIdSuffix);
  352.       Dom.removeClass(container, 'alf-table');
  353.       Dom.addClass(Dom.get(scope.id + "-table-config-button-container"), 'hidden');
  354.  
  355.      
  356.       // Rebuild the original columns...
  357.       if (this.originalColumnDefinitions)
  358.       {
  359.          // Ensure that all the "core" columns are displayed again (these columns are the ones that
  360.          // were defined by the original detailed view and need to be in place for the other views
  361.          // to continue to work...
  362.          scope.widgets.dataTable.showColumn("nodeRef");
  363.          scope.widgets.dataTable.showColumn("status");
  364.          scope.widgets.dataTable.showColumn("thumbnail");
  365.          scope.widgets.dataTable.showColumn("fileName");
  366.          scope.widgets.dataTable.showColumn("actions");
  367.          
  368.          // Remove all the current columns (except for those core columns)...
  369.          var currentColumnDefinitions = [];
  370.          var currentColumnDefinitionsCall = scope.widgets.dataTable.getColumnSet().getDefinitions();
  371.          
  372.          // currentColumnDefinitionsCall changes during iteration
  373.          for (var i = currentColumnDefinitionsCall.length-1; i >= 0 ; i--)
  374.          {
  375.             switch (currentColumnDefinitionsCall[i].key)
  376.             {
  377.                case "nodeRef":
  378.                case "status":
  379.                case "thumbnail":
  380.                case "fileName":
  381.                case "actions":
  382.                   break;
  383.                default:
  384.                   scope.widgets.dataTable.removeColumn(currentColumnDefinitionsCall[i].key);
  385.             }
  386.          }
  387.  
  388.          // Add back in any of the original columns that have since been deleted (typically this
  389.          // won't actually add anything back)...
  390.          for (var i = 0; i < this.originalColumnDefinitions.length; i++)
  391.          {
  392.             switch (this.originalColumnDefinitions[i].key)
  393.             {
  394.                case "nodeRef":
  395.                case "status":
  396.                case "thumbnail":
  397.                case "fileName":
  398.                case "actions":
  399.                   break;
  400.                default:
  401.                   scope.widgets.dataTable.insertColumn(this.originalColumnDefinitions[i]);
  402.             }
  403.          }
  404.       }
  405.    };
  406.    
  407.    /**
  408.     * Generic string custom datacell formatter
  409.     *
  410.     * @method renderCellGenericString
  411.     * @param elCell {object}
  412.     * @param oRecord {object}
  413.     * @param oColumn {object}
  414.     * @param oData {object|string}
  415.     */
  416.    Alfresco.DocumentListTableViewRenderer.prototype.renderCellGenericString = function DL_SVR_renderCellGenericString(elCell, oRecord, oColumn, oData)
  417.    {
  418.       var record = oRecord.getData(),
  419.          node = record.jsNode,
  420.          properties = node.properties,
  421.          propertyValue = properties[oColumn.field];
  422.       if (propertyValue != null)
  423.       {
  424.          elCell.innerHTML = '<span class="alf-generic-property">' + propertyValue + '</span>';
  425.       }
  426.    };
  427.    
  428.    /**
  429.     * Uses a defined metadata 'line' template and renderer as a custom datacell formatter
  430.     *
  431.     * @method renderCellMetadataLineRenderer
  432.     * @param scope {object} The DocumentList object
  433.     * @param elCell {object}
  434.     * @param oRecord {object}
  435.     * @param oColumn {object}
  436.     * @param oData {object|string}
  437.     * @param line {object} the metadata 'line' object
  438.     */
  439.    Alfresco.DocumentListTableViewRenderer.prototype.renderCellMetadataLineRenderer = function DL_SVR_renderCellMetadataLineRenderer(scope, elCell, oRecord, oColumn, oData, line)
  440.    {
  441.       var desc = "", i, j,
  442.          record = oRecord.getData(),
  443.          jsNode = record.jsNode;
  444.      
  445.       var fnRenderTemplate = function fnRenderTemplate_substitute(p_key, p_value, p_meta)
  446.       {
  447.          var label = (p_meta !== null ? '<em>' + scope.msg(p_meta) + '</em>: ': ''),
  448.             value = "";
  449.              
  450.          // render value from properties or custom renderer
  451.          if (scope.renderers.hasOwnProperty(p_key) && typeof scope.renderers[p_key] === "function")
  452.          {
  453.             value = scope.renderers[p_key].call(scope, record, label);
  454.          }
  455.          else
  456.          {
  457.             if (jsNode.hasProperty(p_key))
  458.             {
  459.                value = '<span class="item">' + label + $html(jsNode.properties[p_key]) + '</span>';
  460.             }
  461.          }
  462.  
  463.          return value;
  464.       };
  465.  
  466.       var html;
  467.       if (!$isValueSet(line.view) || line.view == this.metadataLineViewName)
  468.       {
  469.          html = YAHOO.lang.substitute(line.template, scope.renderers, fnRenderTemplate);
  470.          if ($isValueSet(html))
  471.          {
  472.             desc += '<div class="detail">' + html + '</div>';
  473.          }
  474.       }
  475.      
  476.       elCell.innerHTML = desc;
  477.    };
  478.  
  479. })();
Advertisement
Add Comment
Please, Sign In to add comment