From 8d4339969490fa84f6f85be246fee6bf7197ef24 Mon Sep 17 00:00:00 2001 From: gakin <gakin> Date: Mon, 17 Aug 2015 12:40:33 +0000 Subject: [PATCH] SSDM-2320 : Comments and Comments Log aren't shown if empty SVN: 34471 --- .../views/SampleForm/SampleFormController.js | 8 +- .../js/views/SampleForm/SampleFormView.js | 81 +------------------ .../SampleForm/widgets/CommentsController.js | 12 +++ .../views/SampleForm/widgets/CommentsView.js | 6 +- 4 files changed, 25 insertions(+), 82 deletions(-) diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js index 25dba4c0533..a08adcd5871 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js @@ -51,7 +51,13 @@ function SampleFormController(mainController, mode, sample) { this._addCommentsWidget = function($container) { var commentsController = new CommentsController(this._sampleFormModel.sample, this._sampleFormModel.mode, this._sampleFormModel); - commentsController.init($container); + if(this._sampleFormModel.mode !== FormMode.VIEW || + this._sampleFormModel.mode === FormMode.VIEW && !commentsController.isEmpty()) { + commentsController.init($container); + return true; + } else { + return false; + } } this.getLastStorageController = function() { diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js index 675931c1aa1..ff54fa6e40e 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js @@ -243,81 +243,6 @@ function SampleFormView(sampleFormController, sampleFormModel) { currentChildrenLinks, this._sampleFormModel.mode === FormMode.CREATE); - // - // LINKS - // -// var requiredLinks = []; -// if(sampleTypeDefinitionsExtension && sampleTypeDefinitionsExtension["SAMPLE_LINKS_HINT"]) { -// requiredLinks = sampleTypeDefinitionsExtension["SAMPLE_LINKS_HINT"]; -// } -// -// var sampleLinksWidgetId = "sampleLinksWidgetId"; -// var $sampleLinksWidget = $("<div>", { "id" : sampleLinksWidgetId }); -// $formColumn.append($sampleLinksWidget); -// -// var currentOrphanLinksIdentifiers = []; -// var currentOrphanLinksPermIds = []; -// -// //Read the XML to build the orphan links list -// var annotationsFromSample = FormUtil.getAnnotationsFromSample(this._sampleFormModel.sample); -// //Delete parents and children -// if(this._sampleFormModel.sample.parents) { -// for(var idxF = 0; idxF < this._sampleFormModel.sample.parents.length; idxF++) { -// var sample = this._sampleFormModel.sample.parents[idxF]; -// delete annotationsFromSample[sample.permId]; -// } -// } -// if(this._sampleFormModel.sample.children) { -// for(var idxC = 0; idxC < this._sampleFormModel.sample.children.length; idxC++) { -// var sample = this._sampleFormModel.sample.children[idxC]; -// delete annotationsFromSample[sample.permId]; -// } -// } -// //Make samples from Orphans left -// if(annotationsFromSample) { -// for(var orphanSamplePermId in annotationsFromSample) { -// currentOrphanLinksIdentifiers.push(annotationsFromSample[orphanSamplePermId].identifier); -// currentOrphanLinksPermIds.push(orphanSamplePermId); -// } -// } -// -// var isPresentLinkOnData = function(orphanSamplePermId, data) { -// for(var dIdx = 0; dIdx <data.length; dIdx++) { -// if(data[dIdx].permId === orphanSamplePermId) { -// return true; -// } -// } -// return false; -// } -// -// var buildFakeSampleIfNotFoundLink = function(orphanSamplePermId, annotationsFromSample) { -// var orphanSample = {}; -// orphanSample.notFound = true; -// orphanSample.permId = orphanSamplePermId; -// orphanSample.code = annotationsFromSample[orphanSamplePermId].identifier.split('/')[2]; -// orphanSample.identifier = annotationsFromSample[orphanSamplePermId].identifier; -// orphanSample.sampleTypeCode = annotationsFromSample[orphanSamplePermId].sampleType; -// return orphanSample; -// } -// -// var showLinksWidgetAction = function(data) { -// for(var oIdx = 0; oIdx < currentOrphanLinksPermIds.length; oIdx++) { -// if(!isPresentLinkOnData(currentOrphanLinksPermIds[oIdx], data)) { -// data.push(buildFakeSampleIfNotFoundLink(currentOrphanLinksPermIds[oIdx], annotationsFromSample)); -// } -// } -// -// _this._sampleFormModel.sampleLinks = new SampleLinksWidget(sampleLinksWidgetId, -// profile, -// mainController.serverFacade, -// "Links", -// requiredLinks, -// isDisabled, -// data, -// _this._sampleFormModel.mode === FormMode.CREATE); -// _this._sampleFormModel.sampleLinks.repaint(); -// } - // // GENERATE CHILDREN // @@ -468,7 +393,7 @@ function SampleFormView(sampleFormController, sampleFormModel) { if(propertyType.code === "XMLCOMMENTS") { var $commentsContainer = $("<div>"); $fieldset.append($commentsContainer); - this._sampleFormController._addCommentsWidget($commentsContainer); + var isAvailable = this._sampleFormController._addCommentsWidget($commentsContainer); continue; } var $controlGroup = null; @@ -535,7 +460,9 @@ function SampleFormView(sampleFormController, sampleFormModel) { } $fieldset.append($controlGroup); - propertyGroupPropertiesOnForm++; + if(propertyType.code !== "ANNOTATIONS_STATE") { + propertyGroupPropertiesOnForm++; + } } if(propertyGroupPropertiesOnForm === 0) { diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsController.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsController.js index c542023a4bf..e66e50f411d 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsController.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsController.js @@ -22,6 +22,18 @@ function CommentsController(entity, mode, form) { this._commentsView.repaint($container); } + this.isEmpty = function() { + var comments = this.getComments(); + return comments === null || comments.length === 0; + } + + this.getComments = function() { + var commentsXML = this._commentsModel.getComments(); + var xmlDoc = new DOMParser().parseFromString(commentsXML, 'text/xml'); + var comments = xmlDoc.getElementsByTagName("commentEntry"); + return comments; + } + this.deleteComment = function(commentTimestampToDelete) { var commentsXML = this._commentsModel.getComments(); var xmlDoc = new DOMParser().parseFromString(commentsXML, 'text/xml'); diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsView.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsView.js index e66af2582e1..136e4f1a703 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsView.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/CommentsView.js @@ -23,11 +23,9 @@ function CommentsView(commentsController, commentsModel) { this.repaint = function($container) { $container.empty(); $container.append(this.commentsContainer); - this.commentsContainer.append($("<legend>").text("Comments Log")); + this.commentsContainer.append($("<legend>", { "style" : "border-bottom-style:none; font-weight: bold;"} ).text("Comments Log")); $container.append(this.commentsAddButton); - var commentsXML = this._commentsModel.getComments(); - var xmlDoc = new DOMParser().parseFromString(commentsXML, 'text/xml'); - var comments = xmlDoc.getElementsByTagName("commentEntry"); + var comments = this._commentsController.getComments(); for(var i = 0; i < comments.length; i++) { this.addCommentWidgetFromXML(comments[i]); } -- GitLab