Advertisement
Wity

Untitled

Oct 23rd, 2017
165
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.      * YUI Library aliases
  34.      */
  35.     var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, Anim = YAHOO.util.Anim;
  36.  
  37.     /**
  38.      * Alfresco Slingshot aliases
  39.      */
  40.     var $html = Alfresco.util.encodeHTML, $isValueSet = Alfresco.util.isValueSet;
  41.  
  42.     var DND_CONTAINER_ID = 'ygddfdiv';
  43.  
  44.     /**
  45.      * TableViewRenderer constructor.
  46.      *
  47.      * @param name
  48.      *            {String} The name of the TableViewRenderer
  49.      * @return {Alfresco.DocumentListTableViewRenderer} The new
  50.      *         TableViewRenderer instance
  51.      * @constructor
  52.      */
  53.  
  54.     // -------------------------TOHLE
  55.  
  56.     Alfresco.DocumentListTableViewRenderer = function(name, parentDocumentList,
  57.             commonComponentStyle, jsonConfig) {
  58.         Alfresco.DocumentListTableViewRenderer.superclass.constructor.call(
  59.                 this, name, parentDocumentList, commonComponentStyle);
  60.         this.actionsSplitAtModifier = 0;
  61.         if (jsonConfig != null) {
  62.             this.jsonConfig = jsonConfig;
  63.             this.additionalJsonConfig = YAHOO.lang.JSON.parse(jsonConfig);
  64.         } else {
  65.             this.additionalJsonConfig = {};
  66.         }
  67.         YAHOO.Bubbling.fire("registerRenderer", {
  68.             propertyName : "fato:celkovacena",
  69.             renderer : function attachments_renderer(record, label) {
  70.  
  71.                 var jsNode = record.jsNode, properties = jsNode.properties;
  72.  
  73.                 var finalValue = properties['fato:celkovacena'];
  74.  
  75.                 if(finalValue == null || finalValue == "") {
  76.                     return;
  77.                 }   
  78.                 // Zavolání funkce na separaci mezer
  79.                 console.log(finalValue.valueOf());
  80.                 finalValue = numberWithSpaces(finalValue);
  81.  
  82.                 return '<div id="castka" style="text-align: right">'
  83.                         + finalValue + " " + "Kč" + '</div>';
  84.             }
  85.         });
  86.         YAHOO.Bubbling.fire("registerRenderer", {
  87.             propertyName : "fato:zbyvavyfakturovat",
  88.             renderer : function attachments_renderer(record, label) {
  89.  
  90.                 var jsNode = record.jsNode, properties = jsNode.properties;
  91.  
  92.                 var finalValue = properties['fato:zbyvavyfakturovat'];
  93.  
  94.                 if(finalValue == null || finalValue == "") {
  95.                     return;
  96.                 }   
  97.                 // Zavolání funkce na separaci mezer
  98.                 console.log(finalValue.valueOf());
  99.                 finalValue = numberWithSpaces(finalValue);
  100.  
  101.                 return '<div id="castka" style="text-align: right">'
  102.                         + finalValue + " " + "Kč" + '</div>';
  103.             }
  104.         });
  105.         YAHOO.Bubbling.fire("registerRenderer", {
  106.             propertyName : "fato:vysepokutyhavarijni",
  107.             renderer : function attachments_renderer(record, label) {
  108.  
  109.                 var jsNode = record.jsNode, properties = jsNode.properties;
  110.  
  111.                 var finalValue = properties['fato:vysepokutyhavarijni'];
  112.  
  113.                 if(finalValue == null || finalValue == "") {
  114.                     return;
  115.                 }   
  116.                 // Zavolání funkce na separaci mezer
  117.                 console.log(finalValue.valueOf());
  118.                 finalValue = numberWithSpaces(finalValue);
  119.  
  120.                 return '<div id="castka" style="text-align: right">'
  121.                         + finalValue + " " + "Kč" + '</div>';
  122.             }
  123.         });
  124.         YAHOO.Bubbling.fire("registerRenderer", {
  125.             propertyName : "fato:celkovacenasubdodavky",
  126.             renderer : function attachments_renderer(record, label) {
  127.  
  128.                 var jsNode = record.jsNode, properties = jsNode.properties;
  129.  
  130.                 var finalValue = properties['fato:celkovacenasubdodavky'];
  131.  
  132.                 if(finalValue == null || finalValue == "") {
  133.                     return;
  134.                 }   
  135.                 // Zavolání funkce na separaci mezer
  136.                 console.log(finalValue.valueOf());
  137.                 finalValue = numberWithSpaces(finalValue);
  138.  
  139.                 return '<div id="castka" style="text-align: right">'
  140.                         + finalValue + " " + "Kč" + '</div>';
  141.             }
  142.         });
  143.         YAHOO.Bubbling.fire("registerRenderer", {
  144.             propertyName : "fato:vyfakturovano",
  145.             renderer : function attachments_renderer(record, label) {
  146.  
  147.                 var jsNode = record.jsNode, properties = jsNode.properties;
  148.  
  149.                 var finalValue = properties['fato:vyfakturovano'];
  150.  
  151.                 if(finalValue == null || finalValue == "") {
  152.                     return;
  153.                 }   
  154.                 // Zavolání funkce na separaci mezer
  155.                 console.log(finalValue.valueOf());
  156.                 finalValue = numberWithSpaces(finalValue);
  157.  
  158.                 return '<div id="castka" style="text-align: right">'
  159.                         + finalValue + " " + "Kč" + '</div>';
  160.             }
  161.         });
  162.         YAHOO.Bubbling.fire("registerRenderer", {
  163.             propertyName : "fato:zbyvajiciprostredkysubdodavky",
  164.             renderer : function attachments_renderer(record, label) {
  165.  
  166.                 var jsNode = record.jsNode, properties = jsNode.properties;
  167.  
  168.                 var finalValue = properties['fato:zbyvajiciprostredkysubdodavky'];
  169.  
  170.                 if(finalValue == null || finalValue == "") {
  171.                     return;
  172.                 }   
  173.                 // Zavolání funkce na separaci mezer
  174.                 console.log(finalValue.valueOf());
  175.                 finalValue = numberWithSpaces(finalValue);
  176.  
  177.                 return '<div id="castka" style="text-align: right">'
  178.                         + finalValue + " " + "Kč" + '</div>';
  179.             }
  180.         });
  181.         YAHOO.Bubbling.fire("registerRenderer", {
  182.             propertyName : "fato:vysepokutybezna",
  183.             renderer : function attachments_renderer(record, label) {
  184.  
  185.                 var jsNode = record.jsNode, properties = jsNode.properties;
  186.  
  187.                 var finalValue = properties['fato:vysepokutybezna'];
  188.  
  189.                 if(finalValue == null || finalValue == "") {
  190.                     return;
  191.                 }   
  192.                 // Zavolání funkce na separaci mezer
  193.                 console.log(finalValue.valueOf());
  194.                 finalValue = numberWithSpaces(finalValue);
  195.  
  196.                 return '<div id="castka" style="text-align: right">'
  197.                         + finalValue + " " + "Kč" + '</div>';
  198.             }
  199.         });
  200.  
  201.         YAHOO.Bubbling.fire("registerRenderer", {
  202.             propertyName : "fato:upozorneni",
  203.             renderer : function datum_renderer(record, label) {
  204.  
  205.                 var jsNode = record.jsNode, properties = jsNode.properties;
  206.  
  207.                 var finalValue = properties['fato:upozorneni'];
  208.                 if(finalValue == null || finalValue == "") {
  209.                     return;
  210.                 }   
  211.                 var klic = finalValue['iso8601'];
  212.  
  213.                
  214.  
  215.                 var date = new Date(klic);
  216.                 var d = date.getDate();
  217.                 var m = date.getMonth() + 1;
  218.                 var y = date.getFullYear();
  219.  
  220.                 return '<div id="attachments" style="text-align: center">' + d
  221.                         + "." + m + "." + y + '</div>';
  222.             }
  223.         });
  224.         YAHOO.Bubbling.fire("registerRenderer", {
  225.             propertyName : "fato:datumservisu",
  226.             renderer : function datum_renderer(record, label) {
  227.  
  228.                 var jsNode = record.jsNode, properties = jsNode.properties;
  229.  
  230.                 var finalValue = properties['fato:datumservisu'];
  231.                 if(finalValue == null || finalValue == "") {
  232.                     return;
  233.                 }   
  234.                 var klic = finalValue['iso8601'];
  235.  
  236.                
  237.  
  238.                 var date = new Date(klic);
  239.                 var d = date.getDate();
  240.                 var m = date.getMonth() + 1;
  241.                 var y = date.getFullYear();
  242.  
  243.                 return '<div id="attachments" style="text-align: center">' + d
  244.                         + "." + m + "." + y + '</div>';
  245.             }
  246.         });
  247.         YAHOO.Bubbling.fire("registerRenderer", {
  248.             propertyName : "fato:pojistkaauto",
  249.             renderer : function datum_renderer(record, label) {
  250.  
  251.                 var jsNode = record.jsNode, properties = jsNode.properties;
  252.  
  253.                 var finalValue = properties['fato:pojistkaauto'];
  254.                 if(finalValue == null || finalValue == "") {
  255.                     return;
  256.                 }  
  257.                 var klic = finalValue['iso8601'];
  258.  
  259.                  
  260.  
  261.                 var date = new Date(klic);
  262.                 var d = date.getDate();
  263.                 var m = date.getMonth() + 1;
  264.                 var y = date.getFullYear();
  265.  
  266.                 return '<div id="attachments" style="text-align: center">' + d
  267.                         + "." + m + "." + y + '</div>';
  268.             }
  269.         });
  270.         YAHOO.Bubbling.fire("registerRenderer", {
  271.             propertyName : "fato:lekarskaprohlidka",
  272.             renderer : function datum_renderer(record, label) {
  273.  
  274.                 var jsNode = record.jsNode, properties = jsNode.properties;
  275.  
  276.                 var finalValue = properties['fato:lekarskaprohlidka'];
  277.                 if(finalValue == null || finalValue == "") {
  278.                     return;
  279.                 }  
  280.                 var klic = finalValue['iso8601'];
  281.  
  282.                  
  283.  
  284.                 var date = new Date(klic);
  285.                 var d = date.getDate();
  286.                 var m = date.getMonth() + 1;
  287.                 var y = date.getFullYear();
  288.  
  289.                 return '<div id="attachments" style="text-align: center">' + d
  290.                         + "." + m + "." + y + '</div>';
  291.             }
  292.         });
  293.         YAHOO.Bubbling.fire("registerRenderer", {
  294.             propertyName : "fato:skolenibozp",
  295.             renderer : function datum_renderer(record, label) {
  296.  
  297.                 var jsNode = record.jsNode, properties = jsNode.properties;
  298.  
  299.                 var finalValue = properties['fato:skolenibozp'];
  300.  
  301.                 if(finalValue == null || finalValue == "") {
  302.                     return;
  303.                 }  
  304.                 var klic = finalValue['iso8601'];
  305.  
  306.  
  307.                 var date = new Date(klic);
  308.                 var d = date.getDate();
  309.                 var m = date.getMonth() + 1;
  310.                 var y = date.getFullYear();
  311.  
  312.                 return '<div id="attachments" style="text-align: center">' + d
  313.                         + "." + m + "." + y + '</div>';
  314.             }
  315.         });
  316.         YAHOO.Bubbling.fire("registerRenderer", {
  317.             propertyName : "fato:povinneruceni",
  318.             renderer : function datum_renderer(record, label) {
  319.  
  320.                 var jsNode = record.jsNode, properties = jsNode.properties;
  321.  
  322.                 var finalValue = properties['fato:povinneruceni'];
  323.                 if(finalValue == null || finalValue == "") {
  324.                     return;
  325.                 }   
  326.                 var klic = finalValue['iso8601'];
  327.  
  328.                
  329.  
  330.                 var date = new Date(klic);
  331.                 var d = date.getDate();
  332.                 var m = date.getMonth() + 1;
  333.                 var y = date.getFullYear();
  334.  
  335.                 return '<div id="attachments" style="text-align: center">' + d
  336.                         + "." + m + "." + y + '</div>';
  337.             }
  338.         });
  339.         YAHOO.Bubbling.fire("registerRenderer", {
  340.             propertyName : "fato:skoleniridicu",
  341.             renderer : function datum_renderer(record, label) {
  342.  
  343.                 var jsNode = record.jsNode, properties = jsNode.properties;
  344.  
  345.                 var finalValue = properties['fato:skoleniridicu'];
  346.                 if(finalValue == null || finalValue == "") {
  347.                     return;
  348.                 }   
  349.                 var klic = finalValue['iso8601'];
  350.  
  351.                
  352.  
  353.                 var date = new Date(klic);
  354.                 var d = date.getDate();
  355.                 var m = date.getMonth() + 1;
  356.                 var y = date.getFullYear();
  357.  
  358.                 return '<div id="attachments" style="text-align: center">' + d
  359.                         + "." + m + "." + y + '</div>';
  360.             }
  361.         });
  362.  
  363.         return this;
  364.     };
  365.  
  366.     function numberWithSpaces(x) {
  367.         return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); // funkce na
  368.                                                                     // separaci
  369.                                                                     // mezer
  370.     }
  371.     ;
  372.  
  373.     /**
  374.      * Extend from Alfresco.DocumentListViewRenderer
  375.      */
  376.     YAHOO.extend(Alfresco.DocumentListTableViewRenderer,
  377.             Alfresco.DocumentListViewRenderer);
  378.  
  379.     /**
  380.      * @method getConfigWidth
  381.      * @param propColumn
  382.      *            {object}
  383.      */
  384.     Alfresco.DocumentListTableViewRenderer.prototype.getConfigWidth = function(
  385.             propColumn) {
  386.         var width = null;
  387.         var rawWidth = propColumn.width;
  388.         if (rawWidth != null) {
  389.             width = parseInt(rawWidth);
  390.             if (width === NaN) {
  391.                 width = null;
  392.             }
  393.         }
  394.         return width;
  395.     };
  396.  
  397.     /**
  398.      * @see Alfresco.DocumentListViewRenderer.renderView
  399.      */
  400.     Alfresco.DocumentListTableViewRenderer.prototype.renderView = function DL_SVR_renderView(
  401.             scope, sRequest, oResponse, oPayload) {
  402.         // Add a class to help with CSS selectors...
  403.         var container = Dom.get(scope.id + this.parentElementIdSuffix);
  404.         Dom.addClass(container, 'alf-table');
  405.  
  406.         var viewRendererInstance = this;
  407.  
  408.         scope.widgets.dataTable.set('draggableColumns', false);
  409.  
  410.         var container = Dom.get(scope.id + this.parentElementIdSuffix);
  411.         var oRecordSet = scope.widgets.dataTable.getRecordSet();
  412.         Dom.addClass(container, 'alf-table');
  413.         Dom.removeClass(Dom.get(scope.id + "-table-config-button-container"),
  414.                 'hidden');
  415.  
  416.         // Always hide the fileName column...
  417.         // This has been done due to time-constraints and the issues surrounding
  418.         // the other views (most notably the detailed
  419.         // and simple views) changing the widths of the fileName field. The
  420.         // simplest solution was to just always hide this
  421.         // field and rely on the JSON blob to add in columns that identify the
  422.         // item.
  423.         scope.widgets.dataTable.hideColumn("fileName");
  424.  
  425.         // Not all of the columns are properties, the selector, indicators and
  426.         // actions are not properties and
  427.         // need to be handled by specific configuration defined in the JSON
  428.         // BLOB...
  429.         if (this.additionalJsonConfig != null) {
  430.             // Add/remove actions column as appropriate
  431.             if (this.additionalJsonConfig.actions != null
  432.                     && this.additionalJsonConfig.actions.show == "false") {
  433.                 scope.widgets.dataTable.hideColumn("actions");
  434.             } else {
  435.                 scope.widgets.dataTable.showColumn("actions");
  436.             }
  437.  
  438.             // Add/remove the indicators column...
  439.             if (this.additionalJsonConfig.indicators != null
  440.                     && this.additionalJsonConfig.indicators.show == "false") {
  441.                 scope.widgets.dataTable.hideColumn("status");
  442.             } else {
  443.                 scope.widgets.dataTable.showColumn("status");
  444.             }
  445.  
  446.             // Add/remove the selection box column...
  447.             if (this.additionalJsonConfig.selector != null
  448.                     && this.additionalJsonConfig.selector.show == "false") {
  449.                 scope.widgets.dataTable.hideColumn("nodeRef");
  450.             } else {
  451.                 scope.widgets.dataTable.showColumn("nodeRef");
  452.             }
  453.  
  454.             // Add/remove the thumbnail column...
  455.             if (this.additionalJsonConfig.thumbnail != null
  456.                     && this.additionalJsonConfig.thumbnail.show == "false") {
  457.                 scope.widgets.dataTable.hideColumn("thumbnail");
  458.             } else {
  459.                 scope.widgets.dataTable.showColumn("thumbnail");
  460.             }
  461.  
  462.             // If a JSON blob has been provided then is should define the
  463.             // columns that need to be
  464.             // rendered in the detailed view. Iterate over this configuration
  465.             // and add in the columns
  466.             // defined making use of the data provided...
  467.             if (this.additionalJsonConfig.propertyColumns != null
  468.                     && this.additionalJsonConfig.propertyColumns.length != null) {
  469.                 for (var i = 0; i < this.additionalJsonConfig.propertyColumns.length; i++) {
  470.                     var propColumn = this.additionalJsonConfig.propertyColumns[i];
  471.                     if (propColumn.property != null) {
  472.                         var width = null;
  473.                         var rawWidth = propColumn.width;
  474.                         if (rawWidth != null) {
  475.                             width = parseInt(rawWidth);
  476.                             if (width === NaN) {
  477.                                 width = null;
  478.                             }
  479.                         }
  480.  
  481.                         var columnDef = {
  482.                             key : propColumn.property,
  483.                             label : propColumn.property,
  484.                             formatter : (propColumn.link == "true") ? this
  485.                                     .fnRenderCellLinkProperty() : this
  486.                                     .fnRenderCellProperty(),
  487.                             sortable : true,
  488.                             width : this.getConfigWidth(propColumn)
  489.                         };
  490.                         if (propColumn.label != null) {
  491.                             columnDef.label = scope.msg(propColumn.label);
  492.                         }
  493.                         scope.widgets.dataTable.insertColumn(columnDef);
  494.                     }
  495.                 }
  496.             }
  497.  
  498.             // In order to ensure that the actions column always appears at the
  499.             // end we're goign to remove it and
  500.             // then re-insert it. This is necessary because attempts at
  501.             // inserting the additional columns before
  502.             // the actions column always resulted in unexplainable errors and
  503.             // this was the quickest solution to the
  504.             // problem. It is however only necessary when the actions column is
  505.             // going to be displayed and in
  506.             // actual fact causes more errors if this is attempted after the
  507.             // actions column is hidden...
  508.             if (this.additionalJsonConfig.actions == null
  509.                     || this.additionalJsonConfig.actions.show == "true") {
  510.                 var actionsColumn = scope.widgets.dataTable
  511.                         .removeColumn("actions");
  512.                 scope.widgets.dataTable.insertColumn(actionsColumn);
  513.             }
  514.  
  515.             // Get the current sort data...
  516.             var oSortedBy = scope.widgets.dataTable.get("sortedBy") || {};
  517.             var oState = scope.widgets.dataTable.getState();
  518.  
  519.             YAHOO.util.Dom.setStyle(scope.id + this.parentElementIdSuffix,
  520.                     'display', '');
  521.             scope.widgets.dataTable.onDataReturnInitializeTable.call(
  522.                     scope.widgets.dataTable, sRequest, oResponse, oPayload);
  523.  
  524.             // Reset the sort state...
  525.             scope.widgets.dataTable.set('sortedBy', oState.sortedBy);
  526.         }
  527.     };
  528.  
  529.     /**
  530.      * @see Alfresco.DocumentListViewRenderer.renderCellThumbnail
  531.      */
  532.     Alfresco.DocumentListTableViewRenderer.prototype.renderCellThumbnail = function DL_SVR_renderCellThumbnail(
  533.             scope, elCell, oRecord, oColumn, oData) {
  534.         var record = oRecord.getData(), node = record.jsNode, properties = node.properties, name = record.displayName, isContainer = node.isContainer, isLink = node.isLink, extn = name
  535.                 .substring(name.lastIndexOf(".")), imgId = node.nodeRef.nodeRef; // DD
  536.                                                                                     // added
  537.  
  538.         var containerTarget; // This will only get set if thumbnail
  539.                                 // represents a container
  540.  
  541.         oColumn.width = 16;
  542.  
  543.         if (YAHOO.env.ua.ie > 0) {
  544.             try {
  545.                 scope.widgets.dataTable._elThead.children[0].children[2].children[0].style.width = "16px";
  546.             } catch (e) {
  547.                 // Deliberately swallowing any generated exceptions without
  548.                 // remorse.
  549.             }
  550.  
  551.         }
  552.  
  553.         Dom.setStyle(elCell, "width", oColumn.width + "px");
  554.         Dom.setStyle(elCell.parentNode, "width", oColumn.width + "px");
  555.  
  556.         if (isContainer) {
  557.             elCell.innerHTML = '<span class="folder-small">'
  558.                     + (isLink ? '<span class="link"></span>' : '')
  559.                     + (scope.dragAndDropEnabled ? '<span class="droppable"></span>'
  560.                             : '')
  561.                     + Alfresco.DocumentList.generateFileFolderLinkMarkup(scope,
  562.                             record) + '<img id="' + imgId + '" src="'
  563.                     + this.getFolderIcon(record.node) + '" /></a>';
  564.         } else {
  565.             var id = scope.id + '-preview-' + oRecord.getId();
  566.             elCell.innerHTML = '<span id="'
  567.                     + id
  568.                     + '" class="thumbnail">'
  569.                     + (isLink ? '<span class="link"></span>' : '')
  570.                     + Alfresco.DocumentList.generateFileFolderLinkMarkup(scope,
  571.                             record) + '<img id="' + imgId + '" src="'
  572.                     + Alfresco.DocumentList.generateThumbnailUrl(record)
  573.                     + '" alt="' + extn + '" title="' + $html(name)
  574.                     + '" /></a></span>';
  575.  
  576.             // Preview tooltip
  577.             scope.previewTooltips.push(id);
  578.         }
  579.     };
  580.     /**
  581.      * Default icon resource path string for this view.
  582.      *
  583.      * @returns {String}
  584.      */
  585.     Alfresco.DocumentListTableViewRenderer.prototype.getDefaultFolderIcon = function DL_SVR_getDefaultFolderIcon() {
  586.         return "components/documentlibrary/images/folder-32.png";
  587.     };
  588.     /**
  589.      * Default icon size for this view.
  590.      *
  591.      * @returns {String}
  592.      */
  593.     Alfresco.DocumentListTableViewRenderer.prototype.getIconSize = function DL_SVR_getIconSize() {
  594.         return "32x32";
  595.     };
  596.  
  597.     /**
  598.      * @see Alfresco.DocumentListViewRenderer.destroyView
  599.      */
  600.     Alfresco.DocumentListTableViewRenderer.prototype.destroyView = function DL_SVR_destroyView(
  601.             scope, sRequest, oResponse, oPayload) {
  602.         Alfresco.DocumentListTableViewRenderer.superclass.destroyView.call(
  603.                 this, scope, sRequest, oResponse, oPayload);
  604.  
  605.         // This gets called even before the view has first been created, so we
  606.         // need to ensure we have the original
  607.         // set of columns so that they can be restored for the benefit of other
  608.         // views...
  609.         if (!this.originalColumnDefinitions) {
  610.             // Save the originalColumnDefinitions
  611.             this.originalColumnDefinitions = [];
  612.             var columnDefinitions = scope.widgets.dataTable.getColumnSet()
  613.                     .getDefinitions();
  614.             for (var i = 0; i < columnDefinitions.length; i++) {
  615.                 this.originalColumnDefinitions[i] = columnDefinitions[i];
  616.             }
  617.         }
  618.  
  619.         var container = Dom.get(scope.id + this.parentElementIdSuffix);
  620.         Dom.removeClass(container, 'alf-table');
  621.         Dom.addClass(Dom.get(scope.id + "-table-config-button-container"),
  622.                 'hidden');
  623.  
  624.         // Rebuild the original columns...
  625.         if (this.originalColumnDefinitions) {
  626.             // Ensure that all the "core" columns are displayed again (these
  627.             // columns are the ones that
  628.             // were defined by the original detailed view and need to be in
  629.             // place for the other views
  630.             // to continue to work...
  631.             scope.widgets.dataTable.showColumn("nodeRef");
  632.             scope.widgets.dataTable.showColumn("status");
  633.             scope.widgets.dataTable.showColumn("thumbnail");
  634.             scope.widgets.dataTable.showColumn("fileName");
  635.             scope.widgets.dataTable.showColumn("actions");
  636.  
  637.             // Remove all the current columns (except for those core columns)...
  638.             var currentColumnDefinitions = [];
  639.             var currentColumnDefinitionsCall = scope.widgets.dataTable
  640.                     .getColumnSet().getDefinitions();
  641.  
  642.             // currentColumnDefinitionsCall changes during iteration
  643.             for (var i = currentColumnDefinitionsCall.length - 1; i >= 0; i--) {
  644.                 switch (currentColumnDefinitionsCall[i].key) {
  645.                 case "nodeRef":
  646.                 case "status":
  647.                 case "thumbnail":
  648.                 case "fileName":
  649.                 case "actions":
  650.                     break;
  651.                 default:
  652.                     scope.widgets.dataTable
  653.                             .removeColumn(currentColumnDefinitionsCall[i].key);
  654.                 }
  655.             }
  656.  
  657.             // Add back in any of the original columns that have since been
  658.             // deleted (typically this
  659.             // won't actually add anything back)...
  660.             for (var i = 0; i < this.originalColumnDefinitions.length; i++) {
  661.                 switch (this.originalColumnDefinitions[i].key) {
  662.                 case "nodeRef":
  663.                 case "status":
  664.                 case "thumbnail":
  665.                 case "fileName":
  666.                 case "actions":
  667.                     break;
  668.                 default:
  669.                     scope.widgets.dataTable
  670.                             .insertColumn(this.originalColumnDefinitions[i]);
  671.                 }
  672.             }
  673.         }
  674.     };
  675.  
  676.     /**
  677.      * Generic string custom datacell formatter
  678.      *
  679.      * @method renderCellGenericString
  680.      * @param elCell
  681.      *            {object}
  682.      * @param oRecord
  683.      *            {object}
  684.      * @param oColumn
  685.      *            {object}
  686.      * @param oData
  687.      *            {object|string}
  688.      */
  689.     Alfresco.DocumentListTableViewRenderer.prototype.renderCellGenericString = function DL_SVR_renderCellGenericString(
  690.             elCell, oRecord, oColumn, oData) {
  691.         var record = oRecord.getData(), node = record.jsNode, properties = node.properties, propertyValue = properties[oColumn.field];
  692.         if (propertyValue != null) {
  693.             elCell.innerHTML = '<span class="alf-generic-property">'
  694.                     + propertyValue + '</span>';
  695.         }
  696.     };
  697.  
  698.     /**
  699.      * Uses a defined metadata 'line' template and renderer as a custom datacell
  700.      * formatter
  701.      *
  702.      * @method renderCellMetadataLineRenderer
  703.      * @param scope
  704.      *            {object} The DocumentList object
  705.      * @param elCell
  706.      *            {object}
  707.      * @param oRecord
  708.      *            {object}
  709.      * @param oColumn
  710.      *            {object}
  711.      * @param oData
  712.      *            {object|string}
  713.      * @param line
  714.      *            {object} the metadata 'line' object
  715.      */
  716.     Alfresco.DocumentListTableViewRenderer.prototype.renderCellMetadataLineRenderer = function DL_SVR_renderCellMetadataLineRenderer(
  717.             scope, elCell, oRecord, oColumn, oData, line) {
  718.         var desc = "", i, j, record = oRecord.getData(), jsNode = record.jsNode;
  719.  
  720.         var fnRenderTemplate = function fnRenderTemplate_substitute(p_key,
  721.                 p_value, p_meta) {
  722.             var label = (p_meta !== null ? '<em>' + scope.msg(p_meta)
  723.                     + '</em>: ' : ''), value = "";
  724.  
  725.             // render value from properties or custom renderer
  726.             if (scope.renderers.hasOwnProperty(p_key)
  727.                     && typeof scope.renderers[p_key] === "function") {
  728.                 value = scope.renderers[p_key].call(scope, record, label);
  729.             } else {
  730.                 if (jsNode.hasProperty(p_key)) {
  731.                     value = '<span class="item">' + label
  732.                             + $html(jsNode.properties[p_key]) + '</span>';
  733.                 }
  734.             }
  735.  
  736.             return value;
  737.         };
  738.  
  739.         var html;
  740.         if (!$isValueSet(line.view) || line.view == this.metadataLineViewName) {
  741.             html = YAHOO.lang.substitute(line.template, scope.renderers,
  742.                     fnRenderTemplate);
  743.             if ($isValueSet(html)) {
  744.                 desc += '<div class="detail">' + html + '</div>';
  745.             }
  746.         }
  747.  
  748.         elCell.innerHTML = desc;
  749.     };
  750.  
  751. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement