From bad7266534de9d9ece255d43bed4808949f1babc Mon Sep 17 00:00:00 2001 From: David Huynh Date: Thu, 4 Aug 2011 20:37:14 +0000 Subject: [PATCH] Cleaned up code formatting in .js, .html, .vt, .css, .less files. git-svn-id: http://google-refine.googlecode.com/svn/trunk@2185 7d457c2a-affb-35e4-300a-418c747d4874 --- .../freebase/module/MOD-INF/controller.js | 164 +- .../dialogs/extend-data-preview-dialog.js | 660 ++++---- .../dialogs/freebase-loading-dialog.html | 3 +- .../dialogs/freebase-loading-dialog.js | 383 ++--- .../dialogs/schema-alignment/dialog.js | 476 +++--- .../schema-alignment-dialog.html | 28 +- .../dialogs/schema-alignment/ui-link.js | 646 ++++---- .../dialogs/schema-alignment/ui-node.js | 1330 ++++++++--------- .../freebase/module/scripts/extension.js | 188 +-- .../freebase/module/scripts/util/freebase.js | 56 +- .../freebase/module/scripts/util/sign.js | 233 ++- .../dialogs/extend-data-preview-dialog.less | 46 +- .../dialogs/freebase-loading-dialog.less | 40 +- .../dialogs/schema-alignment-dialog.less | 140 +- extensions/gdata/module/MOD-INF/controller.js | 96 +- .../jython/module/MOD-INF/controller.js | 40 +- .../sample/module/MOD-INF/controller.js | 72 +- .../webapp/modules/core/MOD-INF/controller.js | 966 ++++++------ main/webapp/modules/core/scripts/index.js | 230 +-- .../core/scripts/index/create-project-ui.js | 160 +- .../controller.js | 600 ++++---- .../file-selection-panel.js | 504 +++---- .../parsing-panel.js | 280 ++-- .../default-importing-sources/sources.js | 108 +- .../core/scripts/index/open-project-ui.js | 416 +++--- .../parser-interfaces/excel-parser-ui.js | 284 ++-- .../fixed-width-parser-ui.js | 790 +++++----- .../index/parser-interfaces/json-parser-ui.js | 356 ++--- .../parser-interfaces/line-based-parser-ui.js | 260 ++-- .../index/parser-interfaces/preview-table.js | 156 +- .../separator-based-parser-ui.js | 340 ++--- .../index/parser-interfaces/xml-parser-ui.js | 344 ++--- .../modules/core/scripts/preferences.js | 209 +-- main/webapp/modules/core/scripts/project.js | 672 ++++----- .../core/scripts/project/browsing-engine.js | 440 +++--- .../modules/core/scripts/project/exporters.js | 212 +-- .../core/scripts/project/extension-bar.js | 60 +- .../core/scripts/project/history-panel.html | 20 +- .../core/scripts/project/history-panel.js | 488 +++--- .../core/scripts/project/process-panel.js | 350 ++--- .../modules/core/scripts/project/scripting.js | 42 +- .../core/scripts/project/summary-bar.js | 32 +- .../reconciliation/freebase-query-panel.js | 166 +- .../scripts/reconciliation/recon-dialog.js | 330 ++-- .../scripts/reconciliation/recon-manager.js | 184 +-- .../reconciliation/standard-service-panel.js | 506 +++---- main/webapp/modules/core/scripts/util/ajax.js | 44 +- .../core/scripts/util/custom-suggest.js | 130 +- .../modules/core/scripts/util/dialog.js | 150 +- main/webapp/modules/core/scripts/util/dom.js | 80 +- main/webapp/modules/core/scripts/util/menu.js | 428 +++--- main/webapp/modules/core/scripts/util/misc.js | 48 +- .../modules/core/scripts/util/string.js | 16 +- main/webapp/modules/core/scripts/util/url.js | 142 +- .../add-column-by-fetching-urls-dialog.html | 28 +- .../views/data-table/add-column-dialog.html | 18 +- .../core/scripts/views/data-table/cell-ui.js | 942 ++++++------ .../views/data-table/column-header-ui.js | 574 +++---- .../views/data-table/data-table-view.js | 1202 +++++++-------- .../views/data-table/menu-edit-cells.js | 589 ++++---- .../views/data-table/menu-edit-column.js | 483 +++--- .../scripts/views/data-table/menu-facets.js | 476 +++--- .../views/data-table/menu-reconcile.js | 706 ++++----- .../data-table/sorting-criterion-dialog.html | 70 +- .../views/data-table/split-column-dialog.html | 88 +- .../data-table/text-transform-dialog.html | 14 +- .../core/scripts/widgets/histogram-widget.js | 220 +-- .../core/scripts/widgets/slider-widget.js | 360 ++--- main/webapp/modules/core/styles/common.less | 140 +- .../styles/dialogs/clustering-dialog.less | 100 +- .../dialogs/column-reordering-dialog.less | 22 +- .../dialogs/expression-preview-dialog.less | 86 +- .../styles/dialogs/scatterplot-dialog.less | 50 +- main/webapp/modules/core/styles/index.less | 12 +- .../core/styles/index/create-project-ui.less | 4 +- .../index/default-importing-controller.less | 18 +- ...efault-importing-file-selection-panel.less | 16 +- .../default-importing-parsing-panel.less | 18 +- .../index/default-importing-sources.less | 4 +- .../styles/index/fixed-width-parser-ui.less | 18 +- .../core/styles/index/import-project-ui.less | 2 +- .../core/styles/index/json-parser-ui.less | 20 +- .../core/styles/index/xml-parser-ui.less | 12 +- .../modules/core/styles/project/facets.less | 208 ++- .../modules/core/styles/project/process.less | 41 +- main/webapp/modules/core/styles/pure.css | 4 +- .../styles/reconciliation/recon-dialog.less | 68 +- .../standard-service-panel.less | 26 +- .../core/styles/util/custom-suggest.less | 4 +- .../core/styles/widgets/slider-widget.less | 72 +- 90 files changed, 10939 insertions(+), 10920 deletions(-) diff --git a/extensions/freebase/module/MOD-INF/controller.js b/extensions/freebase/module/MOD-INF/controller.js index 0ab7a0e45..7ea1c7fb1 100644 --- a/extensions/freebase/module/MOD-INF/controller.js +++ b/extensions/freebase/module/MOD-INF/controller.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,89 +29,89 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function init() { - Packages.com.google.refine.freebase.oauth.FreebaseProvider.register(); - - var RS = Packages.com.google.refine.RefineServlet; - RS.registerClassMapping( - "com.google.refine.model.changes.DataExtensionChange", - "com.google.refine.freebase.model.changes.DataExtensionChange"); - RS.registerClassMapping( - "com.google.refine.operations.SaveProtographOperation$ProtographChange", - "com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange"); - - // TODO(dfhuynh): Temporary hack until we know how the core module can resolve our module's classes - RS.cacheClass(Packages.com.google.refine.freebase.model.changes.DataExtensionChange); - RS.cacheClass(Packages.com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange); - - RS.registerCommand(module, "extend-data", new Packages.com.google.refine.freebase.commands.ExtendDataCommand()); - RS.registerCommand(module, "preview-extend-data", new Packages.com.google.refine.freebase.commands.PreviewExtendDataCommand()); + Packages.com.google.refine.freebase.oauth.FreebaseProvider.register(); - RS.registerCommand(module, "preview-protograph", new Packages.com.google.refine.freebase.commands.PreviewProtographCommand()); - RS.registerCommand(module, "save-protograph", new Packages.com.google.refine.freebase.commands.SaveProtographCommand()); + var RS = Packages.com.google.refine.RefineServlet; + RS.registerClassMapping( + "com.google.refine.model.changes.DataExtensionChange", + "com.google.refine.freebase.model.changes.DataExtensionChange"); + RS.registerClassMapping( + "com.google.refine.operations.SaveProtographOperation$ProtographChange", + "com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange"); - RS.registerCommand(module, "check-authorization", new Packages.com.google.refine.freebase.commands.auth.CheckAuthorizationCommand()); - RS.registerCommand(module, "authorize", new Packages.com.google.refine.freebase.commands.auth.AuthorizeCommand()); - RS.registerCommand(module, "deauthorize", new Packages.com.google.refine.freebase.commands.auth.DeAuthorizeCommand()); - RS.registerCommand(module, "user-badges", new Packages.com.google.refine.freebase.commands.auth.GetUserBadgesCommand()); + // TODO(dfhuynh): Temporary hack until we know how the core module can resolve our module's classes + RS.cacheClass(Packages.com.google.refine.freebase.model.changes.DataExtensionChange); + RS.cacheClass(Packages.com.google.refine.freebase.operations.SaveProtographOperation$ProtographChange); - RS.registerCommand(module, "upload-data", new Packages.com.google.refine.freebase.commands.UploadDataCommand()); - RS.registerCommand(module, "import-qa-data", new Packages.com.google.refine.freebase.commands.ImportQADataCommand()); - RS.registerCommand(module, "mqlread", new Packages.com.google.refine.freebase.commands.MQLReadCommand()); - RS.registerCommand(module, "mqlwrite", new Packages.com.google.refine.freebase.commands.MQLWriteCommand()); + RS.registerCommand(module, "extend-data", new Packages.com.google.refine.freebase.commands.ExtendDataCommand()); + RS.registerCommand(module, "preview-extend-data", new Packages.com.google.refine.freebase.commands.PreviewExtendDataCommand()); - var OR = Packages.com.google.refine.operations.OperationRegistry; - - OR.registerOperation(module, "extend-data", Packages.com.google.refine.freebase.operations.ExtendDataOperation); - OR.registerOperation(module, "import-qa-data", Packages.com.google.refine.freebase.operations.ImportQADataOperation); - OR.registerOperation(module, "save-protograph", Packages.com.google.refine.freebase.operations.SaveProtographOperation); // for backward compatibility - OR.registerOperation(module, "save-schema-alignment-skeleton", Packages.com.google.refine.freebase.operations.SaveProtographOperation); - - var RC = Packages.com.google.refine.model.recon.ReconConfig; - - RC.registerReconConfig(module, "strict", Packages.com.google.refine.freebase.model.recon.StrictReconConfig); - RC.registerReconConfig(module, "extend", Packages.com.google.refine.freebase.model.recon.DataExtensionReconConfig); - - var ER = Packages.com.google.refine.exporters.ExporterRegistry; - - ER.registerExporter("tripleloader", new Packages.com.google.refine.freebase.ProtographTransposeExporter.TripleLoaderExporter()); - ER.registerExporter("mqlwrite", new Packages.com.google.refine.freebase.ProtographTransposeExporter.MqlwriteLikeExporter()); - - var FCR = Packages.com.google.refine.grel.ControlFunctionRegistry; - - FCR.registerFunction("mqlKeyQuote", new Packages.com.google.refine.freebase.expr.MqlKeyQuote()); - FCR.registerFunction("mqlKeyUnquote", new Packages.com.google.refine.freebase.expr.MqlKeyUnquote()); - - Packages.com.google.refine.model.Project. - registerOverlayModel("freebaseProtograph", Packages.com.google.refine.freebase.protograph.Protograph); - - ClientSideResourceManager.addPaths( - "project/scripts", - module, - [ - "scripts/extension.js", - - "scripts/util/sign.js", - "scripts/util/freebase.js", - - "scripts/dialogs/freebase-loading-dialog.js", - "scripts/dialogs/extend-data-preview-dialog.js", - - "scripts/dialogs/schema-alignment/dialog.js", - "scripts/dialogs/schema-alignment/ui-node.js", - "scripts/dialogs/schema-alignment/ui-link.js" - ] - ); - - ClientSideResourceManager.addPaths( - "project/styles", - module, - [ - "styles/dialogs/freebase-loading-dialog.less", - "styles/dialogs/extend-data-preview-dialog.less", - "styles/dialogs/schema-alignment-dialog.less" - ] - ); + RS.registerCommand(module, "preview-protograph", new Packages.com.google.refine.freebase.commands.PreviewProtographCommand()); + RS.registerCommand(module, "save-protograph", new Packages.com.google.refine.freebase.commands.SaveProtographCommand()); + + RS.registerCommand(module, "check-authorization", new Packages.com.google.refine.freebase.commands.auth.CheckAuthorizationCommand()); + RS.registerCommand(module, "authorize", new Packages.com.google.refine.freebase.commands.auth.AuthorizeCommand()); + RS.registerCommand(module, "deauthorize", new Packages.com.google.refine.freebase.commands.auth.DeAuthorizeCommand()); + RS.registerCommand(module, "user-badges", new Packages.com.google.refine.freebase.commands.auth.GetUserBadgesCommand()); + + RS.registerCommand(module, "upload-data", new Packages.com.google.refine.freebase.commands.UploadDataCommand()); + RS.registerCommand(module, "import-qa-data", new Packages.com.google.refine.freebase.commands.ImportQADataCommand()); + RS.registerCommand(module, "mqlread", new Packages.com.google.refine.freebase.commands.MQLReadCommand()); + RS.registerCommand(module, "mqlwrite", new Packages.com.google.refine.freebase.commands.MQLWriteCommand()); + + var OR = Packages.com.google.refine.operations.OperationRegistry; + + OR.registerOperation(module, "extend-data", Packages.com.google.refine.freebase.operations.ExtendDataOperation); + OR.registerOperation(module, "import-qa-data", Packages.com.google.refine.freebase.operations.ImportQADataOperation); + OR.registerOperation(module, "save-protograph", Packages.com.google.refine.freebase.operations.SaveProtographOperation); // for backward compatibility + OR.registerOperation(module, "save-schema-alignment-skeleton", Packages.com.google.refine.freebase.operations.SaveProtographOperation); + + var RC = Packages.com.google.refine.model.recon.ReconConfig; + + RC.registerReconConfig(module, "strict", Packages.com.google.refine.freebase.model.recon.StrictReconConfig); + RC.registerReconConfig(module, "extend", Packages.com.google.refine.freebase.model.recon.DataExtensionReconConfig); + + var ER = Packages.com.google.refine.exporters.ExporterRegistry; + + ER.registerExporter("tripleloader", new Packages.com.google.refine.freebase.ProtographTransposeExporter.TripleLoaderExporter()); + ER.registerExporter("mqlwrite", new Packages.com.google.refine.freebase.ProtographTransposeExporter.MqlwriteLikeExporter()); + + var FCR = Packages.com.google.refine.grel.ControlFunctionRegistry; + + FCR.registerFunction("mqlKeyQuote", new Packages.com.google.refine.freebase.expr.MqlKeyQuote()); + FCR.registerFunction("mqlKeyUnquote", new Packages.com.google.refine.freebase.expr.MqlKeyUnquote()); + + Packages.com.google.refine.model.Project. + registerOverlayModel("freebaseProtograph", Packages.com.google.refine.freebase.protograph.Protograph); + + ClientSideResourceManager.addPaths( + "project/scripts", + module, + [ + "scripts/extension.js", + + "scripts/util/sign.js", + "scripts/util/freebase.js", + + "scripts/dialogs/freebase-loading-dialog.js", + "scripts/dialogs/extend-data-preview-dialog.js", + + "scripts/dialogs/schema-alignment/dialog.js", + "scripts/dialogs/schema-alignment/ui-node.js", + "scripts/dialogs/schema-alignment/ui-link.js" + ] + ); + + ClientSideResourceManager.addPaths( + "project/styles", + module, + [ + "styles/dialogs/freebase-loading-dialog.less", + "styles/dialogs/extend-data-preview-dialog.less", + "styles/dialogs/schema-alignment-dialog.less" + ] + ); } diff --git a/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js b/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js index 03bc8cfb2..838280a84 100644 --- a/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js +++ b/extensions/freebase/module/scripts/dialogs/extend-data-preview-dialog.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,368 +29,368 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function ExtendDataPreviewDialog(column, columnIndex, rowIndices, onDone) { - this._column = column; - this._columnIndex = columnIndex; - this._rowIndices = rowIndices; - this._onDone = onDone; - this._extension = { properties: [] }; + this._column = column; + this._columnIndex = columnIndex; + this._rowIndices = rowIndices; + this._onDone = onDone; + this._extension = { properties: [] }; - var self = this; - this._dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/extend-data-preview-dialog.html")); - this._elmts = DOM.bind(this._dialog); - this._elmts.dialogHeader.text("Add Columns from Freebase Based on Column " + column.name); - this._elmts.resetButton.click(function() { - self._extension.properties = []; - self._update(); - }); - - this._elmts.okButton.click(function() { - if (self._extension.properties.length === 0) { - alert("Please add some properties first."); - } else { - DialogSystem.dismissUntil(self._level - 1); - self._onDone(self._extension); - } - }); - this._elmts.cancelButton.click(function() { - DialogSystem.dismissUntil(self._level - 1); - }); - - var dismissBusy = DialogSystem.showBusy(); - var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : "/common/topic"; - - ExtendDataPreviewDialog.getAllProperties(type, function(properties) { - dismissBusy(); - self._show(properties); - }); + var self = this; + this._dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/extend-data-preview-dialog.html")); + this._elmts = DOM.bind(this._dialog); + this._elmts.dialogHeader.text("Add Columns from Freebase Based on Column " + column.name); + this._elmts.resetButton.click(function() { + self._extension.properties = []; + self._update(); + }); + + this._elmts.okButton.click(function() { + if (self._extension.properties.length === 0) { + alert("Please add some properties first."); + } else { + DialogSystem.dismissUntil(self._level - 1); + self._onDone(self._extension); + } + }); + this._elmts.cancelButton.click(function() { + DialogSystem.dismissUntil(self._level - 1); + }); + + var dismissBusy = DialogSystem.showBusy(); + var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : "/common/topic"; + + ExtendDataPreviewDialog.getAllProperties(type, function(properties) { + dismissBusy(); + self._show(properties); + }); } ExtendDataPreviewDialog.getAllProperties = function(typeID, onDone) { - var done = false; - - $.getJSON( - Refine.refineHelperService + "/get_properties_of_type?type=" + typeID + "&callback=?", - null, - function(data) { - if (done) return; - done = true; - - var allProperties = []; - for (var i = 0; i < data.properties.length; i++) { - var property = data.properties[i]; - var property2 = { - id: property.id, - name: property.name - }; - if ("id2" in property) { - property2.expected = property.schema2; - property2.properties = [{ - id: property.id2, - name: property.name2, - expected: property.expects - }]; - } else { - property2.expected = property.expects; - } - allProperties.push(property2); - } - allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); - - onDone(allProperties); + var done = false; + + $.getJSON( + Refine.refineHelperService + "/get_properties_of_type?type=" + typeID + "&callback=?", + null, + function(data) { + if (done) return; + done = true; + + var allProperties = []; + for (var i = 0; i < data.properties.length; i++) { + var property = data.properties[i]; + var property2 = { + id: property.id, + name: property.name + }; + if ("id2" in property) { + property2.expected = property.schema2; + property2.properties = [{ + id: property.id2, + name: property.name2, + expected: property.expects + }]; + } else { + property2.expected = property.expects; } - ); - - window.setTimeout(function() { - if (done) return; - - done = true; - onDone([]); - }, 7000); // time to give up? + allProperties.push(property2); + } + allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); + + onDone(allProperties); + } + ); + + window.setTimeout(function() { + if (done) return; + + done = true; + onDone([]); + }, 7000); // time to give up? }; ExtendDataPreviewDialog.prototype._show = function(properties) { - this._level = DialogSystem.showDialog(this._dialog); - - var n = this._elmts.suggestedPropertyContainer.offset().top + - this._elmts.suggestedPropertyContainer.outerHeight(true) - - this._elmts.addPropertyInput.offset().top; - - this._elmts.previewContainer.height(Math.floor(n)); - - var self = this; - var container = this._elmts.suggestedPropertyContainer; - var renderSuggestedProperty = function(property) { - var label = ("properties" in property) ? (property.name + " » " + property.properties[0].name) : property.name; - var div = $('
').addClass("suggested-property").appendTo(container); - - $('') - .attr("href", "javascript:{}") - .html(label) - .appendTo(div) - .click(function() { - self._addProperty(property); - }); - }; - for (var i = 0; i < properties.length; i++) { - renderSuggestedProperty(properties[i]); - } - - var suggestConfig = { - type: '/type/property' - }; - if ((this._column.reconConfig) && (this._column.reconConfig.type)) { - suggestConfig.ac_param = { schema: this._column.reconConfig.type.id }; - } - - this._elmts.addPropertyInput.suggestP(suggestConfig).bind("fb-select", function(evt, data) { - var expected = data.expected_type; - self._addProperty({ - id : data.id, - name: data.name, - expected: { - id: expected.id, - name: expected.name - } - }); + this._level = DialogSystem.showDialog(this._dialog); + + var n = this._elmts.suggestedPropertyContainer.offset().top + + this._elmts.suggestedPropertyContainer.outerHeight(true) - + this._elmts.addPropertyInput.offset().top; + + this._elmts.previewContainer.height(Math.floor(n)); + + var self = this; + var container = this._elmts.suggestedPropertyContainer; + var renderSuggestedProperty = function(property) { + var label = ("properties" in property) ? (property.name + " » " + property.properties[0].name) : property.name; + var div = $('
').addClass("suggested-property").appendTo(container); + + $('') + .attr("href", "javascript:{}") + .html(label) + .appendTo(div) + .click(function() { + self._addProperty(property); }); + }; + for (var i = 0; i < properties.length; i++) { + renderSuggestedProperty(properties[i]); + } + + var suggestConfig = { + type: '/type/property' + }; + if ((this._column.reconConfig) && (this._column.reconConfig.type)) { + suggestConfig.ac_param = { schema: this._column.reconConfig.type.id }; + } + + this._elmts.addPropertyInput.suggestP(suggestConfig).bind("fb-select", function(evt, data) { + var expected = data.expected_type; + self._addProperty({ + id : data.id, + name: data.name, + expected: { + id: expected.id, + name: expected.name + } + }); + }); }; ExtendDataPreviewDialog.prototype._update = function() { - this._elmts.previewContainer.empty().text("Querying Freebase ..."); - - var self = this; - var params = { - project: theProject.id, - columnName: this._column.name - }; - - $.post( - "/command/freebase/preview-extend-data?" + $.param(params), - { - rowIndices: JSON.stringify(this._rowIndices), - extension: JSON.stringify(this._extension) - }, - function(data) { - self._renderPreview(data); - }, - "json" - ); + this._elmts.previewContainer.empty().text("Querying Freebase ..."); + + var self = this; + var params = { + project: theProject.id, + columnName: this._column.name + }; + + $.post( + "/command/freebase/preview-extend-data?" + $.param(params), + { + rowIndices: JSON.stringify(this._rowIndices), + extension: JSON.stringify(this._extension) + }, + function(data) { + self._renderPreview(data); + }, + "json" + ); }; ExtendDataPreviewDialog.prototype._addProperty = function(p) { - var addSeveralToList = function(properties, oldProperties) { - for (var i = 0; i < properties.length; i++) { - addToList(properties[i], oldProperties); + var addSeveralToList = function(properties, oldProperties) { + for (var i = 0; i < properties.length; i++) { + addToList(properties[i], oldProperties); + } + }; + var addToList = function(property, oldProperties) { + for (var i = 0; i < oldProperties.length; i++) { + var oldProperty = oldProperties[i]; + if (oldProperty.id == property.id) { + if ("included" in property) { + oldProperty.included = "included" in oldProperty ? + (oldProperty.included || property.included) : + property.included; } - }; - var addToList = function(property, oldProperties) { - for (var i = 0; i < oldProperties.length; i++) { - var oldProperty = oldProperties[i]; - if (oldProperty.id == property.id) { - if ("included" in property) { - oldProperty.included = "included" in oldProperty ? - (oldProperty.included || property.included) : - property.included; - } - - if ("properties" in property) { - if ("properties" in oldProperty) { - addSeveralToList(property.properties, oldProperty.properties); - } else { - oldProperty.properties = property.properties; - } - } - return; - } + + if ("properties" in property) { + if ("properties" in oldProperty) { + addSeveralToList(property.properties, oldProperty.properties); + } else { + oldProperty.properties = property.properties; + } } - - oldProperties.push(property); - }; - - addToList(p, this._extension.properties); - - this._update(); + return; + } + } + + oldProperties.push(property); + }; + + addToList(p, this._extension.properties); + + this._update(); }; ExtendDataPreviewDialog.prototype._renderPreview = function(data) { - var self = this; - var container = this._elmts.previewContainer.empty(); - if (data.code == "error") { - container.text("Error."); - return; - } - - var table = $('')[0]; - var trHead = table.insertRow(table.rows.length); - $('
').appendTo(trHead).text(this._column.name); - - var renderColumnHeader = function(column) { - var th = $('').appendTo(trHead); - - $('').html(column.names.join(" » ")).appendTo(th); - $('
').appendTo(th); - - $('') - .text("remove") - .addClass("action") - .attr("title", "Remove this column") - .click(function() { - self._removeProperty(column.path); - }).appendTo(th); - - $('') - .text("constrain") - .addClass("action") - .attr("title", "Add constraints to this column") - .click(function() { - self._constrainProperty(column.path); - }).appendTo(th); - }; - for (var c = 0; c < data.columns.length; c++) { - renderColumnHeader(data.columns[c]); - } - - for (var r = 0; r < data.rows.length; r++) { - var tr = table.insertRow(table.rows.length); - var row = data.rows[r]; - - for (var c = 0; c < row.length; c++) { - var td = tr.insertCell(tr.cells.length); - var cell = row[c]; - if (cell !== null) { - if ($.isPlainObject(cell)) { - $('').attr("href", "http://www.freebase.com/view" + cell.id).text(cell.name).appendTo(td); - } else { - $('').text(cell).appendTo(td); - } - } + var self = this; + var container = this._elmts.previewContainer.empty(); + if (data.code == "error") { + container.text("Error."); + return; + } + + var table = $('')[0]; + var trHead = table.insertRow(table.rows.length); + $(' - +
').appendTo(trHead).text(this._column.name); + + var renderColumnHeader = function(column) { + var th = $('').appendTo(trHead); + + $('').html(column.names.join(" » ")).appendTo(th); + $('
').appendTo(th); + + $('') + .text("remove") + .addClass("action") + .attr("title", "Remove this column") + .click(function() { + self._removeProperty(column.path); + }).appendTo(th); + + $('') + .text("constrain") + .addClass("action") + .attr("title", "Add constraints to this column") + .click(function() { + self._constrainProperty(column.path); + }).appendTo(th); + }; + for (var c = 0; c < data.columns.length; c++) { + renderColumnHeader(data.columns[c]); + } + + for (var r = 0; r < data.rows.length; r++) { + var tr = table.insertRow(table.rows.length); + var row = data.rows[r]; + + for (var c = 0; c < row.length; c++) { + var td = tr.insertCell(tr.cells.length); + var cell = row[c]; + if (cell !== null) { + if ($.isPlainObject(cell)) { + $('').attr("href", "http://www.freebase.com/view" + cell.id).text(cell.name).appendTo(td); + } else { + $('').text(cell).appendTo(td); } + } } - - container.append(table); + } + + container.append(table); }; ExtendDataPreviewDialog.prototype._removeProperty = function(path) { - var removeFromList = function(path, index, properties) { - var id = path[index]; - - for (var i = properties.length - 1; i >= 0; i--) { - var property = properties[i]; - if (property.id == id) { - if (index === path.length - 1) { - if ("included" in property) { - delete property.included; - } - } else if ("properties" in property && property.properties.length > 0) { - removeFromList(path, index + 1, property.properties); - } - - if (!("properties" in property) || property.properties.length === 0) { - properties.splice(i, 1); - } - - return; - } + var removeFromList = function(path, index, properties) { + var id = path[index]; + + for (var i = properties.length - 1; i >= 0; i--) { + var property = properties[i]; + if (property.id == id) { + if (index === path.length - 1) { + if ("included" in property) { + delete property.included; + } + } else if ("properties" in property && property.properties.length > 0) { + removeFromList(path, index + 1, property.properties); } - }; - - removeFromList(path, 0, this._extension.properties); - - this._update(); + + if (!("properties" in property) || property.properties.length === 0) { + properties.splice(i, 1); + } + + return; + } + } + }; + + removeFromList(path, 0, this._extension.properties); + + this._update(); }; ExtendDataPreviewDialog.prototype._findProperty = function(path) { - var find = function(path, index, properties) { - var id = path[index]; - - for (var i = properties.length - 1; i >= 0; i--) { - var property = properties[i]; - if (property.id == id) { - if (index === path.length - 1) { - return property; - } else if ("properties" in property && property.properties.length > 0) { - return find(path, index + 1, property.properties); - } - break; - } + var find = function(path, index, properties) { + var id = path[index]; + + for (var i = properties.length - 1; i >= 0; i--) { + var property = properties[i]; + if (property.id == id) { + if (index === path.length - 1) { + return property; + } else if ("properties" in property && property.properties.length > 0) { + return find(path, index + 1, property.properties); } - - return null; - }; - - return find(path, 0, this._extension.properties); + break; + } + } + + return null; + }; + + return find(path, 0, this._extension.properties); }; ExtendDataPreviewDialog.prototype._constrainProperty = function(path) { - var self = this; - var property = this._findProperty(path); - - var frame = DialogSystem.createDialog(); - frame.width("500px"); - - var header = $('
').addClass("dialog-header").text("Constrain " + path.join(" > ")).appendTo(frame); - var body = $('
').addClass("dialog-body").appendTo(frame); - var footer = $('
').addClass("dialog-footer").appendTo(frame); - - body.html( - '
' + - '' + - '' + - '
' + - 'Enter MQL query constraints as JSON' + - '
' + - '' + - '
' - ); - var bodyElmts = DOM.bind(body); - - if ("constraints" in property) { - bodyElmts.textarea[0].value = JSON.stringify(property.constraints, null, 2); - } else { - bodyElmts.textarea[0].value = JSON.stringify({ "limit" : 10 }, null, 2); + var self = this; + var property = this._findProperty(path); + + var frame = DialogSystem.createDialog(); + frame.width("500px"); + + var header = $('
').addClass("dialog-header").text("Constrain " + path.join(" > ")).appendTo(frame); + var body = $('
').addClass("dialog-body").appendTo(frame); + var footer = $('
').addClass("dialog-footer").appendTo(frame); + + body.html( + '
' + + '' + + '' + + '
' + + 'Enter MQL query constraints as JSON' + + '
' + + '' + + '
' + ); + var bodyElmts = DOM.bind(body); + + if ("constraints" in property) { + bodyElmts.textarea[0].value = JSON.stringify(property.constraints, null, 2); + } else { + bodyElmts.textarea[0].value = JSON.stringify({ "limit" : 10 }, null, 2); + } + + footer.html( + '' + + '' + ); + var footerElmts = DOM.bind(footer); + + var level = DialogSystem.showDialog(frame); + var dismiss = function() { + DialogSystem.dismissUntil(level - 1); + }; + + footerElmts.cancelButton.click(dismiss); + footerElmts.okButton.click(function() { + try { + var o = JSON.parse(bodyElmts.textarea[0].value); + if (o === undefined) { + alert("Please ensure that the JSON you enter is valid."); + return; + } + + if ($.isArray(o) && o.length == 1) { + o = o[0]; + } + if (!$.isPlainObject(o)) { + alert("The JSON you enter must be an object, that is, it is of this form { ... }."); + return; + } + + property.constraints = o; + + dismiss(); + + self._update(); + } catch (e) { + //console.log(e); } - - footer.html( - '' + - '' - ); - var footerElmts = DOM.bind(footer); - - var level = DialogSystem.showDialog(frame); - var dismiss = function() { - DialogSystem.dismissUntil(level - 1); - }; - - footerElmts.cancelButton.click(dismiss); - footerElmts.okButton.click(function() { - try { - var o = JSON.parse(bodyElmts.textarea[0].value); - if (o === undefined) { - alert("Please ensure that the JSON you enter is valid."); - return; - } - - if ($.isArray(o) && o.length == 1) { - o = o[0]; - } - if (!$.isPlainObject(o)) { - alert("The JSON you enter must be an object, that is, it is of this form { ... }."); - return; - } - - property.constraints = o; - - dismiss(); - - self._update(); - } catch (e) { - //console.log(e); - } - }); - - bodyElmts.textarea.focus(); + }); + + bodyElmts.textarea.focus(); }; diff --git a/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.html b/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.html index 2c08d58cc..0eb1d1033 100644 --- a/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.html +++ b/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.html @@ -19,7 +19,8 @@
Source ID (optional)
+

Note: Your data will only be loaded into Sandbox. Sandbox is where everyone can experiment with Freebase technologies without disruption diff --git a/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js b/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js index 679cb6f39..03c35c7e4 100644 --- a/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js +++ b/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,218 +29,219 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function FreebaseLoadingDialog() { - this._createDialog(); - this._signedin = false; + this._createDialog(); + this._signedin = false; } FreebaseLoadingDialog.prototype._createDialog = function() { - var self = this; - var dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/freebase-loading-dialog.html")); - this._elmts = DOM.bind(dialog); - this._elmts.cancelButton.click(function() { self._dismiss(); }); - - var provider = "www.freebase.com"; - var authorization = this._elmts.authorization; - var loadButton = this._elmts.loadButton; - - var check_authorization = function(cont) { - $.get("/command/freebase/check-authorization/" + provider, function(data) { - if ("status" in data && data.code == "/api/status/ok") { - authorization.html('Signed in as: ' + data.username + ' | Sign Out').show(); - DOM.bind(authorization).signout.click(function() { - self._signedin = false; - loadButton.attr("disabled","disabled"); - $("#freebase-loading-graph-selector-freebase").attr("disabled","disabled").button("refresh"); - Sign.signout(check_authorization,provider); - }); - loadButton.unbind().click(function() { - self._load(); - }); - - self._signedin = true; - $("#freebase-loading-source-name").keyup(); - - if (typeof cont == "function") cont(data); + var self = this; + var dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/freebase-loading-dialog.html")); + this._elmts = DOM.bind(dialog); + this._elmts.cancelButton.click(function() { self._dismiss(); }); + + var provider = "www.freebase.com"; + var authorization = this._elmts.authorization; + var loadButton = this._elmts.loadButton; + + var check_authorization = function(cont) { + $.get("/command/freebase/check-authorization/" + provider, function(data) { + if ("status" in data && data.code == "/api/status/ok") { + authorization.html('Signed in as: ' + data.username + ' | Sign Out').show(); + DOM.bind(authorization).signout.click(function() { + self._signedin = false; + loadButton.attr("disabled","disabled"); + $("#freebase-loading-graph-selector-freebase").attr("disabled","disabled").button("refresh"); + Sign.signout(check_authorization,provider); + }); + loadButton.unbind().click(function() { + self._load(); + }); + + self._signedin = true; + $("#freebase-loading-source-name").keyup(); + + if (typeof cont == "function") cont(data); + } else { + authorization.html('Sign into Freebase to enable loading').show(); + + self._signedin = false; + $("#freebase-loading-source-name").keyup(); + + DOM.bind(authorization).signin.click(function() { + Sign.signin(function() { + check_authorization(cont); + },provider); + }); + } + },"json"); + }; + + var make_topic = function(new_topic_id, topic_type, cont) { + var mql_query = [{ + "create": "unless_exists", + "name": new_topic_id, + "a:type": topic_type, + "b:type": "/common/topic", + "id": null, + "guid": null + }]; + + $.post("/command/freebase/mqlwrite/" + provider, + { "query" : JSON.stringify(mql_query) }, + function(data) { + if ("status" in data && data.code == "/api/status/ok") { + self._elmts.source_id.val(data.result[0].id); + if (typeof cont == "function") cont(); + } else { + self._show_error("Error creating new topic", data); + } + }, + "json" + ); + }; + + var show_triples = function(cont) { + $.post( + "/command/freebase/preview-protograph?" + $.param({ project: theProject.id }), + { + protograph: JSON.stringify(theProject.overlayModels.freebaseProtograph || {}), + engine: JSON.stringify(ui.browsingEngine.getJSON()) + }, + function(data) { + if ("tripleloader" in data) { + self._elmts.functionalCase.show(); + self._level = DialogSystem.showDialog(dialog); + + self._elmts.functionalTabs.tabs(); + + self._elmts.previewContainer.text(data.tripleloader).show(); + + self._elmts.source_name.keyup(function() { + if (self._signedin && $(this).val() != "") { + loadButton.removeAttr("disabled").removeClass("button-disabled"); } else { - authorization.html('Sign into Freebase to enable loading').show(); - - self._signedin = false; - $("#freebase-loading-source-name").keyup(); - - DOM.bind(authorization).signin.click(function() { - Sign.signin(function() { - check_authorization(cont); - },provider); - }); + loadButton.attr("disabled","disabled").addClass("button-disabled"); } - },"json"); - }; - - var make_topic = function(new_topic_id, topic_type, cont) { - var mql_query = [{ - "create": "unless_exists", - "name": new_topic_id, - "a:type": topic_type, - "b:type": "/common/topic", - "id": null, - "guid": null - }]; + }); - $.post("/command/freebase/mqlwrite/" + provider, - { "query" : JSON.stringify(mql_query) }, + self._elmts.source_id.suggest({ + "type": "/dataworld/information_source", + "suggest_new": "Click here to add a new information source" + }).bind("fb-select", function(e, data) { + self._elmts.source_id.val(data.id); + }).bind("fb-select-new", function(e, val) { + make_topic(val, "/dataworld/information_source"); + }); + + $.getJSON( + "/command/core/get-preference?" + $.param({ project: theProject.id, name: "freebase.load.jobName" }), + null, function(data) { - if ("status" in data && data.code == "/api/status/ok") { - self._elmts.source_id.val(data.result[0].id); - if (typeof cont == "function") cont(); - } else { - self._show_error("Error creating new topic", data); - } - }, - "json" - ); - }; - - var show_triples = function(cont) { - $.post( - "/command/freebase/preview-protograph?" + $.param({ project: theProject.id }), - { - protograph: JSON.stringify(theProject.overlayModels.freebaseProtograph || {}), - engine: JSON.stringify(ui.browsingEngine.getJSON()) - }, - function(data) { - if ("tripleloader" in data) { - self._elmts.functionalCase.show(); - self._level = DialogSystem.showDialog(dialog); - - self._elmts.functionalTabs.tabs(); - - self._elmts.previewContainer.text(data.tripleloader).show(); - - self._elmts.source_name.keyup(function() { - if (self._signedin && $(this).val() != "") { - loadButton.removeAttr("disabled").removeClass("button-disabled"); - } else { - loadButton.attr("disabled","disabled").addClass("button-disabled"); - } - }); - - self._elmts.source_id.suggest({ - "type": "/dataworld/information_source", - "suggest_new": "Click here to add a new information source" - }).bind("fb-select", function(e, data) { - self._elmts.source_id.val(data.id); - }).bind("fb-select-new", function(e, val) { - make_topic(val, "/dataworld/information_source"); - }); + self._elmts.source_name[0].value = (data.value) ? data.value : theProject.metadata.name; + } + ); - $.getJSON( - "/command/core/get-preference?" + $.param({ project: theProject.id, name: "freebase.load.jobName" }), - null, - function(data) { - self._elmts.source_name[0].value = (data.value) ? data.value : theProject.metadata.name; - } - ); + if (typeof cont == "function") cont(); + } else { + self._elmts.unalignedCase.show(); + self._level = DialogSystem.showDialog(dialog); - if (typeof cont == "function") cont(); - } else { - self._elmts.unalignedCase.show(); - self._level = DialogSystem.showDialog(dialog); - - self._elmts.alignButton.click(function() { - self._dismiss(); - FreebaseExtension.handlers.editSchemaAlignment(false); - }); - self._end(); - } - }, - "json" - ); - }; + self._elmts.alignButton.click(function() { + self._dismiss(); + FreebaseExtension.handlers.editSchemaAlignment(false); + }); + self._end(); + } + }, + "json" + ); + }; - show_triples(check_authorization); + show_triples(check_authorization); }; FreebaseLoadingDialog.prototype._load = function() { - var self = this; - var qa = self._elmts.qaCheckbox.is(':checked'); + var self = this; + var qa = self._elmts.qaCheckbox.is(':checked'); - var get_refinery_url = function(url) { - return "http://refinery.freebaseapps.com/load/" + url.split("/").slice(-1)[0]; + var get_refinery_url = function(url) { + return "http://refinery.freebaseapps.com/load/" + url.split("/").slice(-1)[0]; + }; + + var doLoad = function() { + var dismissBusy = DialogSystem.showBusy(); + + $.post( + "/command/freebase/upload-data", + { + "project" : theProject.id, + "qa" : qa, + "engine" : JSON.stringify(ui.browsingEngine.getJSON()), + "source_name" : self._elmts.source_name.val(), + "source_id" : self._elmts.source_id.val() + }, + function(data) { + dismissBusy(); + + var body = self._elmts.dialogBody; + if ("status" in data && typeof data.status == "object" && "code" in data.status && data.status.code == 200) { + self._elmts.tripleCountSpan.text(data.result.added); + self._elmts.refineryLink.attr("href", get_refinery_url(data.result.status_url)); + self._elmts.functionalCase.hide(); + self._elmts.loadedCase.show(); + self._end(); + } else { + self._show_error("Error loading data",data); + } + }, + "json" + ); + }; + + if (qa) { + var dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/confirm-qa-dialog.html")); + var elmts = DOM.bind(dialog); + var level = DialogSystem.showDialog(dialog); + var dismiss = function() { + DialogSystem.dismissUntil(level - 1); }; - - var doLoad = function() { - var dismissBusy = DialogSystem.showBusy(); - - $.post("/command/freebase/upload-data", - { - project: theProject.id, - "qa" : qa, - "engine" : JSON.stringify(ui.browsingEngine.getJSON()), - "source_name" : self._elmts.source_name.val(), - "source_id" : self._elmts.source_id.val() - }, - function(data) { - dismissBusy(); - - var body = self._elmts.dialogBody; - if ("status" in data && typeof data.status == "object" && "code" in data.status && data.status.code == 200) { - self._elmts.tripleCountSpan.text(data.result.added); - self._elmts.refineryLink.attr("href", get_refinery_url(data.result.status_url)); - self._elmts.functionalCase.hide(); - self._elmts.loadedCase.show(); - self._end(); - } else { - self._show_error("Error loading data",data); - } - }, - "json" - ); - }; - - if (qa) { - var dialog = $(DOM.loadHTML("freebase", "scripts/dialogs/confirm-qa-dialog.html")); - var elmts = DOM.bind(dialog); - var level = DialogSystem.showDialog(dialog); - var dismiss = function() { - DialogSystem.dismissUntil(level - 1); - }; - - elmts.okButton.click(function() { - doLoad(); - dismiss(); - }); - elmts.cancelButton.click(function() { - dismiss(); - }); - } else { - doLoad(); - } + + elmts.okButton.click(function() { + doLoad(); + dismiss(); + }); + elmts.cancelButton.click(function() { + dismiss(); + }); + } else { + doLoad(); + } }; FreebaseLoadingDialog.prototype._dismiss = function() { - DialogSystem.dismissUntil(this._level - 1); + DialogSystem.dismissUntil(this._level - 1); }; FreebaseLoadingDialog.prototype._show_error = function(msg, error) { - this._elmts.dialogBody.children().hide(); - this._elmts.errorCase.show(); - this._elmts.errorMessage.text(msg); - this._elmts.errorDetails.html( - (('message' in error) ? '

' + error.message + '

' : '
' + JSON.stringify(error, null, 2) + '
') + - (('stack' in error) ? '
' + error.stack.replace(/\\n/g,'\n').replace(/\\t/g,'\t') + '
' : "") - ); - this._end(); - console.log(error); + this._elmts.dialogBody.children().hide(); + this._elmts.errorCase.show(); + this._elmts.errorMessage.text(msg); + this._elmts.errorDetails.html( + (('message' in error) ? '

' + error.message + '

' : '
' + JSON.stringify(error, null, 2) + '
') + + (('stack' in error) ? '
' + error.stack.replace(/\\n/g,'\n').replace(/\\t/g,'\t') + '
' : "") + ); + this._end(); + console.log(error); }; FreebaseLoadingDialog.prototype._end = function() { - var self = this; - this._elmts.loadButton.text("Close").removeAttr("disabled").removeClass("button-disabled").unbind().click(function() { - self._dismiss(); - }); - this._elmts.cancelButton.hide(); - this._elmts.authorization.hide(); + var self = this; + this._elmts.loadButton.text("Close").removeAttr("disabled").removeClass("button-disabled").unbind().click(function() { + self._dismiss(); + }); + this._elmts.cancelButton.hide(); + this._elmts.authorization.hide(); }; \ No newline at end of file diff --git a/extensions/freebase/module/scripts/dialogs/schema-alignment/dialog.js b/extensions/freebase/module/scripts/dialogs/schema-alignment/dialog.js index 39b3bfb6d..210bf44be 100644 --- a/extensions/freebase/module/scripts/dialogs/schema-alignment/dialog.js +++ b/extensions/freebase/module/scripts/dialogs/schema-alignment/dialog.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,283 +29,283 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ var SchemaAlignment = {}; SchemaAlignment.autoAlign = function() { - var protograph = {}; - - var columns = theProject.columnModel.columns; - - var typedCandidates = []; - var candidates = []; - - for (var c = 0; c < columns.length; c++) { - var column = columns[c]; - var typed = (column.reconConfig) && - ReconciliationManager.isFreebaseIdOrMid(column.reconConfig.identifierSpace) && - ReconciliationManager.isFreebaseId(column.reconConfig.schemaSpace); - - var candidate = { - status: "unbound", - typed: typed, - index: c, - column: column - }; - - candidates.push(candidate); - if (typed) { - typedCandidates.push(candidate); - } + var protograph = {}; + + var columns = theProject.columnModel.columns; + + var typedCandidates = []; + var candidates = []; + + for (var c = 0; c < columns.length; c++) { + var column = columns[c]; + var typed = (column.reconConfig) && + ReconciliationManager.isFreebaseIdOrMid(column.reconConfig.identifierSpace) && + ReconciliationManager.isFreebaseId(column.reconConfig.schemaSpace); + + var candidate = { + status: "unbound", + typed: typed, + index: c, + column: column + }; + + candidates.push(candidate); + if (typed) { + typedCandidates.push(candidate); } - - if (typedCandidates.length > 0) { - - } else { - var queries = {}; - for (var i = 0; i < candidates.length; i++) { - var candidate = candidates[i]; - var name = SchemaAlignment._cleanName(candidate.column.name); - var key = "t" + i + ":search"; - queries[key] = { - "query" : name, - "limit" : 10, - "type" : "/type/type,/type/property", - "type_strict" : "any" - }; - } - - SchemaAlignment._batchSearch(queries, function(result) { - console.log(result); - }); + } + + if (typedCandidates.length > 0) { + + } else { + var queries = {}; + for (var i = 0; i < candidates.length; i++) { + var candidate = candidates[i]; + var name = SchemaAlignment._cleanName(candidate.column.name); + var key = "t" + i + ":search"; + queries[key] = { + "query" : name, + "limit" : 10, + "type" : "/type/type,/type/property", + "type_strict" : "any" + }; } + + SchemaAlignment._batchSearch(queries, function(result) { + console.log(result); + }); + } }; SchemaAlignment._batchSearch = function(queries, onDone) { - var keys = []; - for (var n in queries) { - if (queries.hasOwnProperty(n)) { - keys.push(n); - } + var keys = []; + for (var n in queries) { + if (queries.hasOwnProperty(n)) { + keys.push(n); } - - var result = {}; - var args = []; - var makeBatch = function(keyBatch) { - var batch = {}; - for (var k = 0; k < keyBatch.length; k++) { - var key = keyBatch[k]; - batch[key] = queries[key]; - } - - args.push("http://api.freebase.com/api/service/search?" + - $.param({ "queries" : JSON.stringify(batch) }) + "&callback=?"); - - args.push(null); // no data - args.push(function(data) { - for (var k = 0; k < keyBatch.length; k++) { - var key = keyBatch[k]; - result[key] = data[key]; - } - }); - }; - - for (var i = 0; i < keys.length; i += 10) { - makeBatch(keys.slice(i, i + 10)); + } + + var result = {}; + var args = []; + var makeBatch = function(keyBatch) { + var batch = {}; + for (var k = 0; k < keyBatch.length; k++) { + var key = keyBatch[k]; + batch[key] = queries[key]; } - - args.push(function() { - onDone(result); + + args.push("http://api.freebase.com/api/service/search?" + + $.param({ "queries" : JSON.stringify(batch) }) + "&callback=?"); + + args.push(null); // no data + args.push(function(data) { + for (var k = 0; k < keyBatch.length; k++) { + var key = keyBatch[k]; + result[key] = data[key]; + } }); - - Ajax.chainGetJSON.apply(null, args); + }; + + for (var i = 0; i < keys.length; i += 10) { + makeBatch(keys.slice(i, i + 10)); + } + + args.push(function() { + onDone(result); + }); + + Ajax.chainGetJSON.apply(null, args); }; SchemaAlignment._cleanName = function(s) { - return s.replace(/\W/g, " ").replace(/\s+/g, " ").toLowerCase(); + return s.replace(/\W/g, " ").replace(/\s+/g, " ").toLowerCase(); }; SchemaAlignment.createNewRootNode = function() { - var rootNode = null; - var links = []; - var columns = theProject.columnModel.columns; - for (var i = 0; i < columns.length; i++) { - var column = columns[i]; - var target = { - nodeType: "cell-as-topic", - columnName: column.name, - createForNoReconMatch: true - }; - if ((column.reconConfig) && - ReconciliationManager.isFreebaseIdOrMid(column.reconConfig.identifierSpace) && - ReconciliationManager.isFreebaseId(column.reconConfig.schemaSpace) && - (column.reconConfig.type)) { + var rootNode = null; + var links = []; + var columns = theProject.columnModel.columns; + for (var i = 0; i < columns.length; i++) { + var column = columns[i]; + var target = { + nodeType: "cell-as-topic", + columnName: column.name, + createForNoReconMatch: true + }; + if ((column.reconConfig) && + ReconciliationManager.isFreebaseIdOrMid(column.reconConfig.identifierSpace) && + ReconciliationManager.isFreebaseId(column.reconConfig.schemaSpace) && + (column.reconConfig.type)) { - target.type = { - id: column.reconConfig.type.id, - name: column.reconConfig.type.name - }; - } - - if (column.name == theProject.columnModel.keyColumnName) { - rootNode = target; - } else { - links.push({ - property: null, - target: target - }); - } + target.type = { + id: column.reconConfig.type.id, + name: column.reconConfig.type.name + }; } - - rootNode = rootNode || { nodeType: "cell-as-topic" }; - rootNode.links = links; - - return rootNode; + + if (column.name == theProject.columnModel.keyColumnName) { + rootNode = target; + } else { + links.push({ + property: null, + target: target + }); + } + } + + rootNode = rootNode || { nodeType: "cell-as-topic" }; + rootNode.links = links; + + return rootNode; }; function SchemaAlignmentDialog(protograph, onDone) { - this._onDone = onDone; - this._hasUnsavedChanges = false; - - this._createDialog(); - this._reset(protograph, true); + this._onDone = onDone; + this._hasUnsavedChanges = false; + + this._createDialog(); + this._reset(protograph, true); } SchemaAlignmentDialog.prototype._reset = function(protograph, initial) { - this._originalProtograph = protograph || { rootNodes: [] }; - this._protograph = cloneDeep(this._originalProtograph); // this is what can be munched on - - if (!this._protograph.rootNodes.length) { - this._protograph.rootNodes.push(SchemaAlignment.createNewRootNode()); - } - - $(this._nodeTable).empty(); - - this._nodeUIs = []; - for (var i = 0; i < this._protograph.rootNodes.length; i++) { - this._nodeUIs.push(new SchemaAlignmentDialog.UINode( - this, - this._protograph.rootNodes[i], - this._nodeTable, - { - expanded: true, - mustBeCellTopic: true - } - )); - } - - this.preview(initial); + this._originalProtograph = protograph || { rootNodes: [] }; + this._protograph = cloneDeep(this._originalProtograph); // this is what can be munched on + + if (!this._protograph.rootNodes.length) { + this._protograph.rootNodes.push(SchemaAlignment.createNewRootNode()); + } + + $(this._nodeTable).empty(); + + this._nodeUIs = []; + for (var i = 0; i < this._protograph.rootNodes.length; i++) { + this._nodeUIs.push(new SchemaAlignmentDialog.UINode( + this, + this._protograph.rootNodes[i], + this._nodeTable, + { + expanded: true, + mustBeCellTopic: true + } + )); + } + + this.preview(initial); }; SchemaAlignmentDialog.prototype._save = function(onDone) { - var self = this; - var protograph = this.getJSON(); - - Refine.postProcess( - "freebase", - "save-protograph", - {}, - { protograph: JSON.stringify(protograph) }, - {}, - { - onDone: function() { - theProject.overlayModels.freebaseProtograph = protograph; - - self._elmts.statusIndicator.hide(); - self._hasUnsavedChanges = false; - - if (onDone) onDone(); - } - } - ); + var self = this; + var protograph = this.getJSON(); + + Refine.postProcess( + "freebase", + "save-protograph", + {}, + { protograph: JSON.stringify(protograph) }, + {}, + { + onDone: function() { + theProject.overlayModels.freebaseProtograph = protograph; + + self._elmts.statusIndicator.hide(); + self._hasUnsavedChanges = false; + + if (onDone) onDone(); + } + } + ); }; SchemaAlignmentDialog.prototype._createDialog = function() { - var self = this; - var frame = $(DOM.loadHTML("freebase", "scripts/dialogs/schema-alignment/schema-alignment-dialog.html")); - var elmts = this._elmts = DOM.bind(frame); - - this._level = DialogSystem.showDialog(frame); - - var dismiss = function() { - DialogSystem.dismissUntil(self._level - 1); - }; - - elmts.saveButton.click(function() { - self._save(); - }); - elmts.saveAndLoadButton.click(function() { - self._save(function() { - dismiss(); - FreebaseExtension.handlers.loadIntoFreebase(); - }); - }); - elmts.resetButton.click(function() { - self._reset(null); - }); - elmts.closeButton.click(function() { - if (!self._hasUnsavedChanges || window.confirm("There are unsaved changes. Close anyway?")) { - dismiss(); - } - }); - - $("#schema-alignment-tabs").tabs(); - $("#schema-alignment-tabs-preview-mqllike").css("display", ""); - $("#schema-alignment-tabs-preview-tripleloader").css("display", ""); + var self = this; + var frame = $(DOM.loadHTML("freebase", "scripts/dialogs/schema-alignment/schema-alignment-dialog.html")); + var elmts = this._elmts = DOM.bind(frame); - this._previewPanes = $(".schema-alignment-dialog-preview"); - - this._canvas = $(".schema-alignment-dialog-canvas"); - this._nodeTable = $('
').addClass("schema-alignment-table-layout").appendTo(this._canvas)[0]; + this._level = DialogSystem.showDialog(frame); + + var dismiss = function() { + DialogSystem.dismissUntil(self._level - 1); + }; + + elmts.saveButton.click(function() { + self._save(); + }); + elmts.saveAndLoadButton.click(function() { + self._save(function() { + dismiss(); + FreebaseExtension.handlers.loadIntoFreebase(); + }); + }); + elmts.resetButton.click(function() { + self._reset(null); + }); + elmts.closeButton.click(function() { + if (!self._hasUnsavedChanges || window.confirm("There are unsaved changes. Close anyway?")) { + dismiss(); + } + }); + + $("#schema-alignment-tabs").tabs(); + $("#schema-alignment-tabs-preview-mqllike").css("display", ""); + $("#schema-alignment-tabs-preview-tripleloader").css("display", ""); + + this._previewPanes = $(".schema-alignment-dialog-preview"); + + this._canvas = $(".schema-alignment-dialog-canvas"); + this._nodeTable = $('
').addClass("schema-alignment-table-layout").appendTo(this._canvas)[0]; }; SchemaAlignmentDialog.prototype.getJSON = function() { - var rootNodes = []; - for (var i = 0; i < this._nodeUIs.length; i++) { - var node = this._nodeUIs[i].getJSON(); - if (node !== null) { - rootNodes.push(node); - } + var rootNodes = []; + for (var i = 0; i < this._nodeUIs.length; i++) { + var node = this._nodeUIs[i].getJSON(); + if (node !== null) { + rootNodes.push(node); } - - return { - rootNodes: rootNodes - }; + } + + return { + rootNodes: rootNodes + }; }; SchemaAlignmentDialog.prototype.preview = function(initial) { - var self = this; - - this._previewPanes.empty(); - if (!(initial)) { - this._elmts.statusIndicator.show().text("There are unsaved changes."); - this._hasUnsavedChanges = true; - } - - var protograph = this.getJSON(); - $.post( - "/command/freebase/preview-protograph?" + $.param({ project: theProject.id }), - { protograph: JSON.stringify(protograph), engine: JSON.stringify(ui.browsingEngine.getJSON()) }, - function(data) { - if ("mqllike" in data) { - $(self._previewPanes[0]).text(JSON.stringify(data.mqllike, null, 2)); - } - if ("tripleloader" in data) { - $(self._previewPanes[1]).text(data.tripleloader); - } - }, - "json" - ); + var self = this; + + this._previewPanes.empty(); + if (!(initial)) { + this._elmts.statusIndicator.show().text("There are unsaved changes."); + this._hasUnsavedChanges = true; + } + + var protograph = this.getJSON(); + $.post( + "/command/freebase/preview-protograph?" + $.param({ project: theProject.id }), + { protograph: JSON.stringify(protograph), engine: JSON.stringify(ui.browsingEngine.getJSON()) }, + function(data) { + if ("mqllike" in data) { + $(self._previewPanes[0]).text(JSON.stringify(data.mqllike, null, 2)); + } + if ("tripleloader" in data) { + $(self._previewPanes[1]).text(data.tripleloader); + } + }, + "json" + ); }; SchemaAlignmentDialog._findColumn = function(cellIndex) { - var columns = theProject.columnModel.columns; - for (var i = 0; i < columns.length; i++) { - var column = columns[i]; - if (column.cellIndex == cellIndex) { - return column; - } + var columns = theProject.columnModel.columns; + for (var i = 0; i < columns.length; i++) { + var column = columns[i]; + if (column.cellIndex == cellIndex) { + return column; } - return null; + } + return null; }; diff --git a/extensions/freebase/module/scripts/dialogs/schema-alignment/schema-alignment-dialog.html b/extensions/freebase/module/scripts/dialogs/schema-alignment/schema-alignment-dialog.html index e2d92eaab..ace6f0493 100644 --- a/extensions/freebase/module/scripts/dialogs/schema-alignment/schema-alignment-dialog.html +++ b/extensions/freebase/module/scripts/dialogs/schema-alignment/schema-alignment-dialog.html @@ -7,20 +7,20 @@ Find out more ...

- -
-
-
- - + +
+
+
+ +
').appendTo(tr); - var checkbox = $('') - .attr("type", "checkbox") - .attr("index", index) - .appendTo(tdSelect) - .click(function() { - files[index].selected = this.checked; - self._updateFileSelectionSummary(); - }); - if (fileRecord.selected) { - checkbox.attr("checked", "checked"); - } - - $('').text(fileRecord.fileName).addClass("default-importing-file-selection-filename").appendTo(tr); - $('').text(fileRecord.declaredMimeType || fileRecord.mimeType || "unknown").appendTo(tr); - $('').text(fileRecord.format || "unknown").appendTo(tr); - $('').text(fileRecord.size + " bytes").appendTo(tr); - }; - - for (var i = 0; i < files.length; i++) { - renderFile(files[i], i); + this._fileSelectionPanelElmts.filePanel.empty(); + + var fileTable = $('
NameMime-typeFormatSize
') + .appendTo(this._fileSelectionPanelElmts.filePanel)[0]; + + var files = this._job.config.retrievalRecord.files; + var renderFile = function(fileRecord, index) { + var tr = fileTable.insertRow(fileTable.rows.length); + $(tr).addClass(index % 2 == 0 ? 'even' : 'odd'); + + var tdSelect = $('
').appendTo(tr); + var checkbox = $('') + .attr("type", "checkbox") + .attr("index", index) + .appendTo(tdSelect) + .click(function() { + files[index].selected = this.checked; + self._updateFileSelectionSummary(); + }); + if (fileRecord.selected) { + checkbox.attr("checked", "checked"); } + + $('').text(fileRecord.fileName).addClass("default-importing-file-selection-filename").appendTo(tr); + $('').text(fileRecord.declaredMimeType || fileRecord.mimeType || "unknown").appendTo(tr); + $('').text(fileRecord.format || "unknown").appendTo(tr); + $('').text(fileRecord.size + " bytes").appendTo(tr); + }; + + for (var i = 0; i < files.length; i++) { + renderFile(files[i], i); + } }; Refine.DefaultImportingController.prototype._renderFileSelectionPanelControlPanel = function() { - var self = this; - var files = this._job.config.retrievalRecord.files; - - this._fileSelectionPanelElmts.extensionContainer.empty(); - this._fileSelectionPanelElmts.selectAllButton.unbind().click(function(evt) { - for (var i = 0; i < files.length; i++) { - files[i].selected = true; - } - self._fileSelectionPanelElmts.filePanel.find("input").attr("checked", "checked"); - self._updateFileSelectionSummary(); - }); - this._fileSelectionPanelElmts.unselectAllButton.unbind().click(function(evt) { - for (var i = 0; i < files.length; i++) { - files[i].selected = false; - } - self._fileSelectionPanelElmts.filePanel.find("input").removeAttr("checked"); - self._updateFileSelectionSummary(); - }); - - var table = $('
') - .appendTo(this._fileSelectionPanelElmts.extensionContainer)[0]; - - var renderExtension = function(extension) { - var tr = table.insertRow(table.rows.length); - $('
').text(extension.extension).appendTo(tr); - $('').text(extension.count + (extension.count > 1 ? " files" : " file")).appendTo(tr); - $('').appendTo(tr)) - .click(function() { - for (var i = 0; i < files.length; i++) { - var file = files[i]; - if (!file.selected) { - if (file.fileName.endsWith(extension.extension)) { - file.selected = true; - self._fileSelectionPanelElmts.filePanel - .find("input[index='" + i + "']") - .attr("checked", "checked"); - } - } - } - self._updateFileSelectionSummary(); - }); - $('').appendTo(tr)) - .click(function() { - for (var i = 0; i < files.length; i++) { - var file = files[i]; - if (file.selected) { - if (file.fileName.endsWith(extension.extension)) { - file.selected = false; - self._fileSelectionPanelElmts.filePanel - .find("input[index='" + i + "']") - .removeAttr("checked"); - } - } - } - self._updateFileSelectionSummary(); - }); - }; - for (var i = 0; i < this._extensions.length; i++) { - renderExtension(this._extensions[i]); + var self = this; + var files = this._job.config.retrievalRecord.files; + + this._fileSelectionPanelElmts.extensionContainer.empty(); + this._fileSelectionPanelElmts.selectAllButton.unbind().click(function(evt) { + for (var i = 0; i < files.length; i++) { + files[i].selected = true; } - - this._updateFileSelectionSummary(); - - this._fileSelectionPanelElmts.regexInput.unbind().keyup(function() { - var count = 0; - var elmts = self._fileSelectionPanelElmts.filePanel - .find(".default-importing-file-selection-filename") - .removeClass("highlighted"); - try { - var regex = new RegExp(this.value); - elmts.each(function() { - if (regex.test($(this).text())) { - $(this).addClass("highlighted"); - count++; - } - }); - } catch (e) { - // Ignore + self._fileSelectionPanelElmts.filePanel.find("input").attr("checked", "checked"); + self._updateFileSelectionSummary(); + }); + this._fileSelectionPanelElmts.unselectAllButton.unbind().click(function(evt) { + for (var i = 0; i < files.length; i++) { + files[i].selected = false; + } + self._fileSelectionPanelElmts.filePanel.find("input").removeAttr("checked"); + self._updateFileSelectionSummary(); + }); + + var table = $('
') + .appendTo(this._fileSelectionPanelElmts.extensionContainer)[0]; + + var renderExtension = function(extension) { + var tr = table.insertRow(table.rows.length); + $('
').text(extension.extension).appendTo(tr); + $('').text(extension.count + (extension.count > 1 ? " files" : " file")).appendTo(tr); + $('').appendTo(tr)) + .click(function() { + for (var i = 0; i < files.length; i++) { + var file = files[i]; + if (!file.selected) { + if (file.fileName.endsWith(extension.extension)) { + file.selected = true; + self._fileSelectionPanelElmts.filePanel + .find("input[index='" + i + "']") + .attr("checked", "checked"); + } } - self._fileSelectionPanelElmts.regexSummary.text(count + (count == 1 ? " match" : " matches")); + } + self._updateFileSelectionSummary(); }); - this._fileSelectionPanelElmts.selectRegexButton.unbind().click(function() { - self._fileSelectionPanelElmts.filePanel - .find(".default-importing-file-selection-filename") - .removeClass("highlighted"); - try { - var regex = new RegExp(self._fileSelectionPanelElmts.regexInput[0].value); - for (var i = 0; i < files.length; i++) { - var file = files[i]; - if (!file.selected) { - if (regex.test(file.fileName)) { - file.selected = true; - self._fileSelectionPanelElmts.filePanel - .find("input[index='" + i + "']") - .attr("checked", "checked"); - } - } - } - self._updateFileSelectionSummary(); - } catch (e) { - // Ignore + $('').appendTo(tr)) + .click(function() { + for (var i = 0; i < files.length; i++) { + var file = files[i]; + if (file.selected) { + if (file.fileName.endsWith(extension.extension)) { + file.selected = false; + self._fileSelectionPanelElmts.filePanel + .find("input[index='" + i + "']") + .removeAttr("checked"); + } } + } + self._updateFileSelectionSummary(); }); - this._fileSelectionPanelElmts.unselectRegexButton.unbind().click(function() { - self._fileSelectionPanelElmts.filePanel - .find(".default-importing-file-selection-filename") - .removeClass("highlighted"); - try { - var regex = new RegExp(self._fileSelectionPanelElmts.regexInput[0].value); - for (var i = 0; i < files.length; i++) { - var file = files[i]; - if (file.selected) { - if (regex.test(file.fileName)) { - file.selected = false; - self._fileSelectionPanelElmts.filePanel - .find("input[index='" + i + "']") - .removeAttr("checked"); - } - } - } - self._updateFileSelectionSummary(); - } catch (e) { - // Ignore + }; + for (var i = 0; i < this._extensions.length; i++) { + renderExtension(this._extensions[i]); + } + + this._updateFileSelectionSummary(); + + this._fileSelectionPanelElmts.regexInput.unbind().keyup(function() { + var count = 0; + var elmts = self._fileSelectionPanelElmts.filePanel + .find(".default-importing-file-selection-filename") + .removeClass("highlighted"); + try { + var regex = new RegExp(this.value); + elmts.each(function() { + if (regex.test($(this).text())) { + $(this).addClass("highlighted"); + count++; } - }); + }); + } catch (e) { + // Ignore + } + self._fileSelectionPanelElmts.regexSummary.text(count + (count == 1 ? " match" : " matches")); + }); + this._fileSelectionPanelElmts.selectRegexButton.unbind().click(function() { + self._fileSelectionPanelElmts.filePanel + .find(".default-importing-file-selection-filename") + .removeClass("highlighted"); + try { + var regex = new RegExp(self._fileSelectionPanelElmts.regexInput[0].value); + for (var i = 0; i < files.length; i++) { + var file = files[i]; + if (!file.selected) { + if (regex.test(file.fileName)) { + file.selected = true; + self._fileSelectionPanelElmts.filePanel + .find("input[index='" + i + "']") + .attr("checked", "checked"); + } + } + } + self._updateFileSelectionSummary(); + } catch (e) { + // Ignore + } + }); + this._fileSelectionPanelElmts.unselectRegexButton.unbind().click(function() { + self._fileSelectionPanelElmts.filePanel + .find(".default-importing-file-selection-filename") + .removeClass("highlighted"); + try { + var regex = new RegExp(self._fileSelectionPanelElmts.regexInput[0].value); + for (var i = 0; i < files.length; i++) { + var file = files[i]; + if (file.selected) { + if (regex.test(file.fileName)) { + file.selected = false; + self._fileSelectionPanelElmts.filePanel + .find("input[index='" + i + "']") + .removeAttr("checked"); + } + } + } + self._updateFileSelectionSummary(); + } catch (e) { + // Ignore + } + }); }; Refine.DefaultImportingController.prototype._updateFileSelectionSummary = function() { - var fileSelection = []; - var files = this._job.config.retrievalRecord.files; - for (var i = 0; i < files.length; i++) { - if (files[i].selected) { - fileSelection.push(i); - } + var fileSelection = []; + var files = this._job.config.retrievalRecord.files; + for (var i = 0; i < files.length; i++) { + if (files[i].selected) { + fileSelection.push(i); } - this._job.config.fileSelection = fileSelection; - this._fileSelectionPanelElmts.summary.text(fileSelection.length + " of " + files.length + " files selected"); + } + this._job.config.fileSelection = fileSelection; + this._fileSelectionPanelElmts.summary.text(fileSelection.length + " of " + files.length + " files selected"); }; Refine.DefaultImportingController.prototype._commitFileSelection = function() { - if (this._job.config.fileSelection.length == 0) { - alert("Please select at least one file."); + if (this._job.config.fileSelection.length == 0) { + alert("Please select at least one file."); + return; + } + + var self = this; + var dismissBusy = DialogSystem.showBusy("Inspecting selected files ..."); + $.post( + "/command/core/importing-controller?" + $.param({ + "controller": "core/default-importing-controller", + "jobID": this._jobID, + "subCommand": "update-file-selection" + }), + { + "fileSelection" : JSON.stringify(this._job.config.fileSelection) + }, + function(data) { + if (!(data)) { + self._showImportJobError("Unknown error"); + window.clearInterval(timerID); return; - } - - var self = this; - var dismissBusy = DialogSystem.showBusy("Inspecting selected files ..."); - $.post( - "/command/core/importing-controller?" + $.param({ - "controller": "core/default-importing-controller", - "jobID": this._jobID, - "subCommand": "update-file-selection" - }), - { - "fileSelection" : JSON.stringify(this._job.config.fileSelection) - }, - function(data) { - if (!(data)) { - self._showImportJobError("Unknown error"); - window.clearInterval(timerID); - return; - } else if (data.code == "error" || !("job" in data)) { - self._showImportJobError(data.message || "Unknown error"); - window.clearInterval(timerID); - return; - } - - dismissBusy(); - - // Different files might be selected. We start over again. - delete this._parserOptions; - - self._job = data.job; - self._showParsingPanel(true); - }, - "json" - ); + } else if (data.code == "error" || !("job" in data)) { + self._showImportJobError(data.message || "Unknown error"); + window.clearInterval(timerID); + return; + } + + dismissBusy(); + + // Different files might be selected. We start over again. + delete this._parserOptions; + + self._job = data.job; + self._showParsingPanel(true); + }, + "json" + ); }; diff --git a/main/webapp/modules/core/scripts/index/default-importing-controller/parsing-panel.js b/main/webapp/modules/core/scripts/index/default-importing-controller/parsing-panel.js index 7c6f78759..4757d8b4c 100644 --- a/main/webapp/modules/core/scripts/index/default-importing-controller/parsing-panel.js +++ b/main/webapp/modules/core/scripts/index/default-importing-controller/parsing-panel.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,158 +29,158 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.DefaultImportingController.prototype._showParsingPanel = function(hasFileSelection) { - var self = this; - - if (!(this._format)) { - this._format = this._job.config.rankedFormats[0]; - } - if (!(this._parserOptions)) { - this._parserOptions = {}; - } - - this._prepareParsingPanel(); - this._parsingPanelElmts.nextButton.click(function() { - self._createProject(); + var self = this; + + if (!(this._format)) { + this._format = this._job.config.rankedFormats[0]; + } + if (!(this._parserOptions)) { + this._parserOptions = {}; + } + + this._prepareParsingPanel(); + this._parsingPanelElmts.nextButton.click(function() { + self._createProject(); + }); + if (hasFileSelection) { + this._parsingPanelElmts.previousButton.click(function() { + self._createProjectUI.showCustomPanel(self._fileSelectionPanel); }); - if (hasFileSelection) { - this._parsingPanelElmts.previousButton.click(function() { - self._createProjectUI.showCustomPanel(self._fileSelectionPanel); - }); - } else { - this._parsingPanelElmts.previousButton.hide(); - } - - if (!(this._projectName) && this._job.config.fileSelection.length > 0) { - var index = this._job.config.fileSelection[0]; - var record = this._job.config.retrievalRecord.files[index]; - this._projectName = $.trim(record.fileName.replace(/\W/g, ' ').replace(/\s+/g, ' ')); - } - if (this._projectName) { - this._parsingPanelElmts.projectNameInput[0].value = this._projectName; - } - - this._createProjectUI.showCustomPanel(this._parsingPanel); + } else { + this._parsingPanelElmts.previousButton.hide(); + } + + if (!(this._projectName) && this._job.config.fileSelection.length > 0) { + var index = this._job.config.fileSelection[0]; + var record = this._job.config.retrievalRecord.files[index]; + this._projectName = $.trim(record.fileName.replace(/\W/g, ' ').replace(/\s+/g, ' ')); + } + if (this._projectName) { + this._parsingPanelElmts.projectNameInput[0].value = this._projectName; + } + + this._createProjectUI.showCustomPanel(this._parsingPanel); }; Refine.DefaultImportingController.prototype._disposeFileSelectionPanel = function() { - this._disposeParserUI(); - - if (this._parsingPanelResizer) { - $(window).unbind("resize", this._parsingPanelResizer); - } - - this._parsingPanel.unbind().empty(); - delete this._parsingPanelElmts; + this._disposeParserUI(); + + if (this._parsingPanelResizer) { + $(window).unbind("resize", this._parsingPanelResizer); + } + + this._parsingPanel.unbind().empty(); + delete this._parsingPanelElmts; }; Refine.DefaultImportingController.prototype._prepareParsingPanel = function() { - var self = this; - - this._parsingPanel.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/default-importing-controller/parsing-panel.html")); - - this._parsingPanelElmts = DOM.bind(this._parsingPanel); - this._parsingPanelElmts.startOverButton.click(function() { - self._startOver(); + var self = this; + + this._parsingPanel.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/default-importing-controller/parsing-panel.html")); + + this._parsingPanelElmts = DOM.bind(this._parsingPanel); + this._parsingPanelElmts.startOverButton.click(function() { + self._startOver(); + }); + this._parsingPanelElmts.progressPanel.hide(); + + this._parsingPanelResizer = function() {console.log("here"); + var elmts = self._parsingPanelElmts; + var width = self._parsingPanel.width(); + var height = self._parsingPanel.height(); + var headerHeight = elmts.wizardHeader.outerHeight(true); + var controlPanelHeight = 300; + + elmts.dataPanel + .css("left", "0px") + .css("top", headerHeight + "px") + .css("width", (width - DOM.getHPaddings(elmts.dataPanel)) + "px") + .css("height", (height - headerHeight - controlPanelHeight - DOM.getVPaddings(elmts.dataPanel)) + "px"); + elmts.progressPanel + .css("left", "0px") + .css("top", headerHeight + "px") + .css("width", (width - DOM.getHPaddings(elmts.progressPanel)) + "px") + .css("height", (height - headerHeight - controlPanelHeight - DOM.getVPaddings(elmts.progressPanel)) + "px"); + + elmts.controlPanel + .css("left", "0px") + .css("top", (height - controlPanelHeight) + "px") + .css("width", (width - DOM.getHPaddings(elmts.controlPanel)) + "px") + .css("height", (controlPanelHeight - DOM.getVPaddings(elmts.controlPanel)) + "px"); + }; + + $(window).resize(this._parsingPanelResizer); + this._parsingPanelResizer(); + + var formats = this._job.config.rankedFormats; + var createFormatTab = function(format) { + var tab = $('
') + .text(Refine.importingConfig.formats[format].label) + .attr("format", format) + .addClass("default-importing-parsing-control-panel-format") + .appendTo(self._parsingPanelElmts.formatsContainer) + .click(function() { + self._selectFormat(format); }); - this._parsingPanelElmts.progressPanel.hide(); - - this._parsingPanelResizer = function() {console.log("here"); - var elmts = self._parsingPanelElmts; - var width = self._parsingPanel.width(); - var height = self._parsingPanel.height(); - var headerHeight = elmts.wizardHeader.outerHeight(true); - var controlPanelHeight = 300; - - elmts.dataPanel - .css("left", "0px") - .css("top", headerHeight + "px") - .css("width", (width - DOM.getHPaddings(elmts.dataPanel)) + "px") - .css("height", (height - headerHeight - controlPanelHeight - DOM.getVPaddings(elmts.dataPanel)) + "px"); - elmts.progressPanel - .css("left", "0px") - .css("top", headerHeight + "px") - .css("width", (width - DOM.getHPaddings(elmts.progressPanel)) + "px") - .css("height", (height - headerHeight - controlPanelHeight - DOM.getVPaddings(elmts.progressPanel)) + "px"); - - elmts.controlPanel - .css("left", "0px") - .css("top", (height - controlPanelHeight) + "px") - .css("width", (width - DOM.getHPaddings(elmts.controlPanel)) + "px") - .css("height", (controlPanelHeight - DOM.getVPaddings(elmts.controlPanel)) + "px"); - }; - - $(window).resize(this._parsingPanelResizer); - this._parsingPanelResizer(); - - var formats = this._job.config.rankedFormats; - var createFormatTab = function(format) { - var tab = $('
') - .text(Refine.importingConfig.formats[format].label) - .attr("format", format) - .addClass("default-importing-parsing-control-panel-format") - .appendTo(self._parsingPanelElmts.formatsContainer) - .click(function() { - self._selectFormat(format); - }); - - if (format == self._format) { - tab.addClass("selected"); - } - }; - for (var i = 0; i < formats.length; i++) { - createFormatTab(formats[i]); + + if (format == self._format) { + tab.addClass("selected"); } - this._selectFormat(this._format); + }; + for (var i = 0; i < formats.length; i++) { + createFormatTab(formats[i]); + } + this._selectFormat(this._format); }; Refine.DefaultImportingController.prototype._disposeParserUI = function() { - if (this._formatParserUI) { - this._formatParserUI.dispose(); - delete this._formatParserUI; - } - if (this._parsingPanelElmts) { - this._parsingPanelElmts.optionsContainer.unbind().empty(); - this._parsingPanelElmts.progressPanel.unbind(); - this._parsingPanelElmts.dataPanel.unbind().empty(); - } + if (this._formatParserUI) { + this._formatParserUI.dispose(); + delete this._formatParserUI; + } + if (this._parsingPanelElmts) { + this._parsingPanelElmts.optionsContainer.unbind().empty(); + this._parsingPanelElmts.progressPanel.unbind(); + this._parsingPanelElmts.dataPanel.unbind().empty(); + } }; Refine.DefaultImportingController.prototype._selectFormat = function(newFormat) { - if (newFormat == this._format && (this._formatParserUI)) { - // The new format is the same as the existing one. - return; - } - - var uiClassName = Refine.importingConfig.formats[newFormat].uiClass; - var uiClass = Refine.DefaultImportingController.parserUIs[uiClassName]; - if (uiClass) { - var self = this; - this._ensureFormatParserUIHasInitializationData(newFormat, function() { - self._disposeParserUI(); - self._parsingPanelElmts.formatsContainer - .find(".default-importing-parsing-control-panel-format") - .removeClass("selected") - .each(function() { - if (this.getAttribute("format") == newFormat) { - $(this).addClass("selected"); - } - }); - - self._format = newFormat; - self._formatParserUI = new uiClass( - self, - self._jobID, - self._job, - self._format, - self._parserOptions[newFormat], - self._parsingPanelElmts.dataPanel, - self._parsingPanelElmts.progressPanel, - self._parsingPanelElmts.optionsContainer - ); - }); - } + if (newFormat == this._format && (this._formatParserUI)) { + // The new format is the same as the existing one. + return; + } + + var uiClassName = Refine.importingConfig.formats[newFormat].uiClass; + var uiClass = Refine.DefaultImportingController.parserUIs[uiClassName]; + if (uiClass) { + var self = this; + this._ensureFormatParserUIHasInitializationData(newFormat, function() { + self._disposeParserUI(); + self._parsingPanelElmts.formatsContainer + .find(".default-importing-parsing-control-panel-format") + .removeClass("selected") + .each(function() { + if (this.getAttribute("format") == newFormat) { + $(this).addClass("selected"); + } + }); + + self._format = newFormat; + self._formatParserUI = new uiClass( + self, + self._jobID, + self._job, + self._format, + self._parserOptions[newFormat], + self._parsingPanelElmts.dataPanel, + self._parsingPanelElmts.progressPanel, + self._parsingPanelElmts.optionsContainer + ); + }); + } }; diff --git a/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js b/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js index 0770dd28f..40cc254a1 100644 --- a/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js +++ b/main/webapp/modules/core/scripts/index/default-importing-sources/sources.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,90 +29,90 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function ThisComputerImportingSourceUI(controller) { - this._controller = controller; + this._controller = controller; } Refine.DefaultImportingController.sources.push({ - "label": "This Computer", - "id": "upload", - "uiClass": ThisComputerImportingSourceUI + "label": "This Computer", + "id": "upload", + "uiClass": ThisComputerImportingSourceUI }); ThisComputerImportingSourceUI.prototype.attachUI = function(bodyDiv) { - var self = this; - - bodyDiv.html(DOM.loadHTML("core", "scripts/index/default-importing-sources/import-from-computer-form.html")); + var self = this; - this._elmts = DOM.bind(bodyDiv); - this._elmts.nextButton.click(function(evt) { - if (self._elmts.fileInput[0].files.length === 0) { - window.alert("You must specify a data file to import."); - } else { - self._controller.startImportJob(self._elmts.form, "Uploading data ..."); - } - }); + bodyDiv.html(DOM.loadHTML("core", "scripts/index/default-importing-sources/import-from-computer-form.html")); + + this._elmts = DOM.bind(bodyDiv); + this._elmts.nextButton.click(function(evt) { + if (self._elmts.fileInput[0].files.length === 0) { + window.alert("You must specify a data file to import."); + } else { + self._controller.startImportJob(self._elmts.form, "Uploading data ..."); + } + }); }; ThisComputerImportingSourceUI.prototype.focus = function() { }; function UrlImportingSourceUI(controller) { - this._controller = controller; + this._controller = controller; } Refine.DefaultImportingController.sources.push({ - "label": "Web Addresses (URLs)", - "id": "download", - "uiClass": UrlImportingSourceUI + "label": "Web Addresses (URLs)", + "id": "download", + "uiClass": UrlImportingSourceUI }); UrlImportingSourceUI.prototype.attachUI = function(bodyDiv) { - var self = this; - - bodyDiv.html(DOM.loadHTML("core", "scripts/index/default-importing-sources/import-from-web-form.html")); + var self = this; - this._elmts = DOM.bind(bodyDiv); - this._elmts.nextButton.click(function(evt) { - if ($.trim(self._elmts.urlInput[0].value.length) === 0) { - window.alert("You must specify a web address (URL) to import."); - } else { - self._controller.startImportJob(self._elmts.form, "Downloading data ..."); - } - }); - this._elmts.addButton.click(function(evt) { - self._elmts.buttons.before(self._elmts.urlRow.clone()); - }); + bodyDiv.html(DOM.loadHTML("core", "scripts/index/default-importing-sources/import-from-web-form.html")); + + this._elmts = DOM.bind(bodyDiv); + this._elmts.nextButton.click(function(evt) { + if ($.trim(self._elmts.urlInput[0].value.length) === 0) { + window.alert("You must specify a web address (URL) to import."); + } else { + self._controller.startImportJob(self._elmts.form, "Downloading data ..."); + } + }); + this._elmts.addButton.click(function(evt) { + self._elmts.buttons.before(self._elmts.urlRow.clone()); + }); }; UrlImportingSourceUI.prototype.focus = function() { - this._elmts.urlInput.focus(); + this._elmts.urlInput.focus(); }; function ClipboardImportingSourceUI(controller) { - this._controller = controller; + this._controller = controller; } Refine.DefaultImportingController.sources.push({ - "label": "Clipboard", - "id": "clipboard", - "uiClass": ClipboardImportingSourceUI + "label": "Clipboard", + "id": "clipboard", + "uiClass": ClipboardImportingSourceUI }); ClipboardImportingSourceUI.prototype.attachUI = function(bodyDiv) { - var self = this; - - bodyDiv.html(DOM.loadHTML("core", "scripts/index/default-importing-sources/import-from-clipboard-form.html")); + var self = this; - this._elmts = DOM.bind(bodyDiv); - this._elmts.nextButton.click(function(evt) { - if ($.trim(self._elmts.textInput[0].value).length === 0) { - window.alert("You must paste some data to import."); - } else { - self._controller.startImportJob(self._elmts.form, "Uploading pasted data ..."); - } - }); + bodyDiv.html(DOM.loadHTML("core", "scripts/index/default-importing-sources/import-from-clipboard-form.html")); + + this._elmts = DOM.bind(bodyDiv); + this._elmts.nextButton.click(function(evt) { + if ($.trim(self._elmts.textInput[0].value).length === 0) { + window.alert("You must paste some data to import."); + } else { + self._controller.startImportJob(self._elmts.form, "Uploading pasted data ..."); + } + }); }; ClipboardImportingSourceUI.prototype.focus = function() { - this._elmts.textInput.focus(); + this._elmts.textInput.focus(); }; \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/index/open-project-ui.js b/main/webapp/modules/core/scripts/index/open-project-ui.js index b4a159bf1..77b5b420a 100644 --- a/main/webapp/modules/core/scripts/index/open-project-ui.js +++ b/main/webapp/modules/core/scripts/index/open-project-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,242 +29,242 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.OpenProjectUI = function(elmt) { - var self = this; + var self = this; - elmt.html(DOM.loadHTML("core", "scripts/index/open-project-ui.html")); + elmt.html(DOM.loadHTML("core", "scripts/index/open-project-ui.html")); - this._elmt = elmt; - this._elmts = DOM.bind(elmt); + this._elmt = elmt; + this._elmts = DOM.bind(elmt); - var resize = function() { - var height = elmt.height(); - var width = elmt.width(); - var controlsHeight = self._elmts.workspaceControls.outerHeight(); - self._elmts.projectsContainer - .css("height", (height - controlsHeight - DOM.getVPaddings(self._elmts.projectsContainer)) + "px"); - self._elmts.workspaceControls - .css("bottom", "0px") - .css("width", (width - DOM.getHPaddings(self._elmts.workspaceControls)) + "px") - }; - $(window).resize(resize); - window.setTimeout(resize, 100); + var resize = function() { + var height = elmt.height(); + var width = elmt.width(); + var controlsHeight = self._elmts.workspaceControls.outerHeight(); + self._elmts.projectsContainer + .css("height", (height - controlsHeight - DOM.getVPaddings(self._elmts.projectsContainer)) + "px"); + self._elmts.workspaceControls + .css("bottom", "0px") + .css("width", (width - DOM.getHPaddings(self._elmts.workspaceControls)) + "px") + }; + $(window).resize(resize); + window.setTimeout(resize, 100); - $("#project-file-input").change(function() { - if ($("#project-name-input")[0].value.length == 0) { - var fileName = this.files[0].fileName; - if (fileName) { - $("#project-name-input")[0].value = fileName.replace(/\.\w+/, "").replace(/[_-]/g, " "); - } - $("#project-name-input").focus().select(); - } - }).keypress(function(evt) { - if (evt.keyCode == 13) { - return self._onClickUploadFileButton(evt); + $("#project-file-input").change(function() { + if ($("#project-name-input")[0].value.length == 0) { + var fileName = this.files[0].fileName; + if (fileName) { + $("#project-name-input")[0].value = fileName.replace(/\.\w+/, "").replace(/[_-]/g, " "); + } + $("#project-name-input").focus().select(); + } + }).keypress(function(evt) { + if (evt.keyCode == 13) { + return self._onClickUploadFileButton(evt); + } + }); + + $("#upload-file-button").click(function(evt) { + return self._onClickUploadFileButton(evt) + }); + + $('#projects-workspace-open').click(function() { + $.ajax({ + type: "POST", + url: "/command/core/open-workspace-dir", + dataType: "json", + success: function (data) { + if (data.code != "ok" && "message" in data) { + alert(data.message); } + } }); + }); - $("#upload-file-button").click(function(evt) { - return self._onClickUploadFileButton(evt) - }); - - $('#projects-workspace-open').click(function() { - $.ajax({ - type: "POST", - url: "/command/core/open-workspace-dir", - dataType: "json", - success: function (data) { - if (data.code != "ok" && "message" in data) { - alert(data.message); - } - } - }); - }); - - this._fetchProjects(); + this._fetchProjects(); }; Refine.OpenProjectUI.prototype._fetchProjects = function() { - var self = this; - $.getJSON( - "/command/core/get-all-project-metadata", - null, - function(data) { - self._renderProjects(data); - }, - "json" - ); + var self = this; + $.getJSON( + "/command/core/get-all-project-metadata", + null, + function(data) { + self._renderProjects(data); + }, + "json" + ); }; Refine.OpenProjectUI.prototype._renderProjects = function(data) { - var self = this; - var projects = []; - for (var n in data.projects) { - if (data.projects.hasOwnProperty(n)) { - var project = data.projects[n]; - project.id = n; - project.date = Date.parseExact(project.modified, "yyyy-MM-ddTHH:mm:ssZ"); - projects.push(project); - } + var self = this; + var projects = []; + for (var n in data.projects) { + if (data.projects.hasOwnProperty(n)) { + var project = data.projects[n]; + project.id = n; + project.date = Date.parseExact(project.modified, "yyyy-MM-ddTHH:mm:ssZ"); + projects.push(project); } - projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); }); + } + projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); }); - var container = $("#projects-container").empty(); - if (!projects.length) { - $("#no-project-message").clone().show().appendTo(container); - } else { - Refine.selectActionArea('open-project'); - - var table = $( - '' + - '' + - '' + - '' + - '' + - '
NameLast modified
' - ).appendTo(container)[0]; + var container = $("#projects-container").empty(); + if (!projects.length) { + $("#no-project-message").clone().show().appendTo(container); + } else { + Refine.selectActionArea('open-project'); - var formatDate = function(d) { - var d = new Date(d); - var last_year = Date.today().add({ years: -1 }); - var last_month = Date.today().add({ months: -1 }); - var last_week = Date.today().add({ days: -7 }); - var today = Date.today(); - var tomorrow = Date.today().add({ days: 1 }); + var table = $( + '' + + '' + + '' + + '' + + '' + + '
NameLast modified
' + ).appendTo(container)[0]; - if (d.between(today, tomorrow)) { - return "today " + d.toString("h:mm tt"); - } else if (d.between(last_week, today)) { - var diff = Math.floor(today.getDayOfYear() - d.getDayOfYear()); - return (diff <= 1) ? ("yesterday " + d.toString("h:mm tt")) : (diff + " days ago"); - } else if (d.between(last_month, today)) { - var diff = Math.floor((today.getDayOfYear() - d.getDayOfYear()) / 7); - return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ; - } else if (d.between(last_year, today)) { - var diff = Math.floor(today.getMonth() - d.getMonth()); - return (diff == 1) ? "a month ago" : diff + " months ago"; + var formatDate = function(d) { + var d = new Date(d); + var last_year = Date.today().add({ years: -1 }); + var last_month = Date.today().add({ months: -1 }); + var last_week = Date.today().add({ days: -7 }); + var today = Date.today(); + var tomorrow = Date.today().add({ days: 1 }); + + if (d.between(today, tomorrow)) { + return "today " + d.toString("h:mm tt"); + } else if (d.between(last_week, today)) { + var diff = Math.floor(today.getDayOfYear() - d.getDayOfYear()); + return (diff <= 1) ? ("yesterday " + d.toString("h:mm tt")) : (diff + " days ago"); + } else if (d.between(last_month, today)) { + var diff = Math.floor((today.getDayOfYear() - d.getDayOfYear()) / 7); + return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ; + } else if (d.between(last_year, today)) { + var diff = Math.floor(today.getMonth() - d.getMonth()); + return (diff == 1) ? "a month ago" : diff + " months ago"; + } else { + var diff = Math.floor(today.getYear() - d.getYear()); + return (diff == 1) ? "a year ago" : diff + " years ago"; + } + }; + + var renderProject = function(project) { + var tr = table.insertRow(table.rows.length); + tr.className = "project"; + + var nameLink = $('') + .addClass("list-table-itemname") + .text(project.name) + .attr("href", "/project?project=" + project.id) + .appendTo(tr.insertCell(tr.cells.length)); + + var renameLink = $('') + .text("rename") + .addClass("secondary") + .attr("href", "javascript:{}") + .css("visibility", "hidden") + .click(function() { + var name = window.prompt("New project name:", project.name); + if (name == null) { + return; + } + + name = $.trim(name); + if (project.name == name || name.length == 0) { + return; + } + + $.ajax({ + type: "POST", + url: "/command/core/rename-project", + data: { "project" : project.id, "name" : name }, + dataType: "json", + success: function (data) { + if (data && typeof data.code != 'undefined' && data.code == "ok") { + nameLink.text(name); } else { - var diff = Math.floor(today.getYear() - d.getYear()); - return (diff == 1) ? "a year ago" : diff + " years ago"; + alert("Failed to rename project: " + data.message) } - }; - - var renderProject = function(project) { - var tr = table.insertRow(table.rows.length); - tr.className = "project"; + } + }); + }).appendTo(tr.insertCell(tr.cells.length)); - var nameLink = $('') - .addClass("list-table-itemname") - .text(project.name) - .attr("href", "/project?project=" + project.id) - .appendTo(tr.insertCell(tr.cells.length)); - - var renameLink = $('') - .text("rename") - .addClass("secondary") - .attr("href", "javascript:{}") - .css("visibility", "hidden") - .click(function() { - var name = window.prompt("New project name:", project.name); - if (name == null) { - return; - } - - name = $.trim(name); - if (project.name == name || name.length == 0) { - return; - } - - $.ajax({ - type: "POST", - url: "/command/core/rename-project", - data: { "project" : project.id, "name" : name }, - dataType: "json", - success: function (data) { - if (data && typeof data.code != 'undefined' && data.code == "ok") { - nameLink.text(name); - } else { - alert("Failed to rename project: " + data.message) - } - } - }); - }).appendTo(tr.insertCell(tr.cells.length)); - - var deleteLink = $('') - .addClass("delete-project") - .attr("title","Delete this project") - .attr("href","") - .css("visibility", "hidden") - .html("") - .click(function() { - if (window.confirm("Are you sure you want to delete project \"" + project.name + "\"?")) { - $.ajax({ - type: "POST", - url: "/command/core/delete-project", - data: { "project" : project.id }, - dataType: "json", - success: function (data) { - if (data && typeof data.code != 'undefined' && data.code == "ok") { - self._fetchProjects(); - } - } - }); - } - return false; - }).appendTo(tr.insertCell(tr.cells.length)); - - - $('
') - .html(formatDate(project.date)) - .addClass("last-modified") - .attr("title", project.date.toString()) - .appendTo(tr.insertCell(tr.cells.length)); - - $(tr).mouseenter(function() { - renameLink.css("visibility", "visible"); - deleteLink.css("visibility", "visible"); - }).mouseleave(function() { - renameLink.css("visibility", "hidden"); - deleteLink.css("visibility", "hidden"); - }); - }; - - for (var i = 0; i < projects.length; i++) { - renderProject(projects[i]); + var deleteLink = $('') + .addClass("delete-project") + .attr("title","Delete this project") + .attr("href","") + .css("visibility", "hidden") + .html("") + .click(function() { + if (window.confirm("Are you sure you want to delete project \"" + project.name + "\"?")) { + $.ajax({ + type: "POST", + url: "/command/core/delete-project", + data: { "project" : project.id }, + dataType: "json", + success: function (data) { + if (data && typeof data.code != 'undefined' && data.code == "ok") { + self._fetchProjects(); + } + } + }); } + return false; + }).appendTo(tr.insertCell(tr.cells.length)); + + + $('
') + .html(formatDate(project.date)) + .addClass("last-modified") + .attr("title", project.date.toString()) + .appendTo(tr.insertCell(tr.cells.length)); + + $(tr).mouseenter(function() { + renameLink.css("visibility", "visible"); + deleteLink.css("visibility", "visible"); + }).mouseleave(function() { + renameLink.css("visibility", "hidden"); + deleteLink.css("visibility", "hidden"); + }); + }; + + for (var i = 0; i < projects.length; i++) { + renderProject(projects[i]); } + } }; Refine.OpenProjectUI.prototype._onClickUploadFileButton = function(evt) { - var projectName = $("#project-name-input")[0].value; - var dataURL = $.trim($("#project-url-input")[0].value); - if (! $.trim(projectName).length) { - window.alert("You must specify a project name."); + var projectName = $("#project-name-input")[0].value; + var dataURL = $.trim($("#project-url-input")[0].value); + if (! $.trim(projectName).length) { + window.alert("You must specify a project name."); - } else if ($("#project-file-input")[0].files.length === 0 && ! dataURL.length) { - window.alert("You must specify a data file to upload or a URL to retrieve."); + } else if ($("#project-file-input")[0].files.length === 0 && ! dataURL.length) { + window.alert("You must specify a data file to upload or a URL to retrieve."); - } else { - $("#file-upload-form").attr("action", - "/command/core/create-project-from-upload?" + [ - "url=" + escape(dataURL), - "split-into-columns=" + $("#split-into-columns-input")[0].checked, - "separator=" + $("#separator-input")[0].value, - "ignore=" + $("#ignore-input")[0].value, - "header-lines=" + $("#header-lines-input")[0].value, - "skip=" + $("#skip-input")[0].value, - "limit=" + $("#limit-input")[0].value, - "guess-value-type=" + $("#guess-value-type-input")[0].checked, - "ignore-quotes=" + $("#ignore-quotes-input")[0].checked - ].join("&")); + } else { + $("#file-upload-form").attr("action", + "/command/core/create-project-from-upload?" + [ + "url=" + escape(dataURL), + "split-into-columns=" + $("#split-into-columns-input")[0].checked, + "separator=" + $("#separator-input")[0].value, + "ignore=" + $("#ignore-input")[0].value, + "header-lines=" + $("#header-lines-input")[0].value, + "skip=" + $("#skip-input")[0].value, + "limit=" + $("#limit-input")[0].value, + "guess-value-type=" + $("#guess-value-type-input")[0].checked, + "ignore-quotes=" + $("#ignore-quotes-input")[0].checked + ].join("&")); - return true; - } + return true; + } - evt.preventDefault(); - return false; + evt.preventDefault(); + return false; }; Refine.actionAreas.push({ diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js index 1f1acbc5e..f7982d089 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,31 +29,31 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.ExcelParserUI = function(controller, jobID, job, format, config, dataContainerElmt, progressContainerElmt, optionContainerElmt) { - this._controller = controller; - this._jobID = jobID; - this._job = job; - this._format = format; - this._config = config; - - this._dataContainer = dataContainerElmt; - this._progressContainer = progressContainerElmt; - this._optionContainer = optionContainerElmt; - - this._timerID = null; - this._initialize(); - this._updatePreview(); + this._controller = controller; + this._jobID = jobID; + this._job = job; + this._format = format; + this._config = config; + + this._dataContainer = dataContainerElmt; + this._progressContainer = progressContainerElmt; + this._optionContainer = optionContainerElmt; + + this._timerID = null; + this._initialize(); + this._updatePreview(); }; Refine.DefaultImportingController.parserUIs["ExcelParserUI"] = Refine.ExcelParserUI; Refine.ExcelParserUI.prototype.dispose = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } }; Refine.ExcelParserUI.prototype.confirmReadyToCreateProject = function() { @@ -61,138 +61,138 @@ Refine.ExcelParserUI.prototype.confirmReadyToCreateProject = function() { }; Refine.ExcelParserUI.prototype.getOptions = function() { - var options = { - xmlBased: this._config.xmlBased, - sheets: [] - }; - - var parseIntDefault = function(s, def) { - try { - var n = parseInt(s); - if (!isNaN(n)) { - return n; - } - } catch (e) { - // Ignore - } - return def; - }; - - this._optionContainerElmts.sheetRecordContainer.find('input').each(function() { - if (this.checked) { - options.sheets.push(parseInt(this.getAttribute('index'))); + var options = { + xmlBased: this._config.xmlBased, + sheets: [] + }; + + var parseIntDefault = function(s, def) { + try { + var n = parseInt(s); + if (!isNaN(n)) { + return n; } - }); - - if (this._optionContainerElmts.ignoreCheckbox[0].checked) { - options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); - } else { - options.ignoreLines = -1; + } catch (e) { + // Ignore } - if (this._optionContainerElmts.headerLinesCheckbox[0].checked) { - options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0); - } else { - options.headerLines = 0; + return def; + }; + + this._optionContainerElmts.sheetRecordContainer.find('input').each(function() { + if (this.checked) { + options.sheets.push(parseInt(this.getAttribute('index'))); } - if (this._optionContainerElmts.skipCheckbox[0].checked) { - options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0); - } else { - options.skipDataLines = 0; - } - if (this._optionContainerElmts.limitCheckbox[0].checked) { - options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); - } else { - options.limit = -1; - } - options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; - options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; - options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; - - return options; + }); + + if (this._optionContainerElmts.ignoreCheckbox[0].checked) { + options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); + } else { + options.ignoreLines = -1; + } + if (this._optionContainerElmts.headerLinesCheckbox[0].checked) { + options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0); + } else { + options.headerLines = 0; + } + if (this._optionContainerElmts.skipCheckbox[0].checked) { + options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0); + } else { + options.skipDataLines = 0; + } + if (this._optionContainerElmts.limitCheckbox[0].checked) { + options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); + } else { + options.limit = -1; + } + options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; + options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; + options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; + + return options; }; Refine.ExcelParserUI.prototype._initialize = function() { - var self = this; - - this._optionContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/excel-parser-ui.html")); - this._optionContainerElmts = DOM.bind(this._optionContainer); - this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); - - var sheetTable = this._optionContainerElmts.sheetRecordContainer[0]; - $.each(this._config.sheetRecords, function(i, v) { - var tr = sheetTable.insertRow(sheetTable.rows.length); - var td0 = $(tr.insertCell(0)).attr('width', '1%'); - var checkbox = $('') - .attr('type', 'checkbox') - .attr('index', i) - .appendTo(td0); - if (this.selected) { - checkbox.attr('checked', 'true'); - } - - $(tr.insertCell(1)).text(this.name); - $(tr.insertCell(2)).text(this.rows + ' rows'); - }); - - if (this._config.ignoreLines > 0) { - this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); - this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); + var self = this; + + this._optionContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/excel-parser-ui.html")); + this._optionContainerElmts = DOM.bind(this._optionContainer); + this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); + + var sheetTable = this._optionContainerElmts.sheetRecordContainer[0]; + $.each(this._config.sheetRecords, function(i, v) { + var tr = sheetTable.insertRow(sheetTable.rows.length); + var td0 = $(tr.insertCell(0)).attr('width', '1%'); + var checkbox = $('') + .attr('type', 'checkbox') + .attr('index', i) + .appendTo(td0); + if (this.selected) { + checkbox.attr('checked', 'true'); } - if (this._config.headerLines > 0) { - this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked"); - this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString(); - } - if (this._config.limit > 0) { - this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); - this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); - } - if (this._config.skipDataLines > 0) { - this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); - this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); - } - if (this._config.storeBlankRows) { - this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); - } - if (this._config.storeBlankCellsAsNulls) { - this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); - } - if (this._config.includeFileSources) { - this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); - } - - var onChange = function() { - self._scheduleUpdatePreview(); - }; - this._optionContainer.find("input").bind("change", onChange); - this._optionContainer.find("select").bind("change", onChange); + + $(tr.insertCell(1)).text(this.name); + $(tr.insertCell(2)).text(this.rows + ' rows'); + }); + + if (this._config.ignoreLines > 0) { + this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); + this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); + } + if (this._config.headerLines > 0) { + this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked"); + this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString(); + } + if (this._config.limit > 0) { + this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); + this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); + } + if (this._config.skipDataLines > 0) { + this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); + this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); + } + if (this._config.storeBlankRows) { + this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); + } + if (this._config.storeBlankCellsAsNulls) { + this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); + } + if (this._config.includeFileSources) { + this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); + } + + var onChange = function() { + self._scheduleUpdatePreview(); + }; + this._optionContainer.find("input").bind("change", onChange); + this._optionContainer.find("select").bind("change", onChange); }; Refine.ExcelParserUI.prototype._scheduleUpdatePreview = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } - - var self = this; - this._timerID = window.setTimeout(function() { - self._timerID = null; - self._updatePreview(); - }, 500); // 0.5 second + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } + + var self = this; + this._timerID = window.setTimeout(function() { + self._timerID = null; + self._updatePreview(); + }, 500); // 0.5 second }; Refine.ExcelParserUI.prototype._updatePreview = function() { - var self = this; - - this._progressContainer.show(); - - this._controller.updateFormatAndOptions(this.getOptions(), function(result) { - if (result.status == "ok") { - self._controller.getPreviewData(function(projectData) { - self._progressContainer.hide(); - - new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); - }); - } - }); + var self = this; + + this._progressContainer.show(); + + this._controller.updateFormatAndOptions(this.getOptions(), function(result) { + if (result.status == "ok") { + self._controller.getPreviewData(function(projectData) { + self._progressContainer.hide(); + + new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); + }); + } + }); }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/fixed-width-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/fixed-width-parser-ui.js index 3e181c903..750333b21 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/fixed-width-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/fixed-width-parser-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,44 +29,44 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.FixedWidthParserUI = function(controller, jobID, job, format, config, dataContainerElmt, progressContainerElmt, optionContainerElmt) { - - this._controller = controller; - this._jobID = jobID; - this._job = job; - this._format = format; - this._config = config; - - this._dataContainer = dataContainerElmt; - this._progressContainer = progressContainerElmt; - this._optionContainer = optionContainerElmt; - - this._timerID = null; - this._initialize(); - this.updatePreview(); + + this._controller = controller; + this._jobID = jobID; + this._job = job; + this._format = format; + this._config = config; + + this._dataContainer = dataContainerElmt; + this._progressContainer = progressContainerElmt; + this._optionContainer = optionContainerElmt; + + this._timerID = null; + this._initialize(); + this.updatePreview(); }; Refine.DefaultImportingController.parserUIs["FixedWidthParserUI"] = Refine.FixedWidthParserUI; Refine.FixedWidthParserUI.encodeSeparator = function(s) { - return s.replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("\t", "\\t"); + return s.replace("\\", "\\\\") + .replace("\n", "\\n") + .replace("\t", "\\t"); }; Refine.FixedWidthParserUI.decodeSeparator = function(s) { - return s.replace("\\n", "\n") - .replace("\\t", "\t") - .replace("\\\\", "\\"); + return s.replace("\\n", "\n") + .replace("\\t", "\t") + .replace("\\\\", "\\"); }; Refine.FixedWidthParserUI.prototype.dispose = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } }; Refine.FixedWidthParserUI.prototype.confirmReadyToCreateProject = function() { @@ -74,398 +74,398 @@ Refine.FixedWidthParserUI.prototype.confirmReadyToCreateProject = function() { }; Refine.FixedWidthParserUI.prototype.getOptions = function() { - var options = { - columnWidths: [].concat(this._config.columnWidths) - }; - - var columnNames = $.trim(this._optionContainerElmts.columnNamesInput[0].value).replace(/,\s+/g, ',').split(','); - if (columnNames.length > 0 && columnNames[0].length > 0) { - options.columnNames = columnNames; + var options = { + columnWidths: [].concat(this._config.columnWidths) + }; + + var columnNames = $.trim(this._optionContainerElmts.columnNamesInput[0].value).replace(/,\s+/g, ',').split(','); + if (columnNames.length > 0 && columnNames[0].length > 0) { + options.columnNames = columnNames; + } + + switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) { + case 'new-line': + options.lineSeparator = "\n"; + break; + default: + options.lineSeparator = Refine.FixedWidthParserUI.decodeSeparator( + this._optionContainerElmts.rowSeparatorInput[0].value); + } + + var parseIntDefault = function(s, def) { + try { + var n = parseInt(s); + if (!isNaN(n)) { + return n; + } + } catch (e) { + // Ignore } - - switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) { - case 'new-line': - options.lineSeparator = "\n"; - break; - default: - options.lineSeparator = Refine.FixedWidthParserUI.decodeSeparator( - this._optionContainerElmts.rowSeparatorInput[0].value); - } - - var parseIntDefault = function(s, def) { - try { - var n = parseInt(s); - if (!isNaN(n)) { - return n; - } - } catch (e) { - // Ignore - } - return def; - }; - if (this._optionContainerElmts.ignoreCheckbox[0].checked) { - options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); - } else { - options.ignoreLines = -1; - } - if (this._optionContainerElmts.headerLinesCheckbox[0].checked) { - options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0); - } else { - options.headerLines = 0; - } - if (this._optionContainerElmts.skipCheckbox[0].checked) { - options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0); - } else { - options.skipDataLines = 0; - } - if (this._optionContainerElmts.limitCheckbox[0].checked) { - options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); - } else { - options.limit = -1; - } - - options.guessCellValueTypes = this._optionContainerElmts.guessCellValueTypesCheckbox[0].checked; - - options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; - options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; - options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; - - return options; + return def; + }; + if (this._optionContainerElmts.ignoreCheckbox[0].checked) { + options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); + } else { + options.ignoreLines = -1; + } + if (this._optionContainerElmts.headerLinesCheckbox[0].checked) { + options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0); + } else { + options.headerLines = 0; + } + if (this._optionContainerElmts.skipCheckbox[0].checked) { + options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0); + } else { + options.skipDataLines = 0; + } + if (this._optionContainerElmts.limitCheckbox[0].checked) { + options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); + } else { + options.limit = -1; + } + + options.guessCellValueTypes = this._optionContainerElmts.guessCellValueTypesCheckbox[0].checked; + + options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; + options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; + options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; + + return options; }; Refine.FixedWidthParserUI.prototype._initialize = function() { - var self = this; - - this._optionContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/fixed-width-parser-ui.html")); - this._optionContainerElmts = DOM.bind(this._optionContainer); - this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); - - this._optionContainerElmts.columnWidthsInput[0].value = this._config.columnWidths.join(','); - if ('columnNames' in this._config) { - this._optionContainerElmts.columnNamesInput[0].value = this._config.columnNames.join(','); + var self = this; + + this._optionContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/fixed-width-parser-ui.html")); + this._optionContainerElmts = DOM.bind(this._optionContainer); + this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); + + this._optionContainerElmts.columnWidthsInput[0].value = this._config.columnWidths.join(','); + if ('columnNames' in this._config) { + this._optionContainerElmts.columnNamesInput[0].value = this._config.columnNames.join(','); + } + + var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom'; + this._optionContainer.find( + "input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked"); + this._optionContainerElmts.rowSeparatorInput[0].value = + Refine.FixedWidthParserUI.encodeSeparator(this._config.lineSeparator); + + if (this._config.ignoreLines > 0) { + this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); + this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); + } + if (this._config.headerLines > 0) { + this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked"); + this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString(); + } + if (this._config.limit > 0) { + this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); + this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); + } + if (this._config.skipDataLines > 0) { + this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); + this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); + } + if (this._config.storeBlankRows) { + this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); + } + + if (this._config.guessCellValueTypes) { + this._optionContainerElmts.guessCellValueTypesCheckbox.attr("checked", "checked"); + } + + if (this._config.storeBlankCellsAsNulls) { + this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); + } + if (this._config.includeFileSources) { + this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); + } + + var onChange = function() { + self._scheduleUpdatePreview(); + }; + this._optionContainer.find("input").bind("change", onChange); + this._optionContainer.find("select").bind("change", onChange); + + this._optionContainerElmts.columnWidthsInput.bind("change", function() { + var newColumnWidths = []; + var a = $.trim(this.value).replace(/,\s+/g, ',').split(','); + for (var i = 0; i < a.length; i++) { + var n = parseInt(a[i]); + if (isNaN(n)) { + return; + } + newColumnWidths.push(n); } - - var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom'; - this._optionContainer.find( - "input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked"); - this._optionContainerElmts.rowSeparatorInput[0].value = - Refine.FixedWidthParserUI.encodeSeparator(this._config.lineSeparator); - - if (this._config.ignoreLines > 0) { - this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); - this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); - } - if (this._config.headerLines > 0) { - this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked"); - this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString(); - } - if (this._config.limit > 0) { - this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); - this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); - } - if (this._config.skipDataLines > 0) { - this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); - this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); - } - if (this._config.storeBlankRows) { - this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); - } - - if (this._config.guessCellValueTypes) { - this._optionContainerElmts.guessCellValueTypesCheckbox.attr("checked", "checked"); - } - - if (this._config.storeBlankCellsAsNulls) { - this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); - } - if (this._config.includeFileSources) { - this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); - } - - var onChange = function() { - self._scheduleUpdatePreview(); - }; - this._optionContainer.find("input").bind("change", onChange); - this._optionContainer.find("select").bind("change", onChange); - - this._optionContainerElmts.columnWidthsInput.bind("change", function() { - var newColumnWidths = []; - var a = $.trim(this.value).replace(/,\s+/g, ',').split(','); - for (var i = 0; i < a.length; i++) { - var n = parseInt(a[i]); - if (isNaN(n)) { - return; - } - newColumnWidths.push(n); - } - self._config.columnWidths = newColumnWidths; - onChange(); - }); - this._optionContainerElmts.columnNamesInput.bind("change", onChange); - + self._config.columnWidths = newColumnWidths; + onChange(); + }); + this._optionContainerElmts.columnNamesInput.bind("change", onChange); + }; Refine.FixedWidthParserUI.prototype._scheduleUpdatePreview = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } - - var self = this; - this._timerID = window.setTimeout(function() { - self._timerID = null; - self.updatePreview(); - }, 500); // 0.5 second + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } + + var self = this; + this._timerID = window.setTimeout(function() { + self._timerID = null; + self.updatePreview(); + }, 500); // 0.5 second }; Refine.FixedWidthParserUI.prototype.updatePreview = function() { - var self = this; - - this._progressContainer.show(); - - var options = this.getOptions(); - // for preview, we need exact text, so it's easier to show where the columns are split - options.guessCellValueTypes = false; - - this._controller.updateFormatAndOptions(options, function(result) { - if (result.status == "ok") { - self._controller.getPreviewData(function(projectData) { - new Refine.FixedWidthPreviewTable( - self, - self._config, - projectData, - self._dataContainer - ); - self._progressContainer.hide(); - }, 20); - } - }); + var self = this; + + this._progressContainer.show(); + + var options = this.getOptions(); + // for preview, we need exact text, so it's easier to show where the columns are split + options.guessCellValueTypes = false; + + this._controller.updateFormatAndOptions(options, function(result) { + if (result.status == "ok") { + self._controller.getPreviewData(function(projectData) { + new Refine.FixedWidthPreviewTable( + self, + self._config, + projectData, + self._dataContainer + ); + self._progressContainer.hide(); + }, 20); + } + }); }; Refine.FixedWidthPreviewTable = function(parserUI, config, projectData, elmt) { - this._parserUI = parserUI; - this._config = config; - this._projectData = projectData; - this._elmt = elmt; - this._render(); + this._parserUI = parserUI; + this._config = config; + this._projectData = projectData; + this._elmt = elmt; + this._render(); }; Refine.FixedWidthPreviewTable.prototype._render = function() { - var scrollTop = this._elmt[0].scrollTop; - var scrollLeft = this._elmt[0].scrollLeft; - - this._elmt.unbind().empty(); - - var self = this; - var container = $('
') - .addClass('fixed-width-preview-container') - .appendTo(this._elmt); - var table = $('') - .addClass("data-table") - .addClass("fixed-width-preview-data-table") - .appendTo(container)[0]; - - var columns = this._projectData.columnModel.columns; - var columnWidths = [].concat(this._config.columnWidths); - - var addCell = function(tr) { - var index = tr.cells.length; - var td = tr.insertCell(index); - td.className = (index % 2 == 0) ? 'even' : 'odd'; - return td; - }; - - /*------------------------------------------------------------ - * Column Headers - *------------------------------------------------------------ - */ + var scrollTop = this._elmt[0].scrollTop; + var scrollLeft = this._elmt[0].scrollLeft; - var trHead = table.insertRow(table.rows.length); - $(addCell(trHead)).addClass("column-header").html(' '); // index - - var createColumnHeader = function(column, index) { - var name = column.name; - if (index < columnWidths.length) { - name = name.slice(0, columnWidths[index]); - } - $(addCell(trHead)) - .addClass("column-header") - .text(name) - .attr('title', column.name); - }; + this._elmt.unbind().empty(); + + var self = this; + var container = $('
') + .addClass('fixed-width-preview-container') + .appendTo(this._elmt); + var table = $('
') + .addClass("data-table") + .addClass("fixed-width-preview-data-table") + .appendTo(container)[0]; + + var columns = this._projectData.columnModel.columns; + var columnWidths = [].concat(this._config.columnWidths); + + var addCell = function(tr) { + var index = tr.cells.length; + var td = tr.insertCell(index); + td.className = (index % 2 == 0) ? 'even' : 'odd'; + return td; + }; + + /*------------------------------------------------------------ + * Column Headers + *------------------------------------------------------------ + */ + + var trHead = table.insertRow(table.rows.length); + $(addCell(trHead)).addClass("column-header").html(' '); // index + + var createColumnHeader = function(column, index) { + var name = column.name; + if (index < columnWidths.length) { + name = name.slice(0, columnWidths[index]); + } + $(addCell(trHead)) + .addClass("column-header") + .text(name) + .attr('title', column.name); + }; + for (var i = 0; i < columns.length; i++) { + createColumnHeader(columns[i], i); + } + + /*------------------------------------------------------------ + * Data Cells + *------------------------------------------------------------ + */ + + var rows = this._projectData.rowModel.rows; + var renderRow = function(tr, r, row) { + var tdIndex = addCell(tr); + $('
').html((row.i + 1) + ".").appendTo(tdIndex); + + var cells = row.cells; for (var i = 0; i < columns.length; i++) { - createColumnHeader(columns[i], i); - } - - /*------------------------------------------------------------ - * Data Cells - *------------------------------------------------------------ - */ - - var rows = this._projectData.rowModel.rows; - var renderRow = function(tr, r, row) { - var tdIndex = addCell(tr); - $('
').html((row.i + 1) + ".").appendTo(tdIndex); - - var cells = row.cells; - for (var i = 0; i < columns.length; i++) { - var column = columns[i]; - var td = addCell(tr); - var divContent = $('
').addClass("data-table-cell-content").appendTo(td); - - var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; - if (!cell || ("v" in cell && cell.v === null)) { - $('').html(" ").appendTo(divContent); - } else if ("e" in cell) { - $('').addClass("data-table-error").text(cell.e).appendTo(divContent); - } else if (!("r" in cell) || !cell.r) { - if (typeof cell.v !== "string") { - if (typeof cell.v == "number") { - divContent.addClass("data-table-cell-content-numeric"); - } - $('') - .addClass("data-table-value-nonstring") - .text(cell.v) - .appendTo(divContent); - } else if (URL.looksLikeUrl(cell.v)) { - $('') - .text(cell.v) - .attr("href", cell.v) - .attr("target", "_blank") - .appendTo(divContent); - } else { - $('').text(cell.v).appendTo(divContent); - } - } + var column = columns[i]; + var td = addCell(tr); + var divContent = $('
').addClass("data-table-cell-content").appendTo(td); + + var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; + if (!cell || ("v" in cell && cell.v === null)) { + $('').html(" ").appendTo(divContent); + } else if ("e" in cell) { + $('').addClass("data-table-error").text(cell.e).appendTo(divContent); + } else if (!("r" in cell) || !cell.r) { + if (typeof cell.v !== "string") { + if (typeof cell.v == "number") { + divContent.addClass("data-table-cell-content-numeric"); + } + $('') + .addClass("data-table-value-nonstring") + .text(cell.v) + .appendTo(divContent); + } else if (URL.looksLikeUrl(cell.v)) { + $('') + .text(cell.v) + .attr("href", cell.v) + .attr("target", "_blank") + .appendTo(divContent); + } else { + $('').text(cell.v).appendTo(divContent); } - }; - - for (var r = 0; r < rows.length; r++) { - var row = rows[r]; - renderRow(table.insertRow(table.rows.length), r, row); + } } - - var pixelOffset = $(trHead.cells[1]).position().left; - var testString = '01234567890123456789012345678901234567890123456789'; - var testDiv = $('
') - .css('position', 'absolute') - .css('top', '-100px') - .text(testString) - .appendTo(container); - var pixelsPerChar = testDiv.width() / testString.length; - testDiv.remove(); - - var columnSeparators = []; - var columnCharIndexes = []; - var positionColumnSeparator = function(outer, charIndex) { - outer.css('left', - Math.round(pixelOffset + charIndex * pixelsPerChar - DOM.getHPaddings(outer) / 2) + 'px'); - }; - var computeCharIndex = function(evt) { - var offset = evt.pageX - container.offset().left; - return Math.round((offset - pixelOffset) / pixelsPerChar); - }; - var updatePreview = function() { - columnCharIndexes.sort(function(a, b) { return a - b; }); - - var newColumnWidths = []; - for (var i = 0; i < columnCharIndexes.length; i++) { - var charIndex = columnCharIndexes[i]; - var columnWidth = (i == 0) ? charIndex : (charIndex - columnCharIndexes[i - 1]); - if (columnWidth > 0) { - newColumnWidths.push(columnWidth); - } - } - - self._config.columnWidths = newColumnWidths; - self._parserUI._optionContainerElmts.columnWidthsInput[0].value = newColumnWidths.join(','); - self._parserUI.updatePreview(); - }; - - var newSeparator = $('
') - .addClass('fixed-width-preview-column-separator-outer') - .append($('
').addClass('fixed-width-preview-column-separator-inner')) - .appendTo(container); - - var createColumnSeparator = function(charIndex, index) { - columnCharIndexes[index] = charIndex; - - var outer = $('
') - .addClass('fixed-width-preview-column-separator-outer') - .appendTo(container); - var inner = $('
') - .addClass('fixed-width-preview-column-separator-inner') - .appendTo(outer); - var close = $('
').appendTo(inner); - - positionColumnSeparator(outer, charIndex); - - outer.mouseover(function() { - newSeparator.hide(); - }) - .mouseout(function() { - newSeparator.show(); - }) - .mousedown(function() { - var mouseMove = function(evt) { - var newCharIndex = computeCharIndex(evt); - positionColumnSeparator(outer, newCharIndex); - - evt.preventDefault(); - evt.stopPropagation(); - return false; - }; - var mouseUp = function(evt) { - container.unbind('mousemove', mouseMove); - container.unbind('mouseup', mouseUp); - - var newCharIndex = computeCharIndex(evt); - positionColumnSeparator(outer, newCharIndex); - - columnCharIndexes[index] = newCharIndex; - updatePreview(); - - evt.preventDefault(); - evt.stopPropagation(); - return false; - }; - container.bind('mousemove', mouseMove); - container.bind('mouseup', mouseUp); - }); - - close.click(function() { - columnCharIndexes[index] = index > 0 ? columnCharIndexes[index - 1] : 0; - updatePreview(); - }); - }; - - var charOffset = 0; - for (var i = 0; i < columnWidths.length; i++) { - var columnWidth = columnWidths[i]; - createColumnSeparator(charOffset + columnWidth, i); - charOffset += columnWidth; + }; + + for (var r = 0; r < rows.length; r++) { + var row = rows[r]; + renderRow(table.insertRow(table.rows.length), r, row); + } + + var pixelOffset = $(trHead.cells[1]).position().left; + var testString = '01234567890123456789012345678901234567890123456789'; + var testDiv = $('
') + .css('position', 'absolute') + .css('top', '-100px') + .text(testString) + .appendTo(container); + var pixelsPerChar = testDiv.width() / testString.length; + testDiv.remove(); + + var columnSeparators = []; + var columnCharIndexes = []; + var positionColumnSeparator = function(outer, charIndex) { + outer.css('left', + Math.round(pixelOffset + charIndex * pixelsPerChar - DOM.getHPaddings(outer) / 2) + 'px'); + }; + var computeCharIndex = function(evt) { + var offset = evt.pageX - container.offset().left; + return Math.round((offset - pixelOffset) / pixelsPerChar); + }; + var updatePreview = function() { + columnCharIndexes.sort(function(a, b) { return a - b; }); + + var newColumnWidths = []; + for (var i = 0; i < columnCharIndexes.length; i++) { + var charIndex = columnCharIndexes[i]; + var columnWidth = (i == 0) ? charIndex : (charIndex - columnCharIndexes[i - 1]); + if (columnWidth > 0) { + newColumnWidths.push(columnWidth); + } } - - container - .mouseout(function(evt) { - newSeparator.hide(); - }) - .mousemove(function(evt) { - var offset = evt.pageX - container.offset().left; - var newCharIndex = Math.round((offset - pixelOffset) / pixelsPerChar); - positionColumnSeparator(newSeparator.show(), newCharIndex); - }); - newSeparator.mousedown(function(evt) { + + self._config.columnWidths = newColumnWidths; + self._parserUI._optionContainerElmts.columnWidthsInput[0].value = newColumnWidths.join(','); + self._parserUI.updatePreview(); + }; + + var newSeparator = $('
') + .addClass('fixed-width-preview-column-separator-outer') + .append($('
').addClass('fixed-width-preview-column-separator-inner')) + .appendTo(container); + + var createColumnSeparator = function(charIndex, index) { + columnCharIndexes[index] = charIndex; + + var outer = $('
') + .addClass('fixed-width-preview-column-separator-outer') + .appendTo(container); + var inner = $('
') + .addClass('fixed-width-preview-column-separator-inner') + .appendTo(outer); + var close = $('
').appendTo(inner); + + positionColumnSeparator(outer, charIndex); + + outer.mouseover(function() { + newSeparator.hide(); + }) + .mouseout(function() { + newSeparator.show(); + }) + .mousedown(function() { + var mouseMove = function(evt) { var newCharIndex = computeCharIndex(evt); - columnCharIndexes.push(newCharIndex); - updatePreview(); - + positionColumnSeparator(outer, newCharIndex); + evt.preventDefault(); evt.stopPropagation(); return false; + }; + var mouseUp = function(evt) { + container.unbind('mousemove', mouseMove); + container.unbind('mouseup', mouseUp); + + var newCharIndex = computeCharIndex(evt); + positionColumnSeparator(outer, newCharIndex); + + columnCharIndexes[index] = newCharIndex; + updatePreview(); + + evt.preventDefault(); + evt.stopPropagation(); + return false; + }; + container.bind('mousemove', mouseMove); + container.bind('mouseup', mouseUp); }); - - this._elmt[0].scrollTop = scrollTop; - this._elmt[0].scrollLeft = scrollLeft; + + close.click(function() { + columnCharIndexes[index] = index > 0 ? columnCharIndexes[index - 1] : 0; + updatePreview(); + }); + }; + + var charOffset = 0; + for (var i = 0; i < columnWidths.length; i++) { + var columnWidth = columnWidths[i]; + createColumnSeparator(charOffset + columnWidth, i); + charOffset += columnWidth; + } + + container + .mouseout(function(evt) { + newSeparator.hide(); + }) + .mousemove(function(evt) { + var offset = evt.pageX - container.offset().left; + var newCharIndex = Math.round((offset - pixelOffset) / pixelsPerChar); + positionColumnSeparator(newSeparator.show(), newCharIndex); + }); + newSeparator.mousedown(function(evt) { + var newCharIndex = computeCharIndex(evt); + columnCharIndexes.push(newCharIndex); + updatePreview(); + + evt.preventDefault(); + evt.stopPropagation(); + return false; + }); + + this._elmt[0].scrollTop = scrollTop; + this._elmt[0].scrollLeft = scrollLeft; }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/json-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/json-parser-ui.js index f4f5f1d5d..9e1efb164 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/json-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/json-parser-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,213 +29,213 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.JsonParserUI = function(controller, jobID, job, format, config, dataContainerElmt, progressContainerElmt, optionContainerElmt) { - - this._controller = controller; - this._jobID = jobID; - this._job = job; - this._format = format; - this._config = config; - - this._dataContainer = dataContainerElmt; - this._progressContainer = progressContainerElmt; - this._optionContainer = optionContainerElmt; - - this._timerID = null; - this._initialize(); - this._showPickRecordNodesUI(); + + this._controller = controller; + this._jobID = jobID; + this._job = job; + this._format = format; + this._config = config; + + this._dataContainer = dataContainerElmt; + this._progressContainer = progressContainerElmt; + this._optionContainer = optionContainerElmt; + + this._timerID = null; + this._initialize(); + this._showPickRecordNodesUI(); }; Refine.DefaultImportingController.parserUIs["JsonParserUI"] = Refine.JsonParserUI; Refine.JsonParserUI.prototype.dispose = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } }; Refine.JsonParserUI.prototype.confirmReadyToCreateProject = function() { if ((this._config.recordPath) && this._config.recordPath.length > 0) { - return true; + return true; } else { - window.alert('Please specify a record path first.'); + window.alert('Please specify a record path first.'); } }; Refine.JsonParserUI.prototype.getOptions = function() { - var options = { - recordPath: this._config.recordPath - }; - - if (this._optionContainerElmts.limitCheckbox[0].checked) { - options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); - } else { - options.limit = -1; - } - options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; - - return options; + var options = { + recordPath: this._config.recordPath + }; + + if (this._optionContainerElmts.limitCheckbox[0].checked) { + options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); + } else { + options.limit = -1; + } + options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; + + return options; }; Refine.JsonParserUI.prototype._initialize = function() { - var self = this; - - this._optionContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/json-parser-ui.html")); - this._optionContainerElmts = DOM.bind(this._optionContainer); - this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); - - if (this._config.limit > 0) { - this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); - this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); - } - if (this._config.includeFileSources) { - this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); - } - this._optionContainerElmts.pickRecordElementsButton.click(function() { - self._showPickRecordNodesUI(); - }); - - var onChange = function() { - self._scheduleUpdatePreview(); - }; - this._optionContainer.find("input").bind("change", onChange); - this._optionContainer.find("select").bind("change", onChange); + var self = this; + + this._optionContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/json-parser-ui.html")); + this._optionContainerElmts = DOM.bind(this._optionContainer); + this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); + + if (this._config.limit > 0) { + this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); + this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); + } + if (this._config.includeFileSources) { + this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); + } + this._optionContainerElmts.pickRecordElementsButton.click(function() { + self._showPickRecordNodesUI(); + }); + + var onChange = function() { + self._scheduleUpdatePreview(); + }; + this._optionContainer.find("input").bind("change", onChange); + this._optionContainer.find("select").bind("change", onChange); }; Refine.JsonParserUI.prototype._showPickRecordNodesUI = function() { - var self = this; - - this._dataContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/json-parser-select-ui.html")); - - var elmts = DOM.bind(this._dataContainer); - - var escapeElmt = $(''); - var escapeHtml = function(s) { - escapeElmt.empty().text(s); - return escapeElmt.html(); - }; - var textAsHtml = function(s) { - s = s.length <= 200 ? s : (s.substring(0, 200) + ' ...'); - return '' + escapeHtml(s) + ''; - }; - var hittest = function(evt, elmt) { - var a = $(evt.target).closest('.node'); - return a.length > 0 && a[0] == elmt[0]; - }; - var registerEvents = function(elmt, path) { - elmt.bind('mouseover', function(evt) { - if (hittest(evt, elmt)) { - elmts.domContainer.find('.highlight').removeClass('highlight'); - elmt.addClass('highlight'); - } - }) - .bind('mouseout', function(evt) { - elmt.removeClass('highlight'); - }) - .click(function(evt) { - if (hittest(evt, elmt)) { - self._setRecordPath(path); - } - }); - }; - var renderArray = function(a, container, parentPath) { - $('').addClass('punctuation').text('[').appendTo(container); - - var parentPath2 = [].concat(parentPath); - parentPath2.push('__anonymous__'); - - var elementNode = null; - for (var i = 0; i < a.length; i++) { - if (elementNode != null) { - $('').addClass('punctuation').text(',').appendTo(elementNode); - } - elementNode = $('
').addClass('node').addClass('indented').appendTo(container); - - renderNode(a[i], elementNode, parentPath2); - } - - $('').addClass('punctuation').text(']').appendTo(container); - }; - var renderObject = function(o, container, parentPath) { - $('').addClass('punctuation').text('{').appendTo(container); - - var elementNode = null; - for (var key in o) { - if (o.hasOwnProperty(key)) { - if (elementNode != null) { - $('').addClass('punctuation').text(',').appendTo(elementNode); - } - elementNode = $('
').addClass('node').addClass('indented').appendTo(container); - - $('').text(key).addClass('field-name').appendTo(elementNode); - $('').text(': ').addClass('punctuation').appendTo(elementNode); - - var parentPath2 = [].concat(parentPath); - parentPath2.push(key); + var self = this; - renderNode(o[key], elementNode, parentPath2); - } + this._dataContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/json-parser-select-ui.html")); + + var elmts = DOM.bind(this._dataContainer); + + var escapeElmt = $(''); + var escapeHtml = function(s) { + escapeElmt.empty().text(s); + return escapeElmt.html(); + }; + var textAsHtml = function(s) { + s = s.length <= 200 ? s : (s.substring(0, 200) + ' ...'); + return '' + escapeHtml(s) + ''; + }; + var hittest = function(evt, elmt) { + var a = $(evt.target).closest('.node'); + return a.length > 0 && a[0] == elmt[0]; + }; + var registerEvents = function(elmt, path) { + elmt.bind('mouseover', function(evt) { + if (hittest(evt, elmt)) { + elmts.domContainer.find('.highlight').removeClass('highlight'); + elmt.addClass('highlight'); + } + }) + .bind('mouseout', function(evt) { + elmt.removeClass('highlight'); + }) + .click(function(evt) { + if (hittest(evt, elmt)) { + self._setRecordPath(path); + } + }); + }; + var renderArray = function(a, container, parentPath) { + $('').addClass('punctuation').text('[').appendTo(container); + + var parentPath2 = [].concat(parentPath); + parentPath2.push('__anonymous__'); + + var elementNode = null; + for (var i = 0; i < a.length; i++) { + if (elementNode != null) { + $('').addClass('punctuation').text(',').appendTo(elementNode); + } + elementNode = $('
').addClass('node').addClass('indented').appendTo(container); + + renderNode(a[i], elementNode, parentPath2); + } + + $('').addClass('punctuation').text(']').appendTo(container); + }; + var renderObject = function(o, container, parentPath) { + $('').addClass('punctuation').text('{').appendTo(container); + + var elementNode = null; + for (var key in o) { + if (o.hasOwnProperty(key)) { + if (elementNode != null) { + $('').addClass('punctuation').text(',').appendTo(elementNode); } - $('').addClass('punctuation').text('}').appendTo(container); - + elementNode = $('
').addClass('node').addClass('indented').appendTo(container); + + $('').text(key).addClass('field-name').appendTo(elementNode); + $('').text(': ').addClass('punctuation').appendTo(elementNode); + + var parentPath2 = [].concat(parentPath); + parentPath2.push(key); + + renderNode(o[key], elementNode, parentPath2); + } + } + $('').addClass('punctuation').text('}').appendTo(container); + + registerEvents(container, parentPath); + }; + var renderNode = function(node, container, parentPath) { + if (node == null) { + $('').addClass('literal').text('null').appendTo(container); + } else { + if ($.isPlainObject(node)) { + renderObject(node, container, parentPath); + } else if ($.isArray(node)) { + renderArray(node, container, parentPath); + } else { + $('').addClass('literal').text(node.toString()).appendTo(container); registerEvents(container, parentPath); - }; - var renderNode = function(node, container, parentPath) { - if (node == null) { - $('').addClass('literal').text('null').appendTo(container); - } else { - if ($.isPlainObject(node)) { - renderObject(node, container, parentPath); - } else if ($.isArray(node)) { - renderArray(node, container, parentPath); - } else { - $('').addClass('literal').text(node.toString()).appendTo(container); - registerEvents(container, parentPath); - } - } - }; - renderNode(this._config.dom, elmts.domContainer, [ '__anonymous__' ]); + } + } + }; + renderNode(this._config.dom, elmts.domContainer, [ '__anonymous__' ]); }; Refine.JsonParserUI.prototype._scheduleUpdatePreview = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } - - var self = this; - this._timerID = window.setTimeout(function() { - self._timerID = null; - self._updatePreview(); - }, 500); // 0.5 second + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } + + var self = this; + this._timerID = window.setTimeout(function() { + self._timerID = null; + self._updatePreview(); + }, 500); // 0.5 second }; Refine.JsonParserUI.prototype._setRecordPath = function(path) { - this._config.recordPath = path; - this._updatePreview(); + this._config.recordPath = path; + this._updatePreview(); }; Refine.JsonParserUI.prototype._updatePreview = function() { - var self = this; - - this._progressContainer.show(); - - var options = this.getOptions(); - // for preview, we need exact text, so it's easier to show where the columns are split - options.guessCellValueTypes = false; - - this._controller.updateFormatAndOptions(options, function(result) { - if (result.status == "ok") { - self._controller.getPreviewData(function(projectData) { - self._progressContainer.hide(); - - new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); - }, 100); - } - }); + var self = this; + + this._progressContainer.show(); + + var options = this.getOptions(); + // for preview, we need exact text, so it's easier to show where the columns are split + options.guessCellValueTypes = false; + + this._controller.updateFormatAndOptions(options, function(result) { + if (result.status == "ok") { + self._controller.getPreviewData(function(projectData) { + self._progressContainer.hide(); + + new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); + }, 100); + } + }); }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/line-based-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/line-based-parser-ui.js index e9df9b111..ee3e8a8ae 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/line-based-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/line-based-parser-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,24 +29,24 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.LineBasedParserUI = function(controller, jobID, job, format, config, - dataContainerElmt, progressContainerElmt, optionContainerElmt) { + dataContainerElmt, progressContainerElmt, optionContainerElmt) { - this._controller = controller; - this._jobID = jobID; - this._job = job; - this._format = format; - this._config = config; + this._controller = controller; + this._jobID = jobID; + this._job = job; + this._format = format; + this._config = config; - this._dataContainer = dataContainerElmt; - this._progressContainer = progressContainerElmt; - this._optionContainer = optionContainerElmt; + this._dataContainer = dataContainerElmt; + this._progressContainer = progressContainerElmt; + this._optionContainer = optionContainerElmt; - this._timerID = null; - this._initialize(); - this._updatePreview(); + this._timerID = null; + this._initialize(); + this._updatePreview(); }; Refine.DefaultImportingController.parserUIs["LineBasedParserUI"] = Refine.LineBasedParserUI; @@ -55,132 +55,132 @@ Refine.LineBasedParserUI.prototype.confirmReadyToCreateProject = function() { }; Refine.LineBasedParserUI.prototype.dispose = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } }; Refine.LineBasedParserUI.prototype.getOptions = function() { - var options = { - recordPath: this._config.recordPath - }; - - var parseIntDefault = function(s, def) { - try { - var n = parseInt(s); - if (!isNaN(n)) { - return n; - } - } catch (e) { - // Ignore - } - return def; - }; - options.linesPerRow = parseIntDefault(this._optionContainerElmts.linesPerRowInput[0].value, 1); - - switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) { - case 'new-line': - options.lineSeparator = "\n"; - break; - default: - options.lineSeparator = Refine.FixedWidthParserUI.decodeSeparator( - this._optionContainerElmts.rowSeparatorInput[0].value); + var options = { + recordPath: this._config.recordPath + }; + + var parseIntDefault = function(s, def) { + try { + var n = parseInt(s); + if (!isNaN(n)) { + return n; + } + } catch (e) { + // Ignore } - - if (this._optionContainerElmts.ignoreCheckbox[0].checked) { - options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); - } else { - options.ignoreLines = -1; - } - if (this._optionContainerElmts.limitCheckbox[0].checked) { - options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); - } else { - options.limit = -1; - } - if (this._optionContainerElmts.skipCheckbox[0].checked) { - options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, -1); - } else { - options.skipDataLines = -1; - } - options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; - options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; - options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; - - return options; + return def; + }; + options.linesPerRow = parseIntDefault(this._optionContainerElmts.linesPerRowInput[0].value, 1); + + switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) { + case 'new-line': + options.lineSeparator = "\n"; + break; + default: + options.lineSeparator = Refine.FixedWidthParserUI.decodeSeparator( + this._optionContainerElmts.rowSeparatorInput[0].value); + } + + if (this._optionContainerElmts.ignoreCheckbox[0].checked) { + options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); + } else { + options.ignoreLines = -1; + } + if (this._optionContainerElmts.limitCheckbox[0].checked) { + options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); + } else { + options.limit = -1; + } + if (this._optionContainerElmts.skipCheckbox[0].checked) { + options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, -1); + } else { + options.skipDataLines = -1; + } + options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; + options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; + options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; + + return options; }; Refine.LineBasedParserUI.prototype._initialize = function() { - var self = this; - - this._optionContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/line-based-parser-ui.html")); - this._optionContainerElmts = DOM.bind(this._optionContainer); - this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); - - this._optionContainerElmts.linesPerRowInput[0].value = - this._config.linesPerRow.toString(); - - var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom'; - this._optionContainer.find( - "input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked"); - this._optionContainerElmts.rowSeparatorInput[0].value = - Refine.SeparatorBasedParserUI.encodeSeparator(this._config.lineSeparator); + var self = this; - if (this._config.ignoreLines > 0) { - this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); - this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); - } - if (this._config.limit > 0) { - this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); - this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); - } - if (this._config.skipDataLines > 0) { - this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); - this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); - } - if (this._config.storeBlankRows) { - this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); - } - if (this._config.storeBlankCellsAsNulls) { - this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); - } - if (this._config.includeFileSources) { - this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); - } - - var onChange = function() { - self._scheduleUpdatePreview(); - }; - this._optionContainer.find("input").bind("change", onChange); - this._optionContainer.find("select").bind("change", onChange); + this._optionContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/line-based-parser-ui.html")); + this._optionContainerElmts = DOM.bind(this._optionContainer); + this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); + + this._optionContainerElmts.linesPerRowInput[0].value = + this._config.linesPerRow.toString(); + + var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom'; + this._optionContainer.find( + "input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked"); + this._optionContainerElmts.rowSeparatorInput[0].value = + Refine.SeparatorBasedParserUI.encodeSeparator(this._config.lineSeparator); + + if (this._config.ignoreLines > 0) { + this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); + this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); + } + if (this._config.limit > 0) { + this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); + this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); + } + if (this._config.skipDataLines > 0) { + this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); + this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); + } + if (this._config.storeBlankRows) { + this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); + } + if (this._config.storeBlankCellsAsNulls) { + this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); + } + if (this._config.includeFileSources) { + this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); + } + + var onChange = function() { + self._scheduleUpdatePreview(); + }; + this._optionContainer.find("input").bind("change", onChange); + this._optionContainer.find("select").bind("change", onChange); }; Refine.LineBasedParserUI.prototype._scheduleUpdatePreview = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } - - var self = this; - this._timerID = window.setTimeout(function() { - self._timerID = null; - self._updatePreview(); - }, 500); // 0.5 second + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } + + var self = this; + this._timerID = window.setTimeout(function() { + self._timerID = null; + self._updatePreview(); + }, 500); // 0.5 second }; Refine.LineBasedParserUI.prototype._updatePreview = function() { - var self = this; - - this._progressContainer.show(); - - this._controller.updateFormatAndOptions(this.getOptions(), function(result) { - if (result.status == "ok") { - self._controller.getPreviewData(function(projectData) { - self._progressContainer.hide(); - - new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); - }); - } - }); + var self = this; + + this._progressContainer.show(); + + this._controller.updateFormatAndOptions(this.getOptions(), function(result) { + if (result.status == "ok") { + self._controller.getPreviewData(function(projectData) { + self._progressContainer.hide(); + + new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); + }); + } + }); }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/preview-table.js b/main/webapp/modules/core/scripts/index/parser-interfaces/preview-table.js index 86556b507..95fb85da7 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/preview-table.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/preview-table.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,87 +29,87 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.PreviewTable = function(projectData, elmt) { - this._projectData = projectData; - this._elmt = elmt; - this._render(); + this._projectData = projectData; + this._elmt = elmt; + this._render(); }; Refine.PreviewTable.prototype._render = function() { - var self = this; - var table = $('
').addClass("data-table").appendTo(this._elmt)[0]; - - var columns = this._projectData.columnModel.columns; - - /*------------------------------------------------------------ - * Column Headers - *------------------------------------------------------------ - */ + var self = this; + var table = $('
').addClass("data-table").appendTo(this._elmt)[0]; + + var columns = this._projectData.columnModel.columns; + + /*------------------------------------------------------------ + * Column Headers + *------------------------------------------------------------ + */ + + var trHead = table.insertRow(table.rows.length); + $(trHead.insertCell(0)).addClass("column-header").html(' '); // index + + var createColumnHeader = function(column) { + $(trHead.insertCell(trHead.cells.length)) + .addClass("column-header") + .text(column.name); + }; + for (var i = 0; i < columns.length; i++) { + createColumnHeader(columns[i], i); + } + + /*------------------------------------------------------------ + * Data Cells + *------------------------------------------------------------ + */ + + var rows = this._projectData.rowModel.rows; + var renderRow = function(tr, r, row, even) { + $(tr).addClass(even ? "even" : "odd"); + + var cells = row.cells; + var tdIndex = tr.insertCell(tr.cells.length); + $('
').html((row.i + 1) + ".").appendTo(tdIndex); - var trHead = table.insertRow(table.rows.length); - $(trHead.insertCell(0)).addClass("column-header").html(' '); // index - - var createColumnHeader = function(column) { - $(trHead.insertCell(trHead.cells.length)) - .addClass("column-header") - .text(column.name); - }; for (var i = 0; i < columns.length; i++) { - createColumnHeader(columns[i], i); - } - - /*------------------------------------------------------------ - * Data Cells - *------------------------------------------------------------ - */ - - var rows = this._projectData.rowModel.rows; - var renderRow = function(tr, r, row, even) { - $(tr).addClass(even ? "even" : "odd"); - - var cells = row.cells; - var tdIndex = tr.insertCell(tr.cells.length); - $('
').html((row.i + 1) + ".").appendTo(tdIndex); - - for (var i = 0; i < columns.length; i++) { - var column = columns[i]; - var td = tr.insertCell(tr.cells.length); - var divContent = $('
').addClass("data-table-cell-content").appendTo(td); - - var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; - if (!cell || ("v" in cell && cell.v === null)) { - $('').html(" ").appendTo(divContent); - } else if ("e" in cell) { - $('').addClass("data-table-error").text(cell.e).appendTo(divContent); - } else if (!("r" in cell) || !cell.r) { - if (typeof cell.v !== "string") { - if (typeof cell.v == "number") { - divContent.addClass("data-table-cell-content-numeric"); - } - $('') - .addClass("data-table-value-nonstring") - .text(cell.v) - .appendTo(divContent); - } else if (URL.looksLikeUrl(cell.v)) { - $('') - .text(cell.v) - .attr("href", cell.v) - .attr("target", "_blank") - .appendTo(divContent); - } else { - $('').text(cell.v).appendTo(divContent); - } - } + var column = columns[i]; + var td = tr.insertCell(tr.cells.length); + var divContent = $('
').addClass("data-table-cell-content").appendTo(td); + + var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; + if (!cell || ("v" in cell && cell.v === null)) { + $('').html(" ").appendTo(divContent); + } else if ("e" in cell) { + $('').addClass("data-table-error").text(cell.e).appendTo(divContent); + } else if (!("r" in cell) || !cell.r) { + if (typeof cell.v !== "string") { + if (typeof cell.v == "number") { + divContent.addClass("data-table-cell-content-numeric"); + } + $('') + .addClass("data-table-value-nonstring") + .text(cell.v) + .appendTo(divContent); + } else if (URL.looksLikeUrl(cell.v)) { + $('') + .text(cell.v) + .attr("href", cell.v) + .attr("target", "_blank") + .appendTo(divContent); + } else { + $('').text(cell.v).appendTo(divContent); } - }; - - var even = true; - for (var r = 0; r < rows.length; r++) { - var row = rows[r]; - var tr = table.insertRow(table.rows.length); - even = !even; - renderRow(tr, r, row, even); - } + } + } + }; + + var even = true; + for (var r = 0; r < rows.length; r++) { + var row = rows[r]; + var tr = table.insertRow(table.rows.length); + even = !even; + renderRow(tr, r, row, even); + } }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/separator-based-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/separator-based-parser-ui.js index c4099927f..5dcf22dde 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/separator-based-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/separator-based-parser-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,43 +29,43 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.SeparatorBasedParserUI = function(controller, jobID, job, format, config, dataContainerElmt, progressContainerElmt, optionContainerElmt) { - this._controller = controller; - this._jobID = jobID; - this._job = job; - this._format = format; - this._config = config; - - this._dataContainer = dataContainerElmt; - this._progressContainer = progressContainerElmt; - this._optionContainer = optionContainerElmt; - - this._timerID = null; - this._initialize(); - this._updatePreview(); + this._controller = controller; + this._jobID = jobID; + this._job = job; + this._format = format; + this._config = config; + + this._dataContainer = dataContainerElmt; + this._progressContainer = progressContainerElmt; + this._optionContainer = optionContainerElmt; + + this._timerID = null; + this._initialize(); + this._updatePreview(); }; Refine.DefaultImportingController.parserUIs["SeparatorBasedParserUI"] = Refine.SeparatorBasedParserUI; Refine.SeparatorBasedParserUI.encodeSeparator = function(s) { - return s.replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("\t", "\\t"); + return s.replace("\\", "\\\\") + .replace("\n", "\\n") + .replace("\t", "\\t"); }; Refine.SeparatorBasedParserUI.decodeSeparator = function(s) { - return s.replace("\\n", "\n") - .replace("\\t", "\t") - .replace("\\\\", "\\"); + return s.replace("\\n", "\n") + .replace("\\t", "\t") + .replace("\\\\", "\\"); }; Refine.SeparatorBasedParserUI.prototype.dispose = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } }; Refine.SeparatorBasedParserUI.prototype.confirmReadyToCreateProject = function() { @@ -73,157 +73,157 @@ Refine.SeparatorBasedParserUI.prototype.confirmReadyToCreateProject = function() }; Refine.SeparatorBasedParserUI.prototype.getOptions = function() { - var options = {}; - - switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) { - case 'new-line': - options.lineSeparator = "\n"; - break; - default: - options.lineSeparator = Refine.SeparatorBasedParserUI.decodeSeparator( - this._optionContainerElmts.rowSeparatorInput[0].value); + var options = {}; + + switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) { + case 'new-line': + options.lineSeparator = "\n"; + break; + default: + options.lineSeparator = Refine.SeparatorBasedParserUI.decodeSeparator( + this._optionContainerElmts.rowSeparatorInput[0].value); + } + switch (this._optionContainer.find("input[name='column-separator']:checked")[0].value) { + case 'comma': + options.separator = ","; + break; + case 'tab': + options.separator = "\t"; + break; + default: + options.separator = Refine.SeparatorBasedParserUI.decodeSeparator( + this._optionContainerElmts.columnSeparatorInput[0].value); + } + + var parseIntDefault = function(s, def) { + try { + var n = parseInt(s); + if (!isNaN(n)) { + return n; + } + } catch (e) { + // Ignore } - switch (this._optionContainer.find("input[name='column-separator']:checked")[0].value) { - case 'comma': - options.separator = ","; - break; - case 'tab': - options.separator = "\t"; - break; - default: - options.separator = Refine.SeparatorBasedParserUI.decodeSeparator( - this._optionContainerElmts.columnSeparatorInput[0].value); - } - - var parseIntDefault = function(s, def) { - try { - var n = parseInt(s); - if (!isNaN(n)) { - return n; - } - } catch (e) { - // Ignore - } - return def; - }; - if (this._optionContainerElmts.ignoreCheckbox[0].checked) { - options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); - } else { - options.ignoreLines = -1; - } - if (this._optionContainerElmts.headerLinesCheckbox[0].checked) { - options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0); - } else { - options.headerLines = 0; - } - if (this._optionContainerElmts.skipCheckbox[0].checked) { - options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0); - } else { - options.skipDataLines = 0; - } - if (this._optionContainerElmts.limitCheckbox[0].checked) { - options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); - } else { - options.limit = -1; - } - options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; - - options.guessCellValueTypes = this._optionContainerElmts.guessCellValueTypesCheckbox[0].checked; - options.processQuotes = this._optionContainerElmts.processQuoteMarksCheckbox[0].checked; - - options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; - options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; - - return options; + return def; + }; + if (this._optionContainerElmts.ignoreCheckbox[0].checked) { + options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1); + } else { + options.ignoreLines = -1; + } + if (this._optionContainerElmts.headerLinesCheckbox[0].checked) { + options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0); + } else { + options.headerLines = 0; + } + if (this._optionContainerElmts.skipCheckbox[0].checked) { + options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0); + } else { + options.skipDataLines = 0; + } + if (this._optionContainerElmts.limitCheckbox[0].checked) { + options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); + } else { + options.limit = -1; + } + options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked; + + options.guessCellValueTypes = this._optionContainerElmts.guessCellValueTypesCheckbox[0].checked; + options.processQuotes = this._optionContainerElmts.processQuoteMarksCheckbox[0].checked; + + options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked; + options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; + + return options; }; Refine.SeparatorBasedParserUI.prototype._initialize = function() { - var self = this; - - this._optionContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/separator-based-parser-ui.html")); - this._optionContainerElmts = DOM.bind(this._optionContainer); - this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); - - var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom'; - this._optionContainer.find( - "input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked"); - this._optionContainerElmts.rowSeparatorInput[0].value = - Refine.SeparatorBasedParserUI.encodeSeparator(this._config.lineSeparator); - - var columnSeparatorValue = (this._config.separator == ",") ? 'comma' : - ((this._config.separator == "\t") ? 'tab' : 'custom'); - this._optionContainer.find( - "input[name='column-separator'][value='" + columnSeparatorValue + "']").attr("checked", "checked"); - this._optionContainerElmts.columnSeparatorInput[0].value = - Refine.SeparatorBasedParserUI.encodeSeparator(this._config.separator); - - if (this._config.ignoreLines > 0) { - this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); - this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); - } - if (this._config.headerLines > 0) { - this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked"); - this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString(); - } - if (this._config.limit > 0) { - this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); - this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); - } - if (this._config.skipDataLines > 0) { - this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); - this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); - } - if (this._config.storeBlankRows) { - this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); - } - - if (this._config.guessCellValueTypes) { - this._optionContainerElmts.guessCellValueTypesCheckbox.attr("checked", "checked"); - } - if (this._config.processQuotes) { - this._optionContainerElmts.processQuoteMarksCheckbox.attr("checked", "checked"); - } - - if (this._config.storeBlankCellsAsNulls) { - this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); - } - if (this._config.includeFileSources) { - this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); - } - - var onChange = function() { - self._scheduleUpdatePreview(); - }; - this._optionContainer.find("input").bind("change", onChange); - this._optionContainer.find("select").bind("change", onChange); + var self = this; + + this._optionContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/separator-based-parser-ui.html")); + this._optionContainerElmts = DOM.bind(this._optionContainer); + this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); + + var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom'; + this._optionContainer.find( + "input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked"); + this._optionContainerElmts.rowSeparatorInput[0].value = + Refine.SeparatorBasedParserUI.encodeSeparator(this._config.lineSeparator); + + var columnSeparatorValue = (this._config.separator == ",") ? 'comma' : + ((this._config.separator == "\t") ? 'tab' : 'custom'); + this._optionContainer.find( + "input[name='column-separator'][value='" + columnSeparatorValue + "']").attr("checked", "checked"); + this._optionContainerElmts.columnSeparatorInput[0].value = + Refine.SeparatorBasedParserUI.encodeSeparator(this._config.separator); + + if (this._config.ignoreLines > 0) { + this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked"); + this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString(); + } + if (this._config.headerLines > 0) { + this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked"); + this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString(); + } + if (this._config.limit > 0) { + this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); + this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); + } + if (this._config.skipDataLines > 0) { + this._optionContainerElmts.skipCheckbox.attr("checked", "checked"); + this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString(); + } + if (this._config.storeBlankRows) { + this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked"); + } + + if (this._config.guessCellValueTypes) { + this._optionContainerElmts.guessCellValueTypesCheckbox.attr("checked", "checked"); + } + if (this._config.processQuotes) { + this._optionContainerElmts.processQuoteMarksCheckbox.attr("checked", "checked"); + } + + if (this._config.storeBlankCellsAsNulls) { + this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked"); + } + if (this._config.includeFileSources) { + this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); + } + + var onChange = function() { + self._scheduleUpdatePreview(); + }; + this._optionContainer.find("input").bind("change", onChange); + this._optionContainer.find("select").bind("change", onChange); }; Refine.SeparatorBasedParserUI.prototype._scheduleUpdatePreview = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } - - var self = this; - this._timerID = window.setTimeout(function() { - self._timerID = null; - self._updatePreview(); - }, 500); // 0.5 second + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } + + var self = this; + this._timerID = window.setTimeout(function() { + self._timerID = null; + self._updatePreview(); + }, 500); // 0.5 second }; Refine.SeparatorBasedParserUI.prototype._updatePreview = function() { - var self = this; - - this._progressContainer.show(); - - this._controller.updateFormatAndOptions(this.getOptions(), function(result) { - if (result.status == "ok") { - self._controller.getPreviewData(function(projectData) { - self._progressContainer.hide(); - - new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); - }); - } - }); + var self = this; + + this._progressContainer.show(); + + this._controller.updateFormatAndOptions(this.getOptions(), function(result) { + if (result.status == "ok") { + self._controller.getPreviewData(function(projectData) { + self._progressContainer.hide(); + + new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); + }); + } + }); }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/xml-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/xml-parser-ui.js index 5a487cf14..409193413 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/xml-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/xml-parser-ui.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,208 +29,208 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Refine.XmlParserUI = function(controller, jobID, job, format, config, dataContainerElmt, progressContainerElmt, optionContainerElmt) { - - this._controller = controller; - this._jobID = jobID; - this._job = job; - this._format = format; - this._config = config; - - this._dataContainer = dataContainerElmt; - this._progressContainer = progressContainerElmt; - this._optionContainer = optionContainerElmt; - - this._timerID = null; - this._initialize(); - this._showPickRecordElementsUI(); + + this._controller = controller; + this._jobID = jobID; + this._job = job; + this._format = format; + this._config = config; + + this._dataContainer = dataContainerElmt; + this._progressContainer = progressContainerElmt; + this._optionContainer = optionContainerElmt; + + this._timerID = null; + this._initialize(); + this._showPickRecordElementsUI(); }; Refine.DefaultImportingController.parserUIs["XmlParserUI"] = Refine.XmlParserUI; Refine.XmlParserUI.prototype.dispose = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } }; Refine.XmlParserUI.prototype.confirmReadyToCreateProject = function() { if ((this._config.recordPath) && this._config.recordPath.length > 0) { - return true; + return true; } else { - window.alert('Please specify a record path first.'); + window.alert('Please specify a record path first.'); } }; Refine.XmlParserUI.prototype.getOptions = function() { - var options = { - recordPath: this._config.recordPath - }; - - if (this._optionContainerElmts.limitCheckbox[0].checked) { - options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); - } else { - options.limit = -1; - } - options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; - - return options; + var options = { + recordPath: this._config.recordPath + }; + + if (this._optionContainerElmts.limitCheckbox[0].checked) { + options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1); + } else { + options.limit = -1; + } + options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked; + + return options; }; Refine.XmlParserUI.prototype._initialize = function() { - var self = this; - - this._optionContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/xml-parser-ui.html")); - this._optionContainerElmts = DOM.bind(this._optionContainer); - this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); - - if (this._config.limit > 0) { - this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); - this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); - } - if (this._config.includeFileSources) { - this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); - } - this._optionContainerElmts.pickRecordElementsButton.click(function() { - self._showPickRecordElementsUI(); - }); - - var onChange = function() { - self._scheduleUpdatePreview(); - }; - this._optionContainer.find("input").bind("change", onChange); - this._optionContainer.find("select").bind("change", onChange); + var self = this; + + this._optionContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/xml-parser-ui.html")); + this._optionContainerElmts = DOM.bind(this._optionContainer); + this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); }); + + if (this._config.limit > 0) { + this._optionContainerElmts.limitCheckbox.attr("checked", "checked"); + this._optionContainerElmts.limitInput[0].value = this._config.limit.toString(); + } + if (this._config.includeFileSources) { + this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked"); + } + this._optionContainerElmts.pickRecordElementsButton.click(function() { + self._showPickRecordElementsUI(); + }); + + var onChange = function() { + self._scheduleUpdatePreview(); + }; + this._optionContainer.find("input").bind("change", onChange); + this._optionContainer.find("select").bind("change", onChange); }; Refine.XmlParserUI.prototype._showPickRecordElementsUI = function() { - var self = this; - - this._dataContainer.unbind().empty().html( - DOM.loadHTML("core", "scripts/index/parser-interfaces/xml-parser-select-ui.html")); - - var elmts = DOM.bind(this._dataContainer); - - var escapeElmt = $(''); - var escapeHtml = function(s) { - escapeElmt.empty().text(s); - return escapeElmt.html(); - }; - var textAsHtml = function(s) { - s = s.length <= 200 ? s : (s.substring(0, 200) + ' ...'); - return '' + escapeHtml(s) + ''; - }; - var renderNode = function(node, container, parentPath) { - if (node.t) { - $('
').html(textAsHtml(node.t)).appendTo(container); + var self = this; + + this._dataContainer.unbind().empty().html( + DOM.loadHTML("core", "scripts/index/parser-interfaces/xml-parser-select-ui.html")); + + var elmts = DOM.bind(this._dataContainer); + + var escapeElmt = $(''); + var escapeHtml = function(s) { + escapeElmt.empty().text(s); + return escapeElmt.html(); + }; + var textAsHtml = function(s) { + s = s.length <= 200 ? s : (s.substring(0, 200) + ' ...'); + return '' + escapeHtml(s) + ''; + }; + var renderNode = function(node, container, parentPath) { + if (node.t) { + $('
').html(textAsHtml(node.t)).appendTo(container); + } else { + var qname = node.n; + if (node.p) { + qname = node.p + ':' + qname; + } + + var t = qname; + if (node.a) { + t += ' ' + $.map(node.a, function(attr) { + return attr.n + '="' + attr.v + '"'; + }).join(' '); + } + if (node.ns) { + t += ' ' + $.map(node.ns, function(ns) { + return 'xmlns' + ((ns.p) ? (':' + ns.p) : '') + '="' + ns.uri + '"'; + }).join(' '); + } + + var path = [].concat(parentPath); + path.push(qname); + + var div = $('
').addClass('elmt').appendTo(container); + var hasSelectableChildren = false; + var hotspot; + if (node.c) { + if (node.c.length == 1 && (node.c[0].t)) { + $('').html('<' + t + '>' + textAsHtml(node.c[0].t) + '</' + qname + '>').appendTo(div); } else { - var qname = node.n; - if (node.p) { - qname = node.p + ':' + qname; - } - - var t = qname; - if (node.a) { - t += ' ' + $.map(node.a, function(attr) { - return attr.n + '="' + attr.v + '"'; - }).join(' '); - } - if (node.ns) { - t += ' ' + $.map(node.ns, function(ns) { - return 'xmlns' + ((ns.p) ? (':' + ns.p) : '') + '="' + ns.uri + '"'; - }).join(' '); - } - - var path = [].concat(parentPath); - path.push(qname); - - var div = $('
').addClass('elmt').appendTo(container); - var hasSelectableChildren = false; - var hotspot; - if (node.c) { - if (node.c.length == 1 && (node.c[0].t)) { - $('').html('<' + t + '>' + textAsHtml(node.c[0].t) + '</' + qname + '>').appendTo(div); - } else { - $('
').text('<' + t + '>').appendTo(div); + $('
').text('<' + t + '>').appendTo(div); - var divChildren = $('
').addClass('children').appendTo(div); - $.each(node.c, function() { - renderNode(this, divChildren, path); - }); + var divChildren = $('
').addClass('children').appendTo(div); + $.each(node.c, function() { + renderNode(this, divChildren, path); + }); - $('
').text('').appendTo(div); - hasSelectableChildren = true; - } - } else { - $('').text('<' + t + ' />').appendTo(div); - } - - var hittest = function(evt) { - if (hasSelectableChildren) { - if (evt.target !== div[0] && - (evt.target.className == 'elmt' || evt.target.parentNode !== div[0])) { - return false; - } - } - return true; - }; - div.attr('title', '/' + path.join('/')) - .bind('mouseover', function(evt) { - if (hittest(evt)) { - elmts.domContainer.find('.highlight').removeClass('highlight'); - div.addClass('highlight'); - } - }) - .bind('mouseout', function(evt) { - div.removeClass('highlight'); - }) - .click(function(evt) { - if (hittest(evt)) { - self._setRecordPath(path); - } - }); + $('
').text('').appendTo(div); + hasSelectableChildren = true; } - }; - renderNode(this._config.dom, elmts.domContainer, []); + } else { + $('').text('<' + t + ' />').appendTo(div); + } + + var hittest = function(evt) { + if (hasSelectableChildren) { + if (evt.target !== div[0] && + (evt.target.className == 'elmt' || evt.target.parentNode !== div[0])) { + return false; + } + } + return true; + }; + div.attr('title', '/' + path.join('/')) + .bind('mouseover', function(evt) { + if (hittest(evt)) { + elmts.domContainer.find('.highlight').removeClass('highlight'); + div.addClass('highlight'); + } + }) + .bind('mouseout', function(evt) { + div.removeClass('highlight'); + }) + .click(function(evt) { + if (hittest(evt)) { + self._setRecordPath(path); + } + }); + } + }; + renderNode(this._config.dom, elmts.domContainer, []); }; Refine.XmlParserUI.prototype._scheduleUpdatePreview = function() { - if (this._timerID != null) { - window.clearTimeout(this._timerID); - this._timerID = null; - } - - var self = this; - this._timerID = window.setTimeout(function() { - self._timerID = null; - self._updatePreview(); - }, 500); // 0.5 second + if (this._timerID != null) { + window.clearTimeout(this._timerID); + this._timerID = null; + } + + var self = this; + this._timerID = window.setTimeout(function() { + self._timerID = null; + self._updatePreview(); + }, 500); // 0.5 second }; Refine.XmlParserUI.prototype._setRecordPath = function(path) { - this._config.recordPath = path; - this._updatePreview(); + this._config.recordPath = path; + this._updatePreview(); }; Refine.XmlParserUI.prototype._updatePreview = function() { - var self = this; - - this._progressContainer.show(); - - var options = this.getOptions(); - // for preview, we need exact text, so it's easier to show where the columns are split - options.guessCellValueTypes = false; - - this._controller.updateFormatAndOptions(options, function(result) { - if (result.status == "ok") { - self._controller.getPreviewData(function(projectData) { - self._progressContainer.hide(); - - new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); - }, 20); - } - }); + var self = this; + + this._progressContainer.show(); + + var options = this.getOptions(); + // for preview, we need exact text, so it's easier to show where the columns are split + options.guessCellValueTypes = false; + + this._controller.updateFormatAndOptions(options, function(result) { + if (result.status == "ok") { + self._controller.getPreviewData(function(projectData) { + self._progressContainer.hide(); + + new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); + }, 20); + } + }); }; diff --git a/main/webapp/modules/core/scripts/preferences.js b/main/webapp/modules/core/scripts/preferences.js index 6fd90a30c..d797e2565 100644 --- a/main/webapp/modules/core/scripts/preferences.js +++ b/main/webapp/modules/core/scripts/preferences.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,116 +29,121 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ var preferenceUIs = []; function onLoad() { - $.post( - "/command/core/get-all-preferences", - null, - populatePreferences, - "json" - ); + $.post( + "/command/core/get-all-preferences", + null, + populatePreferences, + "json" + ); } $(onLoad); function populatePreferences(prefs) { - var body = $("#body-info").empty(); - - $('

').text("Preferences").appendTo(body); - - var table = $('

').addClass("list-table").addClass("preferences").html('').appendTo(body)[0]; - for (var k in prefs) { - var tr = table.insertRow(table.rows.length); - preferenceUIs.push(new PreferenceUI(tr, k, prefs[k])); - } - - var trLast = table.insertRow(table.rows.length); - var tdLast0 = trLast.insertCell(0); - trLast.insertCell(1); - trLast.insertCell(2); - $('
KeyValue
') + .addClass("list-table") + .addClass("preferences") + .html('') + .appendTo(body)[0]; + + for (var k in prefs) { + var tr = table.insertRow(table.rows.length); + preferenceUIs.push(new PreferenceUI(tr, k, prefs[k])); + } + + var trLast = table.insertRow(table.rows.length); + var tdLast0 = trLast.insertCell(0); + trLast.insertCell(1); + trLast.insertCell(2); + $('
KeyValue
').appendTo(typeTableContainer)[0]; - - var createTypeChoice = function(type, check) { - var typeID = typeof type == "string" ? type : type.id; - var typeName = typeof type == "string" ? type : (type.name || type.id); - - var tr = typeTable.insertRow(typeTable.rows.length); - var td0 = tr.insertCell(0); - var td1 = tr.insertCell(1); - - td0.width = "1%"; - var radio = $('') - .attr("value", typeID) - .attr("typeName", typeName) - .appendTo(td0) - .click(function() { - self._rewirePropertySuggests(this.value); - }); - - if (check) { - radio.attr("checked", "true"); - } - - if (typeName == typeID) { - $(td1).html(typeName); - } else { - $(td1).html( - typeName + - '
' + - '' + typeID + ''); - } - }; - for (var i = 0; i < this._types.length; i++) { - createTypeChoice(this._types[i], i === 0); - } - } else { - $('
') - .addClass("recon-dialog-standard-service-panel-message") - .text("Sorry, we can't suggest any type for your data. Please specify a type yourself below.") - .appendTo(this._elmts.typeContainer); - - this._panel - .find('input[name="type-choice"][value=""]') - .attr("checked", "true"); - - this._elmts.typeInput.focus(); + var self = this; + + /* + * Populate types + */ + if (this._types.length > 0) { + var typeTableContainer = $('
') + .addClass("grid-layout layout-tightest") + .appendTo(this._elmts.typeContainer); + + var typeTable = $('
').appendTo(typeTableContainer)[0]; + + var createTypeChoice = function(type, check) { + var typeID = typeof type == "string" ? type : type.id; + var typeName = typeof type == "string" ? type : (type.name || type.id); + + var tr = typeTable.insertRow(typeTable.rows.length); + var td0 = tr.insertCell(0); + var td1 = tr.insertCell(1); + + td0.width = "1%"; + var radio = $('') + .attr("value", typeID) + .attr("typeName", typeName) + .appendTo(td0) + .click(function() { + self._rewirePropertySuggests(this.value); + }); + + if (check) { + radio.attr("checked", "true"); + } + + if (typeName == typeID) { + $(td1).html(typeName); + } else { + $(td1).html( + typeName + + '
' + + '' + typeID + ''); + } + }; + for (var i = 0; i < this._types.length; i++) { + createTypeChoice(this._types[i], i === 0); } - - /* - * Populate properties - */ - var detailTableContainer = $('
') - .addClass("grid-layout layout-tightest") - .appendTo(this._elmts.detailContainer); - - var detailTable = $( - '' + - '' + - '
ColumnInclude?As Property
' - ).appendTo(detailTableContainer)[0]; - - function renderDetailColumn(column) { - var tr = detailTable.insertRow(detailTable.rows.length); - var td0 = tr.insertCell(0); - var td1 = tr.insertCell(1); - var td2 = tr.insertCell(2); - - $(td0).html(column.name); - $('') - .attr("columnName", column.name) - .appendTo(td1); - $('') - .attr("columnName", column.name) - .appendTo(td2); - } - var columns = theProject.columnModel.columns; - for (var i = 0; i < columns.length; i++) { - var column = columns[i]; - if (column !== this._column) { - renderDetailColumn(column); - } + } else { + $('
') + .addClass("recon-dialog-standard-service-panel-message") + .text("Sorry, we can't suggest any type for your data. Please specify a type yourself below.") + .appendTo(this._elmts.typeContainer); + + this._panel + .find('input[name="type-choice"][value=""]') + .attr("checked", "true"); + + this._elmts.typeInput.focus(); + } + + /* + * Populate properties + */ + var detailTableContainer = $('
') + .addClass("grid-layout layout-tightest") + .appendTo(this._elmts.detailContainer); + + var detailTable = $( + '' + + '' + + '
ColumnInclude?As Property
' + ).appendTo(detailTableContainer)[0]; + + function renderDetailColumn(column) { + var tr = detailTable.insertRow(detailTable.rows.length); + var td0 = tr.insertCell(0); + var td1 = tr.insertCell(1); + var td2 = tr.insertCell(2); + + $(td0).html(column.name); + $('') + .attr("columnName", column.name) + .appendTo(td1); + $('') + .attr("columnName", column.name) + .appendTo(td2); + } + var columns = theProject.columnModel.columns; + for (var i = 0; i < columns.length; i++) { + var column = columns[i]; + if (column !== this._column) { + renderDetailColumn(column); } + } }; ReconStandardServicePanel.prototype._wireEvents = function() { - var self = this; - var input = this._elmts.typeInput.unbind(); - - if ("suggest" in this._service && "type" in this._service.suggest) { - var suggestOptions = $.extend({}, this._service.suggest.type); - input.suggestT(suggestOptions); - } else if (this._isInFreebaseSchemaSpace()) { - input.suggestT({ type : '/type/type' }); - } - - input.bind("fb-select", function(e, data) { - self._panel - .find('input[name="type-choice"][value=""]') - .attr("checked", "true"); - - self._rewirePropertySuggests(data.id); - }); - - this._rewirePropertySuggests((this._types.length > 0) ? this._types[0] : null); + var self = this; + var input = this._elmts.typeInput.unbind(); + + if ("suggest" in this._service && "type" in this._service.suggest) { + var suggestOptions = $.extend({}, this._service.suggest.type); + input.suggestT(suggestOptions); + } else if (this._isInFreebaseSchemaSpace()) { + input.suggestT({ type : '/type/type' }); + } + + input.bind("fb-select", function(e, data) { + self._panel + .find('input[name="type-choice"][value=""]') + .attr("checked", "true"); + + self._rewirePropertySuggests(data.id); + }); + + this._rewirePropertySuggests((this._types.length > 0) ? this._types[0] : null); }; ReconStandardServicePanel.prototype._rewirePropertySuggests = function(type) { - var inputs = this._panel - .find('input[name="property"]') - .unbind(); - - if ("suggest" in this._service && "property" in this._service.suggest) { - var suggestOptions = $.extend({}, this._service.suggest.property); - if (type) { - suggestOptions.ac_param = { schema: typeof type == "string" ? type : type.id }; - } - inputs.suggestP(suggestOptions); - } else if (this._isInFreebaseSchemaSpace()) { - inputs.suggestP({ - type: '/type/property', - ac_param: { - schema: (type) ? (typeof type == "string" ? type : type.id) : "/common/topic" - } - }); + var inputs = this._panel + .find('input[name="property"]') + .unbind(); + + if ("suggest" in this._service && "property" in this._service.suggest) { + var suggestOptions = $.extend({}, this._service.suggest.property); + if (type) { + suggestOptions.ac_param = { schema: typeof type == "string" ? type : type.id }; } + inputs.suggestP(suggestOptions); + } else if (this._isInFreebaseSchemaSpace()) { + inputs.suggestP({ + type: '/type/property', + ac_param: { + schema: (type) ? (typeof type == "string" ? type : type.id) : "/common/topic" + } + }); + } }; ReconStandardServicePanel.prototype._isInFreebaseIdentifierSpace = function() { - return ReconciliationManager.isFreebaseIdOrMid(this._service.identifierSpace); + return ReconciliationManager.isFreebaseIdOrMid(this._service.identifierSpace); }; ReconStandardServicePanel.prototype._isInFreebaseSchemaSpace = function() { - return ReconciliationManager.isFreebaseId(this._service.schemaSpace); + return ReconciliationManager.isFreebaseId(this._service.schemaSpace); }; ReconStandardServicePanel.prototype.start = function() { - var self = this; - - var type = this._elmts.typeInput.data("data.suggest"); - if (!(type)) { - type = { - id: this._elmts.typeInput[0].value, - name: this._elmts.typeInput[0].value - }; + var self = this; + + var type = this._elmts.typeInput.data("data.suggest"); + if (!(type)) { + type = { + id: this._elmts.typeInput[0].value, + name: this._elmts.typeInput[0].value + }; + } + + var choices = this._panel.find('input[name="type-choice"]:checked'); + if (choices !== null && choices.length > 0) { + if (choices[0].value == '-') { + type = null; + } else if (choices[0].value != "") { + type = { + id: choices[0].value, + name: choices.attr("typeName") + }; } - - var choices = this._panel.find('input[name="type-choice"]:checked'); - if (choices !== null && choices.length > 0) { - if (choices[0].value == '-') { - type = null; - } else if (choices[0].value != "") { - type = { - id: choices[0].value, - name: choices.attr("typeName") - }; - } - } - - var columnDetails = []; - $.each( - this._panel.find('input[name="property"]'), - function() { - var property = $(this).data("data.suggest"); - if (property && property.id) { - columnDetails.push({ - column: this.getAttribute("columnName"), - property: { - id: property.id, - name: property.name - } - }); - } else { - var property = $.trim(this.value); - if (property) { - columnDetails.push({ - column: this.getAttribute("columnName"), - property: { - id: property, - name: property - } - }); - } + } + + var columnDetails = []; + $.each( + this._panel.find('input[name="property"]'), + function() { + var property = $(this).data("data.suggest"); + if (property && property.id) { + columnDetails.push({ + column: this.getAttribute("columnName"), + property: { + id: property.id, + name: property.name + } + }); + } else { + var property = $.trim(this.value); + if (property) { + columnDetails.push({ + column: this.getAttribute("columnName"), + property: { + id: property, + name: property } + }); } - ); - - Refine.postCoreProcess( - "reconcile", - {}, - { - columnName: this._column.name, - config: JSON.stringify({ - mode: "standard-service", - service: this._service.url, - identifierSpace: this._service.identifierSpace, - schemaSpace: this._service.schemaSpace, - type: (type) ? { id: type.id, name: type.name } : null, - autoMatch: this._elmts.automatchCheck[0].checked, - columnDetails: columnDetails - }) - }, - { cellsChanged: true, columnStatsChanged: true } - ); + } + } + ); + + Refine.postCoreProcess( + "reconcile", + {}, + { + columnName: this._column.name, + config: JSON.stringify({ + mode: "standard-service", + service: this._service.url, + identifierSpace: this._service.identifierSpace, + schemaSpace: this._service.schemaSpace, + type: (type) ? { id: type.id, name: type.name } : null, + autoMatch: this._elmts.automatchCheck[0].checked, + columnDetails: columnDetails + }) + }, + { cellsChanged: true, columnStatsChanged: true } + ); }; diff --git a/main/webapp/modules/core/scripts/util/ajax.js b/main/webapp/modules/core/scripts/util/ajax.js index fe22408d9..5d7aa70be 100644 --- a/main/webapp/modules/core/scripts/util/ajax.js +++ b/main/webapp/modules/core/scripts/util/ajax.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,27 +29,27 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ Ajax = {}; Ajax.chainGetJSON = function() { - var a = arguments; - var i = 0; - var next = function() { - if (i <= a.length - 3) { - var url = a[i++]; - var data = a[i++]; - var callback = a[i++]; - - $.getJSON(url, data, function(o) { - callback(o); - next(); - }, "json"); - } else if (i < a.length) { - var finalCallback = a[i++]; - finalCallback(); - } - }; - next(); + var a = arguments; + var i = 0; + var next = function() { + if (i <= a.length - 3) { + var url = a[i++]; + var data = a[i++]; + var callback = a[i++]; + + $.getJSON(url, data, function(o) { + callback(o); + next(); + }, "json"); + } else if (i < a.length) { + var finalCallback = a[i++]; + finalCallback(); + } + }; + next(); }; \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/util/custom-suggest.js b/main/webapp/modules/core/scripts/util/custom-suggest.js index 9f2232020..d00b35254 100644 --- a/main/webapp/modules/core/scripts/util/custom-suggest.js +++ b/main/webapp/modules/core/scripts/util/custom-suggest.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,22 +29,22 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ (function() { - /* - * Make suggest widgets clean up when removed. - */ - var oldInit = $.suggest.suggest.prototype._init; - $.suggest.suggest.prototype._init = function() { - oldInit.call(this); - - var self = this; - this.input.bind("remove", function() { - self._destroy(); - }); - }; - + /* + * Make suggest widgets clean up when removed. + */ + var oldInit = $.suggest.suggest.prototype._init; + $.suggest.suggest.prototype._init = function() { + oldInit.call(this); + + var self = this; + this.input.bind("remove", function() { + self._destroy(); + }); + }; + /* * Property suggest */ @@ -56,44 +56,44 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $.suggest.suggest.prototype, { create_item: function(data, response_data) { - var css = this.options.css; - - var li = $("
  • ").addClass(css.item); - - var name = $("
    ") - .addClass(css.item_name) - .append( - $("
  • ").addClass(css.item); + + var name = $("
    ") + .addClass(css.item_name) + .append( + $("
  • ").addClass(css.item); + var li = $("
  • ").addClass(css.item); - var name = $("
    ") - .addClass(css.item_name) - .append( - $("
    ") + .addClass(css.item_name) + .append( + $("
    ").addClass(css.item_type).text(data.id)); - - return li; + name.prepend($("
    ").addClass(css.item_type).text(data.id)); + + return li; } } ) ); - + $.extend( $.suggest.suggestT, { @@ -149,7 +149,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. true, {}, $.suggest.suggest.defaults, { - css: { pane: "fbs-pane fbs-pane-type" } + css: { pane: "fbs-pane fbs-pane-type" } } ) } diff --git a/main/webapp/modules/core/scripts/util/dialog.js b/main/webapp/modules/core/scripts/util/dialog.js index a9f10b6cb..f337c1ed0 100644 --- a/main/webapp/modules/core/scripts/util/dialog.js +++ b/main/webapp/modules/core/scripts/util/dialog.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,95 +29,95 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ DialogSystem = { _layers: [] }; DialogSystem.showDialog = function(elmt, onCancel) { - var overlay = $('
     
    ') - .addClass("dialog-overlay") - .css("z-index", 101 + DialogSystem._layers.length * 2) - .appendTo(document.body); - - var container = $('
    ') - .addClass("dialog-container") - .css("z-index", 102 + DialogSystem._layers.length * 2) - .appendTo(document.body); - - elmt.css("visibility", "hidden").appendTo(container); - container.css("top", Math.round((overlay.height() - elmt.height()) / 2) + "px"); - elmt.css("visibility", "visible"); - - container.draggable({ handle: '.dialog-header', cursor: 'move' }); - - var layer = { - overlay: overlay, - container: container, - onCancel: onCancel - }; - DialogSystem._layers.push(layer); - - var level = DialogSystem._layers.length; - - layer.keyHandler = function(evt) { - if (evt.keyCode == 27 && !evt.shiftKey && !evt.metaKey && !evt.altKey && !evt.ctrlKey && - evt.target.tagName.toLowerCase() != "input" && - evt.target.tagName.toLowerCase() != "textarea") { - - DialogSystem.dismissUntil(level - 1); - evt.stopImmediatePropagation(); - evt.stopPropagation(); - evt.preventDefault(); - return false; - } - }; - $(document).stack("keydown", layer.keyHandler); - - return level; + var overlay = $('
     
    ') + .addClass("dialog-overlay") + .css("z-index", 101 + DialogSystem._layers.length * 2) + .appendTo(document.body); + + var container = $('
    ') + .addClass("dialog-container") + .css("z-index", 102 + DialogSystem._layers.length * 2) + .appendTo(document.body); + + elmt.css("visibility", "hidden").appendTo(container); + container.css("top", Math.round((overlay.height() - elmt.height()) / 2) + "px"); + elmt.css("visibility", "visible"); + + container.draggable({ handle: '.dialog-header', cursor: 'move' }); + + var layer = { + overlay: overlay, + container: container, + onCancel: onCancel + }; + DialogSystem._layers.push(layer); + + var level = DialogSystem._layers.length; + + layer.keyHandler = function(evt) { + if (evt.keyCode == 27 && !evt.shiftKey && !evt.metaKey && !evt.altKey && !evt.ctrlKey && + evt.target.tagName.toLowerCase() != "input" && + evt.target.tagName.toLowerCase() != "textarea") { + + DialogSystem.dismissUntil(level - 1); + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); + return false; + } + }; + $(document).stack("keydown", layer.keyHandler); + + return level; }; DialogSystem.dismissAll = function() { - DialogSystem.dismissUntil(0); + DialogSystem.dismissUntil(0); }; DialogSystem.dismissUntil = function(level) { - for (var i = DialogSystem._layers.length - 1; i >= level; i--) { - var layer = DialogSystem._layers[i]; - - $(document).unbind("keydown", layer.keyHandler); - - layer.overlay.remove(); - layer.container.remove(); - layer.container.unbind(); - - if (layer.onCancel) { - try { - layer.onCancel(); - } catch (e) { - Refine.reportException(e); - } - } + for (var i = DialogSystem._layers.length - 1; i >= level; i--) { + var layer = DialogSystem._layers[i]; + + $(document).unbind("keydown", layer.keyHandler); + + layer.overlay.remove(); + layer.container.remove(); + layer.container.unbind(); + + if (layer.onCancel) { + try { + layer.onCancel(); + } catch (e) { + Refine.reportException(e); + } } - DialogSystem._layers = DialogSystem._layers.slice(0, level); + } + DialogSystem._layers = DialogSystem._layers.slice(0, level); }; DialogSystem.createDialog = function() { - return $('
    ').addClass("dialog-frame"); + return $('
    ').addClass("dialog-frame"); }; DialogSystem.showBusy = function(message) { - var frame = DialogSystem.createDialog(); - frame.addClass("dialog-busy"); - - var body = $('
    ').attr('id', 'loading-message').appendTo(frame); - $('').attr("src", "images/large-spinner.gif").appendTo(body); - $('').text(" " + (message || "Working...")).appendTo(body); - - var level = DialogSystem.showDialog(frame); - - return function() { - DialogSystem.dismissUntil(level - 1); - }; + var frame = DialogSystem.createDialog(); + frame.addClass("dialog-busy"); + + var body = $('
    ').attr('id', 'loading-message').appendTo(frame); + $('').attr("src", "images/large-spinner.gif").appendTo(body); + $('').text(" " + (message || "Working...")).appendTo(body); + + var level = DialogSystem.showDialog(frame); + + return function() { + DialogSystem.dismissUntil(level - 1); + }; }; diff --git a/main/webapp/modules/core/scripts/util/dom.js b/main/webapp/modules/core/scripts/util/dom.js index f18e69c41..67da5f93e 100644 --- a/main/webapp/modules/core/scripts/util/dom.js +++ b/main/webapp/modules/core/scripts/util/dom.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,62 +29,62 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ var DOM = {}; DOM.bind = function(elmt) { - var map = {}; - - for (var i = 0; i < elmt.length; i++) { - DOM._bindDOMElement(elmt[i], map); - } - - return map; + var map = {}; + + for (var i = 0; i < elmt.length; i++) { + DOM._bindDOMElement(elmt[i], map); + } + + return map; }; DOM._bindDOMElement = function(elmt, map) { - var bind = elmt.getAttribute("bind"); - if (bind !== null && bind.length > 0) { - map[bind] = $(elmt); - } - - if (elmt.hasChildNodes()) { - DOM._bindDOMChildren(elmt, map); - } + var bind = elmt.getAttribute("bind"); + if (bind !== null && bind.length > 0) { + map[bind] = $(elmt); + } + + if (elmt.hasChildNodes()) { + DOM._bindDOMChildren(elmt, map); + } }; DOM._bindDOMChildren = function(elmt, map) { - var node = elmt.firstChild; - while (node !== null) { - var node2 = node.nextSibling; - if (node.nodeType == 1) { - DOM._bindDOMElement(node, map); - } - node = node2; + var node = elmt.firstChild; + while (node !== null) { + var node2 = node.nextSibling; + if (node.nodeType == 1) { + DOM._bindDOMElement(node, map); } + node = node2; + } }; DOM._loadedHTML = {}; DOM.loadHTML = function(module, path) { - var fullPath = ModuleWirings[module] + path; - if (!(fullPath in DOM._loadedHTML)) { - $.ajax({ - async: false, - url: fullPath, - dataType: "html", - success: function(html) { - DOM._loadedHTML[fullPath] = html; - } - }) - } - return DOM._loadedHTML[fullPath]; + var fullPath = ModuleWirings[module] + path; + if (!(fullPath in DOM._loadedHTML)) { + $.ajax({ + async: false, + url: fullPath, + dataType: "html", + success: function(html) { + DOM._loadedHTML[fullPath] = html; + } + }) + } + return DOM._loadedHTML[fullPath]; }; DOM.getHPaddings = function(elmt) { - return elmt.outerWidth() - elmt.width(); + return elmt.outerWidth() - elmt.width(); }; DOM.getVPaddings = function(elmt) { - return elmt.outerHeight() - elmt.height(); + return elmt.outerHeight() - elmt.height(); }; diff --git a/main/webapp/modules/core/scripts/util/menu.js b/main/webapp/modules/core/scripts/util/menu.js index db99398ce..8b907054a 100644 --- a/main/webapp/modules/core/scripts/util/menu.js +++ b/main/webapp/modules/core/scripts/util/menu.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,264 +29,264 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ MenuSystem = { - _layers: [], - _overlay: null + _layers: [], + _overlay: null }; MenuSystem.showMenu = function(elmt, onDismiss) { - if (!MenuSystem._overlay) { - MenuSystem._overlay = $('
     
    ') - .addClass("menu-overlay") - .appendTo(document.body) - .click(MenuSystem.dismissAll); + if (!MenuSystem._overlay) { + MenuSystem._overlay = $('
     
    ') + .addClass("menu-overlay") + .appendTo(document.body) + .click(MenuSystem.dismissAll); + } + + elmt.css("z-index", 1010 + MenuSystem._layers.length).appendTo(document.body); + + var layer = { + elmt: elmt, + onDismiss: onDismiss + }; + + MenuSystem._layers.push(layer); + + var level = MenuSystem._layers.length; + + layer.keyHandler = function(evt) { + if (evt.keyCode == 27 && !evt.shiftKey && !evt.metaKey && !evt.altKey && !evt.ctrlKey && + evt.target.tagName.toLowerCase() != "input" && + evt.target.tagName.toLowerCase() != "textarea") { + MenuSystem.dismissUntil(level - 1); + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); + return false; } - - elmt.css("z-index", 1010 + MenuSystem._layers.length).appendTo(document.body); - - var layer = { - elmt: elmt, - onDismiss: onDismiss - }; - - MenuSystem._layers.push(layer); - - var level = MenuSystem._layers.length; - - layer.keyHandler = function(evt) { - if (evt.keyCode == 27 && !evt.shiftKey && !evt.metaKey && !evt.altKey && !evt.ctrlKey && - evt.target.tagName.toLowerCase() != "input" && - evt.target.tagName.toLowerCase() != "textarea") { - MenuSystem.dismissUntil(level - 1); - evt.stopImmediatePropagation(); - evt.stopPropagation(); - evt.preventDefault(); - return false; - } - }; - $(document).stack("keydown", layer.keyHandler); - - return level; + }; + $(document).stack("keydown", layer.keyHandler); + + return level; }; MenuSystem.dismissAll = function() { - MenuSystem.dismissUntil(0); - if (MenuSystem._overlay !== null) { - MenuSystem._overlay.remove(); - MenuSystem._overlay = null; - } + MenuSystem.dismissUntil(0); + if (MenuSystem._overlay !== null) { + MenuSystem._overlay.remove(); + MenuSystem._overlay = null; + } }; MenuSystem.dismissUntil = function(level) { - for (var i = MenuSystem._layers.length - 1; i >= level; i--) { - var layer = MenuSystem._layers[i]; - - $(document).unbind("keydown", layer.keyHandler); - - layer.elmt.remove(); - layer.elmt.unbind(); - layer.onDismiss(); - } - MenuSystem._layers = MenuSystem._layers.slice(0, level); + for (var i = MenuSystem._layers.length - 1; i >= level; i--) { + var layer = MenuSystem._layers[i]; + + $(document).unbind("keydown", layer.keyHandler); + + layer.elmt.remove(); + layer.elmt.unbind(); + layer.onDismiss(); + } + MenuSystem._layers = MenuSystem._layers.slice(0, level); }; MenuSystem.createMenu = function() { - return $('
    ').addClass("menu-container"); + return $('
    ').addClass("menu-container"); }; MenuSystem.createMenuItem = function() { - return $('').addClass("menu-item"); + return $('
    ').addClass("menu-item"); }; MenuSystem.positionMenuAboveBelow = function(menu, elmt) { - var offset = elmt.offset(); - var windowWidth = $(window).width(); - var windowHeight = $(window).height(); - - if (offset.top + elmt.outerHeight() - document.body.scrollTop + menu.outerHeight() > windowHeight - 10) { - menu.css("top", (offset.top - menu.outerHeight()) + "px"); - } else { - menu.css("top", (offset.top + elmt.outerHeight()) + "px"); - } - - if (offset.left - document.body.scrollLeft + menu.outerWidth() > windowWidth - 10) { - menu.css("left", (offset.left + elmt.outerWidth() - menu.outerWidth()) + "px"); - } else { - menu.css("left", offset.left + "px"); - } + var offset = elmt.offset(); + var windowWidth = $(window).width(); + var windowHeight = $(window).height(); + + if (offset.top + elmt.outerHeight() - document.body.scrollTop + menu.outerHeight() > windowHeight - 10) { + menu.css("top", (offset.top - menu.outerHeight()) + "px"); + } else { + menu.css("top", (offset.top + elmt.outerHeight()) + "px"); + } + + if (offset.left - document.body.scrollLeft + menu.outerWidth() > windowWidth - 10) { + menu.css("left", (offset.left + elmt.outerWidth() - menu.outerWidth()) + "px"); + } else { + menu.css("left", offset.left + "px"); + } }; MenuSystem.positionMenuLeftRight = function(menu, elmt) { - var offset = elmt.offset(); - var windowWidth = $(window).width(); - var windowHeight = $(window).height(); - - if (offset.top - document.body.scrollTop + menu.outerHeight() > windowHeight - 10) { - menu.css("top", (offset.top + elmt.outerHeight() - menu.outerHeight()) + "px"); - } else { - menu.css("top", offset.top + "px"); - } - - if (offset.left + elmt.outerWidth() - document.body.scrollLeft + menu.outerWidth() > windowWidth - 10) { - menu.css("left", Math.max(10, offset.left - menu.outerWidth()) + "px"); - } else { - menu.css("left", (offset.left + elmt.outerWidth()) + "px"); - } + var offset = elmt.offset(); + var windowWidth = $(window).width(); + var windowHeight = $(window).height(); + + if (offset.top - document.body.scrollTop + menu.outerHeight() > windowHeight - 10) { + menu.css("top", (offset.top + elmt.outerHeight() - menu.outerHeight()) + "px"); + } else { + menu.css("top", offset.top + "px"); + } + + if (offset.left + elmt.outerWidth() - document.body.scrollLeft + menu.outerWidth() > windowWidth - 10) { + menu.css("left", Math.max(10, offset.left - menu.outerWidth()) + "px"); + } else { + menu.css("left", (offset.left + elmt.outerWidth()) + "px"); + } }; MenuSystem.createAndShowStandardMenu = function(items, elmt, options) { - options = options || { - horizontal: false - }; - - var menu = MenuSystem.createMenu(); - if ("width" in options) { - menu.width(options.width); - } - - var createMenuItem = function(item) { - if ("label" in item) { - var menuItem = MenuSystem.createMenuItem().appendTo(menu); - if ("submenu" in item) { - menuItem.html( - '' + - '' + - '' + - '' - ); - menuItem.mouseenter(function() { - MenuSystem.dismissUntil(level); - - menuItem.addClass("menu-expanded"); - - var options = { - horizontal: true, - onDismiss: function() { - menuItem.removeClass("menu-expanded"); - } - }; - if ("width" in item) { - options.width = item.width; - } - - MenuSystem.createAndShowStandardMenu(item.submenu, this, options); - }); - } else { - menuItem.html(item.label).click(function(evt) { - item.click.call(this, evt); - MenuSystem.dismissAll(); - }); - if ("tooltip" in item) { - menuItem.attr("title", item.tooltip); - } - menuItem.mouseenter(function() { - MenuSystem.dismissUntil(level); - }); + options = options || { + horizontal: false + }; + + var menu = MenuSystem.createMenu(); + if ("width" in options) { + menu.width(options.width); + } + + var createMenuItem = function(item) { + if ("label" in item) { + var menuItem = MenuSystem.createMenuItem().appendTo(menu); + if ("submenu" in item) { + menuItem.html( + '' + + '' + + '' + + '' + ); + menuItem.mouseenter(function() { + MenuSystem.dismissUntil(level); + + menuItem.addClass("menu-expanded"); + + var options = { + horizontal: true, + onDismiss: function() { + menuItem.removeClass("menu-expanded"); } - } else if ("heading" in item) { - $('
    ').addClass("menu-section").text(item.heading).appendTo(menu); - } else { - $('
    ').appendTo(menu); + }; + if ("width" in item) { + options.width = item.width; + } + + MenuSystem.createAndShowStandardMenu(item.submenu, this, options); + }); + } else { + menuItem.html(item.label).click(function(evt) { + item.click.call(this, evt); + MenuSystem.dismissAll(); + }); + if ("tooltip" in item) { + menuItem.attr("title", item.tooltip); } - }; - - for (var i = 0; i < items.length; i++) { - createMenuItem(items[i]); - } - - var level = MenuSystem.showMenu(menu, "onDismiss" in options ? options.onDismiss : function(){}); - if (options.horizontal) { - MenuSystem.positionMenuLeftRight(menu, $(elmt)); + menuItem.mouseenter(function() { + MenuSystem.dismissUntil(level); + }); + } + } else if ("heading" in item) { + $('
    ').addClass("menu-section").text(item.heading).appendTo(menu); } else { - MenuSystem.positionMenuAboveBelow(menu, $(elmt)); + $('
    ').appendTo(menu); } - - return level; + }; + + for (var i = 0; i < items.length; i++) { + createMenuItem(items[i]); + } + + var level = MenuSystem.showMenu(menu, "onDismiss" in options ? options.onDismiss : function(){}); + if (options.horizontal) { + MenuSystem.positionMenuLeftRight(menu, $(elmt)); + } else { + MenuSystem.positionMenuAboveBelow(menu, $(elmt)); + } + + return level; }; MenuSystem.find = function(rootItems, path, levels) { - var menuItems = rootItems; - for (var p = 0; p < path.length && p < levels; p++) { - var segment = path[p]; - var subMenuItems; - - for (var i = 0; i < menuItems.length; i++) { - var menuItem = menuItems[i]; - if (menuItem.id == segment) { - if ("submenu" in menuItem) { - subMenuItems = menuItem.submenu; - } else { - return undefined; - } - break; - } - } - - if (subMenuItems) { - menuItems = subMenuItems; + var menuItems = rootItems; + for (var p = 0; p < path.length && p < levels; p++) { + var segment = path[p]; + var subMenuItems; + + for (var i = 0; i < menuItems.length; i++) { + var menuItem = menuItems[i]; + if (menuItem.id == segment) { + if ("submenu" in menuItem) { + subMenuItems = menuItem.submenu; } else { - return undefined; + return undefined; } + break; + } } - - return menuItems; + + if (subMenuItems) { + menuItems = subMenuItems; + } else { + return undefined; + } + } + + return menuItems; }; MenuSystem.appendTo = function(rootItems, path, what) { - var menuItems = MenuSystem.find(rootItems, path, path.length); - if (menuItems) { - if (what instanceof Array) { - $.merge(menuItems, what); - } else { - menuItems.push(what); - } + var menuItems = MenuSystem.find(rootItems, path, path.length); + if (menuItems) { + if (what instanceof Array) { + $.merge(menuItems, what); + } else { + menuItems.push(what); } + } }; MenuSystem.insertBefore = function(rootItems, path, what) { - var menuItems = MenuSystem.find(rootItems, path, path.length - 1); - if ((menuItems) && path.length > 0) { - var spliceArgs = [ 0, 0 ]; - if (what instanceof Array) { - $.merge(spliceArgs, what); - } else { - spliceArgs.push(what); - } - - var segment = path[path.length - 1]; - for (var i = 0; i < menuItems.length; i++) { - var menuItem = menuItems[i]; - if (menuItem.id == segment) { - spliceArgs[0] = i; - break; - } - } - - Array.prototype.splice.apply(menuItems, spliceArgs); + var menuItems = MenuSystem.find(rootItems, path, path.length - 1); + if ((menuItems) && path.length > 0) { + var spliceArgs = [ 0, 0 ]; + if (what instanceof Array) { + $.merge(spliceArgs, what); + } else { + spliceArgs.push(what); } + + var segment = path[path.length - 1]; + for (var i = 0; i < menuItems.length; i++) { + var menuItem = menuItems[i]; + if (menuItem.id == segment) { + spliceArgs[0] = i; + break; + } + } + + Array.prototype.splice.apply(menuItems, spliceArgs); + } }; MenuSystem.insertAfter = function(rootItems, path, what) { - var menuItems = MenuSystem.find(rootItems, path, path.length - 1); - if ((menuItems) && path.length > 0) { - var spliceArgs = [ menuItems.length, 0 ]; - if (what instanceof Array) { - $.merge(spliceArgs, what); - } else { - spliceArgs.push(what); - } - - var segment = path[path.length - 1]; - for (var i = 0; i < menuItems.length; i++) { - var menuItem = menuItems[i]; - if (menuItem.id == segment) { - spliceArgs[0] = i + 1; - break; - } - } - - Array.prototype.splice.apply(menuItems, spliceArgs); + var menuItems = MenuSystem.find(rootItems, path, path.length - 1); + if ((menuItems) && path.length > 0) { + var spliceArgs = [ menuItems.length, 0 ]; + if (what instanceof Array) { + $.merge(spliceArgs, what); + } else { + spliceArgs.push(what); } + + var segment = path[path.length - 1]; + for (var i = 0; i < menuItems.length; i++) { + var menuItem = menuItems[i]; + if (menuItem.id == segment) { + spliceArgs[0] = i + 1; + break; + } + } + + Array.prototype.splice.apply(menuItems, spliceArgs); + } }; \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/util/misc.js b/main/webapp/modules/core/scripts/util/misc.js index 96a83a680..2e465392e 100644 --- a/main/webapp/modules/core/scripts/util/misc.js +++ b/main/webapp/modules/core/scripts/util/misc.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,28 +29,28 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function cloneDeep(o) { - if (o === undefined || o === null) { - return o; - } else if (o instanceof Function) { - return o; - } else if (o instanceof Array) { - var a = []; - for (var i = 0; i < o.length; i++) { - a.push(cloneDeep(o[i])); - } - return a; - } else if (o instanceof Object) { - var a = {}; - for (var n in o) { - if (o.hasOwnProperty(n)) { - a[n] = cloneDeep(o[n]); - } - } - return a; - } else { - return o; + if (o === undefined || o === null) { + return o; + } else if (o instanceof Function) { + return o; + } else if (o instanceof Array) { + var a = []; + for (var i = 0; i < o.length; i++) { + a.push(cloneDeep(o[i])); } + return a; + } else if (o instanceof Object) { + var a = {}; + for (var n in o) { + if (o.hasOwnProperty(n)) { + a[n] = cloneDeep(o[n]); + } + } + return a; + } else { + return o; + } } \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/util/string.js b/main/webapp/modules/core/scripts/util/string.js index 184413b62..4162a29b6 100644 --- a/main/webapp/modules/core/scripts/util/string.js +++ b/main/webapp/modules/core/scripts/util/string.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,20 +29,20 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ String.prototype.trim = function() { - return this.replace(/^\s+/, '').replace(/\s+$/, ''); + return this.replace(/^\s+/, '').replace(/\s+$/, ''); }; String.prototype.startsWith = function(s) { - return this.length >= s.length && this.substring(0, s.length) == s; + return this.length >= s.length && this.substring(0, s.length) == s; }; String.prototype.endsWith = function(s) { - return this.length >= s.length && this.substring(this.length - s.length) == s; + return this.length >= s.length && this.substring(this.length - s.length) == s; }; String.prototype.contains = function(s) { - return this.indexOf(s) >= 0; + return this.indexOf(s) >= 0; }; \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/util/url.js b/main/webapp/modules/core/scripts/util/url.js index a7b457711..5b929380e 100644 --- a/main/webapp/modules/core/scripts/util/url.js +++ b/main/webapp/modules/core/scripts/util/url.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,89 +29,89 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ URL = { - schemes: { // 1 means followed by ://, 0 means followed by just : - "callto":0, - "chrome":1, - "file":1, - "ftp":1, - "http":1, - "https":1, - "imap":1, - "info":0, - "irc":1, - "jar":0, - "javascript":0, - "lastfm":1, - "ldap":1, - "ldaps":1, - "mailto":0, - "news":0, - "nntp":1, - "pop":1, - "sftp":1, - "skype":0, - "smb":1, - "ssh":1, - "svn":1, - "svn+ssh":1, - "telnet":1, - "view-source":0 - } + schemes: { // 1 means followed by ://, 0 means followed by just : + "callto":0, + "chrome":1, + "file":1, + "ftp":1, + "http":1, + "https":1, + "imap":1, + "info":0, + "irc":1, + "jar":0, + "javascript":0, + "lastfm":1, + "ldap":1, + "ldaps":1, + "mailto":0, + "news":0, + "nntp":1, + "pop":1, + "sftp":1, + "skype":0, + "smb":1, + "ssh":1, + "svn":1, + "svn+ssh":1, + "telnet":1, + "view-source":0 + } }; (function() { - var minLength = 100; - var maxLength = 0; - - for (var n in URL.schemes) { - minLength = Math.min(minLength, n.length); - maxLength = Math.max(maxLength, n.length); - } - - URL.minSchemeLength = minLength; - URL.maxSchemeLength = maxLength; + var minLength = 100; + var maxLength = 0; + + for (var n in URL.schemes) { + minLength = Math.min(minLength, n.length); + maxLength = Math.max(maxLength, n.length); + } + + URL.minSchemeLength = minLength; + URL.maxSchemeLength = maxLength; })(); URL.getParameters = function() { - var r = {}; - - var params = window.location.search; - if (params.length > 1) { - params = params.substr(1).split("&"); - $.each(params, function() { - pair = this.split("="); - r[pair[0]] = unescape(pair[1]); - }); - } - - return r; + var r = {}; + + var params = window.location.search; + if (params.length > 1) { + params = params.substr(1).split("&"); + $.each(params, function() { + pair = this.split("="); + r[pair[0]] = unescape(pair[1]); + }); + } + + return r; }; URL.looksLikeUrl = function(s) { - if (s.length > URL.minSchemeLength + 1) { - var sep = s.substring(0, URL.maxSchemeLength + 3).indexOf(":"); - if (sep >= URL.minSchemeLength) { - var scheme = s.substring(0, sep).toLowerCase(); - if (scheme in URL.schemes) { - return URL.schemes[scheme] == 0 || - s.substring(sep + 1, sep + 3) == "//"; - } - } + if (s.length > URL.minSchemeLength + 1) { + var sep = s.substring(0, URL.maxSchemeLength + 3).indexOf(":"); + if (sep >= URL.minSchemeLength) { + var scheme = s.substring(0, sep).toLowerCase(); + if (scheme in URL.schemes) { + return URL.schemes[scheme] == 0 || + s.substring(sep + 1, sep + 3) == "//"; + } } - return false; + } + return false; }; URL.getHostname = function(){ - var url = location.href; // entire url including querystring - also: window.location.href; - var baseURL = url.substring(0, url.indexOf('/',7));//7 is the length of http:// - return baseURL; + var url = location.href; // entire url including querystring - also: window.location.href; + var baseURL = url.substring(0, url.indexOf('/',7));//7 is the length of http:// + return baseURL; }; URL.urlify = function(str) { - if(!str) { - return ''; - } - return escape(str.replace(/\W/g, '_')); + if(!str) { + return ''; + } + return escape(str.replace(/\W/g, '_')); }; \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/views/data-table/add-column-by-fetching-urls-dialog.html b/main/webapp/modules/core/scripts/views/data-table/add-column-by-fetching-urls-dialog.html index 84c31b3d9..ad0f25eb3 100644 --- a/main/webapp/modules/core/scripts/views/data-table/add-column-by-fetching-urls-dialog.html +++ b/main/webapp/modules/core/scripts/views/data-table/add-column-by-fetching-urls-dialog.html @@ -3,20 +3,20 @@
    - - - - - - - - - - - - - + + + + + + + + + + + + +
    New column nameThrottle delay milliseconds
    On error set to blank - store error

    Formulate the URLs to fetch:

    $EXPRESSION_PREVIEW_WIDGET$
    New column nameThrottle delay milliseconds
    On error set to blank + store error

    Formulate the URLs to fetch:

    $EXPRESSION_PREVIEW_WIDGET$
  • Valid values
  • '; - var blankValuesHtml = '
  • Blanks
  • '; - var errorValuesHtml = '
  • Errors
  • '; - var positionsHtml; - if (criterion.blankPosition < 0) { - if (criterion.errorPosition > 0) { - positionsHtml = [ blankValuesHtml, validValuesHtml, errorValuesHtml ]; - } else if (criterion.errorPosition < criterion.blankPosition) { - positionsHtml = [ errorValuesHtml, blankValuesHtml, validValuesHtml ]; - } else { - positionsHtml = [ blankValuesHtml, errorValuesHtml, validValuesHtml ]; - } + }; + elmts.valueTypeOptions + .find("input[type='radio']") + .change(function() { + setValueType(this.value); + }); + + if (criterion.valueType == "string" && criterion.caseSensitive) { + elmts.caseSensitiveCheckbox.attr("checked", "checked"); + } + + elmts.directionOptions + .find("input[type='radio'][value='" + (criterion.reverse ? "reverse" : "forward") + "']") + .attr("checked", "checked"); + + if (hasOtherCriteria) { + elmts.sortAloneContainer.show(); + } + + var validValuesHtml = '
  • Valid values
  • '; + var blankValuesHtml = '
  • Blanks
  • '; + var errorValuesHtml = '
  • Errors
  • '; + var positionsHtml; + if (criterion.blankPosition < 0) { + if (criterion.errorPosition > 0) { + positionsHtml = [ blankValuesHtml, validValuesHtml, errorValuesHtml ]; + } else if (criterion.errorPosition < criterion.blankPosition) { + positionsHtml = [ errorValuesHtml, blankValuesHtml, validValuesHtml ]; } else { - if (criterion.errorPosition < 0) { - positionsHtml = [ errorValuesHtml, validValuesHtml, blankValuesHtml ]; - } else if (criterion.errorPosition < criterion.blankPosition) { - positionsHtml = [ validValuesHtml, errorValuesHtml, blankValuesHtml ]; - } else { - positionsHtml = [ validValuesHtml, blankValuesHtml, errorValuesHtml ]; - } + positionsHtml = [ blankValuesHtml, errorValuesHtml, validValuesHtml ]; } - elmts.blankErrorPositions.html(positionsHtml.join("")).sortable().disableSelection(); - - var level = DialogSystem.showDialog(frame); - var dismiss = function() { DialogSystem.dismissUntil(level - 1); }; - - setValueType(criterion.valueType); - - elmts.cancelButton.click(dismiss); - elmts.okButton.click(function() { - var criterion2 = { - column: self._column.name, - valueType: elmts.valueTypeOptions.find("input[type='radio']:checked")[0].value, - reverse: elmts.directionOptions.find("input[type='radio']:checked")[0].value == "reverse" - }; - - var valuePosition, blankPosition, errorPosition; - elmts.blankErrorPositions.find("li").each(function(index, elmt) { - var kind = this.getAttribute("kind"); - if (kind == "value") { - valuePosition = index; - } else if (kind == "blank") { - blankPosition = index; - } else if (kind == "error") { - errorPosition = index; - } - }); - criterion2.blankPosition = blankPosition - valuePosition; - criterion2.errorPosition = errorPosition - valuePosition; - - if (criterion2.valueType == "string") { - criterion2.caseSensitive = elmts.caseSensitiveCheckbox[0].checked; - } - - self._dataTableView._addSortingCriterion( - criterion2, elmts.sortAloneContainer.find("input")[0].checked); - - dismiss(); + } else { + if (criterion.errorPosition < 0) { + positionsHtml = [ errorValuesHtml, validValuesHtml, blankValuesHtml ]; + } else if (criterion.errorPosition < criterion.blankPosition) { + positionsHtml = [ validValuesHtml, errorValuesHtml, blankValuesHtml ]; + } else { + positionsHtml = [ validValuesHtml, blankValuesHtml, errorValuesHtml ]; + } + } + elmts.blankErrorPositions.html(positionsHtml.join("")).sortable().disableSelection(); + + var level = DialogSystem.showDialog(frame); + var dismiss = function() { DialogSystem.dismissUntil(level - 1); }; + + setValueType(criterion.valueType); + + elmts.cancelButton.click(dismiss); + elmts.okButton.click(function() { + var criterion2 = { + column: self._column.name, + valueType: elmts.valueTypeOptions.find("input[type='radio']:checked")[0].value, + reverse: elmts.directionOptions.find("input[type='radio']:checked")[0].value == "reverse" + }; + + var valuePosition, blankPosition, errorPosition; + elmts.blankErrorPositions.find("li").each(function(index, elmt) { + var kind = this.getAttribute("kind"); + if (kind == "value") { + valuePosition = index; + } else if (kind == "blank") { + blankPosition = index; + } else if (kind == "error") { + errorPosition = index; + } }); + criterion2.blankPosition = blankPosition - valuePosition; + criterion2.errorPosition = errorPosition - valuePosition; + + if (criterion2.valueType == "string") { + criterion2.caseSensitive = elmts.caseSensitiveCheckbox[0].checked; + } + + self._dataTableView._addSortingCriterion( + criterion2, elmts.sortAloneContainer.find("input")[0].checked); + + dismiss(); + }); }; \ No newline at end of file diff --git a/main/webapp/modules/core/scripts/views/data-table/data-table-view.js b/main/webapp/modules/core/scripts/views/data-table/data-table-view.js index 396731f2d..472451f81 100644 --- a/main/webapp/modules/core/scripts/views/data-table/data-table-view.js +++ b/main/webapp/modules/core/scripts/views/data-table/data-table-view.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,695 +29,703 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ function DataTableView(div) { - this._div = div; - - this._pageSize = 10; - this._showRecon = true; - this._collapsedColumnNames = {}; - this._sorting = { criteria: [] }; - this._columnHeaderUIs = []; - - this._showRows(0); + this._div = div; + + this._pageSize = 10; + this._showRecon = true; + this._collapsedColumnNames = {}; + this._sorting = { criteria: [] }; + this._columnHeaderUIs = []; + + this._showRows(0); } DataTableView._extenders = []; /* - To extend, do something like this - - DataTableView.extendMenu(function(dataTableView, menu) { - ... - MenuSystem.appendTo(menu, [ "core/view" ], { - "label": "Test", - "click": function() { - alert("Test"); - } - }); + To extend, do something like this + + DataTableView.extendMenu(function(dataTableView, menu) { + ... + MenuSystem.appendTo(menu, [ "core/view" ], { + "label": "Test", + "click": function() { + alert("Test"); + } }); + }); */ DataTableView.extendMenu = function(extender) { - DataTableView._extenders.push(extender); + DataTableView._extenders.push(extender); }; DataTableView.prototype.getSorting = function() { - return this._sorting; + return this._sorting; }; DataTableView.prototype.resize = function() { - var topHeight = this._div.find(".viewpanel-header").outerHeight(true); - var tableContainerIntendedHeight = this._div.innerHeight() - topHeight; - - var tableContainer = this._div.find(".data-table-container").css("display", "block"); - var tableContainerVPadding = tableContainer.outerHeight(true) - tableContainer.height(); - tableContainer.height((tableContainerIntendedHeight - tableContainerVPadding) + "px"); + var topHeight = this._div.find(".viewpanel-header").outerHeight(true); + var tableContainerIntendedHeight = this._div.innerHeight() - topHeight; + + var tableContainer = this._div.find(".data-table-container").css("display", "block"); + var tableContainerVPadding = tableContainer.outerHeight(true) - tableContainer.height(); + tableContainer.height((tableContainerIntendedHeight - tableContainerVPadding) + "px"); }; DataTableView.prototype.update = function(onDone) { - this._showRows(0, onDone); + this._showRows(0, onDone); }; DataTableView.prototype.render = function() { - var self = this; - - var oldTableDiv = this._div.find(".data-table-container"); - var scrollLeft = (oldTableDiv.length > 0) ? oldTableDiv[0].scrollLeft : 0; - - var html = $( - '
    ' + - '
    Show as: ' + - '' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '' - ); - var elmts = DOM.bind(html); - - ui.summaryBar.updateResultCount(); - - var renderBrowsingModeLink = function(label, value) { - var a = $('') - .addClass("viewPanel-browsingModes-mode") - .text(label) - .appendTo(elmts.modeSelectors); - - if (value == ui.browsingEngine.getMode()) { - a.addClass("selected"); - } else { - a.addClass("action").click(function(evt) { - ui.browsingEngine.setMode(value); - }); - } - }; - renderBrowsingModeLink("rows", "row-based"); - renderBrowsingModeLink("records", "record-based"); - - this._renderPagingControls(elmts.pageSizeControls, elmts.pagingControls); - - if (this._sorting.criteria.length > 0) { - this._renderSortingControls(elmts.sortingControls); + var self = this; + + var oldTableDiv = this._div.find(".data-table-container"); + var scrollLeft = (oldTableDiv.length > 0) ? oldTableDiv[0].scrollLeft : 0; + + var html = $( + '
    ' + + '
    Show as: ' + + '' + + '
    ' + + '
    ' + + '
    ' + + '
    ' + + '
    ' + + '' + ); + var elmts = DOM.bind(html); + + ui.summaryBar.updateResultCount(); + + var renderBrowsingModeLink = function(label, value) { + var a = $('') + .addClass("viewPanel-browsingModes-mode") + .text(label) + .appendTo(elmts.modeSelectors); + + if (value == ui.browsingEngine.getMode()) { + a.addClass("selected"); + } else { + a.addClass("action").click(function(evt) { + ui.browsingEngine.setMode(value); + }); } - - this._renderDataTable(elmts.table[0]); - - this._div.empty().append(html); - this.resize(); - - elmts.dataTableContainer[0].scrollLeft = scrollLeft; + }; + renderBrowsingModeLink("rows", "row-based"); + renderBrowsingModeLink("records", "record-based"); + + this._renderPagingControls(elmts.pageSizeControls, elmts.pagingControls); + + if (this._sorting.criteria.length > 0) { + this._renderSortingControls(elmts.sortingControls); + } + + this._renderDataTable(elmts.table[0]); + + this._div.empty().append(html); + this.resize(); + + elmts.dataTableContainer[0].scrollLeft = scrollLeft; }; DataTableView.prototype._renderSortingControls = function(sortingControls) { - var self = this; - - $('') - .addClass("action") - .text("Sort ") - .append($('').attr("src", "/images/down-arrow.png")) - .appendTo(sortingControls) - .click(function() { - self._createSortingMenu(this); - }); + var self = this; + + $('') + .addClass("action") + .text("Sort ") + .append($('').attr("src", "/images/down-arrow.png")) + .appendTo(sortingControls) + .click(function() { + self._createSortingMenu(this); + }); }; DataTableView.prototype._renderPagingControls = function(pageSizeControls, pagingControls) { - var self = this; - - var from = (theProject.rowModel.start + 1); - var to = Math.min(theProject.rowModel.filtered, theProject.rowModel.start + theProject.rowModel.limit); - - var firstPage = $('« first').appendTo(pagingControls); - var previousPage = $('‹ previous').appendTo(pagingControls); - if (theProject.rowModel.start > 0) { - firstPage.addClass("action").click(function(evt) { self._onClickFirstPage(this, evt); }); - previousPage.addClass("action").click(function(evt) { self._onClickPreviousPage(this, evt); }); - } else { - firstPage.addClass("inaction"); - previousPage.addClass("inaction"); - } - - $('').addClass("viewpanel-pagingcount").html(" " + from + " - " + to + " ").appendTo(pagingControls); - - var nextPage = $('next ›').appendTo(pagingControls); - var lastPage = $('last »').appendTo(pagingControls); - if (theProject.rowModel.start + theProject.rowModel.limit < theProject.rowModel.filtered) { - nextPage.addClass("action").click(function(evt) { self._onClickNextPage(this, evt); }); - lastPage.addClass("action").click(function(evt) { self._onClickLastPage(this, evt); }); - } else { - nextPage.addClass("inaction"); - lastPage.addClass("inaction"); - } - - $('Show: ').appendTo(pageSizeControls); - var sizes = [ 5, 10, 25, 50 ]; - var renderPageSize = function(index) { - var pageSize = sizes[index]; - var a = $('') - .addClass("viewPanel-pagingControls-page") - .appendTo(pageSizeControls); - if (pageSize == self._pageSize) { - a.text(pageSize).addClass("selected"); - } else { - a.text(pageSize).addClass("action").click(function(evt) { - self._pageSize = pageSize; - self.update(); - }); - } - }; - for (var i = 0; i < sizes.length; i++) { - renderPageSize(i); - } + var self = this; - $('') - .text(theProject.rowModel.mode == "record-based" ? ' records' : ' rows') - .appendTo(pageSizeControls); + var from = (theProject.rowModel.start + 1); + var to = Math.min(theProject.rowModel.filtered, theProject.rowModel.start + theProject.rowModel.limit); + + var firstPage = $('« first').appendTo(pagingControls); + var previousPage = $('‹ previous').appendTo(pagingControls); + if (theProject.rowModel.start > 0) { + firstPage.addClass("action").click(function(evt) { self._onClickFirstPage(this, evt); }); + previousPage.addClass("action").click(function(evt) { self._onClickPreviousPage(this, evt); }); + } else { + firstPage.addClass("inaction"); + previousPage.addClass("inaction"); + } + + $('').addClass("viewpanel-pagingcount").html(" " + from + " - " + to + " ").appendTo(pagingControls); + + var nextPage = $('next ›').appendTo(pagingControls); + var lastPage = $('last »').appendTo(pagingControls); + if (theProject.rowModel.start + theProject.rowModel.limit < theProject.rowModel.filtered) { + nextPage.addClass("action").click(function(evt) { self._onClickNextPage(this, evt); }); + lastPage.addClass("action").click(function(evt) { self._onClickLastPage(this, evt); }); + } else { + nextPage.addClass("inaction"); + lastPage.addClass("inaction"); + } + + $('Show: ').appendTo(pageSizeControls); + var sizes = [ 5, 10, 25, 50 ]; + var renderPageSize = function(index) { + var pageSize = sizes[index]; + var a = $('') + .addClass("viewPanel-pagingControls-page") + .appendTo(pageSizeControls); + if (pageSize == self._pageSize) { + a.text(pageSize).addClass("selected"); + } else { + a.text(pageSize).addClass("action").click(function(evt) { + self._pageSize = pageSize; + self.update(); + }); + } + }; + for (var i = 0; i < sizes.length; i++) { + renderPageSize(i); + } + + $('') + .text(theProject.rowModel.mode == "record-based" ? ' records' : ' rows') + .appendTo(pageSizeControls); }; DataTableView.prototype._renderDataTable = function(table) { - var self = this; - - var columns = theProject.columnModel.columns; - var columnGroups = theProject.columnModel.columnGroups; - - /*------------------------------------------------------------ - * Column Group Headers - *------------------------------------------------------------ - */ - - var renderColumnKeys = function(keys) { - if (keys.length > 0) { - var tr = table.insertRow(table.rows.length); - tr.insertCell(0); // star - tr.insertCell(1); // flag - tr.insertCell(2); // row index - - for (var c = 0; c < columns.length; c++) { - var td = tr.insertCell(tr.cells.length); - - for (var k = 0; k < keys.length; k++) { - if (c == keys[k]) { - $('').attr("src", "images/down-arrow.png").appendTo(td); - break; - } - } - } - } - }; - - var renderColumnGroups = function(groups, keys) { - var nextLayer = []; - - if (groups.length > 0) { - var tr = table.insertRow(table.rows.length); - tr.insertCell(0); // star - tr.insertCell(1); // flag - tr.insertCell(2); // row index - - for (var c = 0; c < columns.length; c++) { - var foundGroup = false; - var columnGroup; - - for (var g = 0; g < groups.length; g++) { - columnGroup = groups[g]; - if (columnGroup.startColumnIndex == c) { - foundGroup = true; - break; - } - } - - var td = tr.insertCell(tr.cells.length); - if (foundGroup) { - td.setAttribute("colspan", columnGroup.columnSpan); - td.style.background = "#FF6A00"; - - if (columnGroup.keyColumnIndex >= 0) { - keys.push(columnGroup.keyColumnIndex); - } - - c += (columnGroup.columnSpan - 1); - - if ("subgroups" in columnGroup) { - nextLayer = nextLayer.concat(columnGroup.subgroups); - } - } - } - } - - renderColumnKeys(keys); - - if (nextLayer.length > 0) { - renderColumnGroups(nextLayer, []); - } - }; - - if (columnGroups.length > 0) { - renderColumnGroups( - columnGroups, - [ theProject.columnModel.keyCellIndex ] - ); - } - - /*------------------------------------------------------------ - * Column Headers with Menus - *------------------------------------------------------------ - */ + var self = this; - var trHead = table.insertRow(table.rows.length); - DOM.bind( - $(trHead.insertCell(trHead.cells.length)) - .attr("colspan", "3") - .addClass("column-header") - .html('
    All
    ') - ).dropdownMenu.click(function() { - self._createMenuForAllColumns(this); + var columns = theProject.columnModel.columns; + var columnGroups = theProject.columnModel.columnGroups; + + /*------------------------------------------------------------ + * Column Group Headers + *------------------------------------------------------------ + */ + + var renderColumnKeys = function(keys) { + if (keys.length > 0) { + var tr = table.insertRow(table.rows.length); + tr.insertCell(0); // star + tr.insertCell(1); // flag + tr.insertCell(2); // row index + + for (var c = 0; c < columns.length; c++) { + var td = tr.insertCell(tr.cells.length); + + for (var k = 0; k < keys.length; k++) { + if (c == keys[k]) { + $('').attr("src", "images/down-arrow.png").appendTo(td); + break; + } + } + } + } + }; + + var renderColumnGroups = function(groups, keys) { + var nextLayer = []; + + if (groups.length > 0) { + var tr = table.insertRow(table.rows.length); + tr.insertCell(0); // star + tr.insertCell(1); // flag + tr.insertCell(2); // row index + + for (var c = 0; c < columns.length; c++) { + var foundGroup = false; + var columnGroup; + + for (var g = 0; g < groups.length; g++) { + columnGroup = groups[g]; + if (columnGroup.startColumnIndex == c) { + foundGroup = true; + break; + } + } + + var td = tr.insertCell(tr.cells.length); + if (foundGroup) { + td.setAttribute("colspan", columnGroup.columnSpan); + td.style.background = "#FF6A00"; + + if (columnGroup.keyColumnIndex >= 0) { + keys.push(columnGroup.keyColumnIndex); + } + + c += (columnGroup.columnSpan - 1); + + if ("subgroups" in columnGroup) { + nextLayer = nextLayer.concat(columnGroup.subgroups); + } + } + } + } + + renderColumnKeys(keys); + + if (nextLayer.length > 0) { + renderColumnGroups(nextLayer, []); + } + }; + + if (columnGroups.length > 0) { + renderColumnGroups( + columnGroups, + [ theProject.columnModel.keyCellIndex ] + ); + } + + /*------------------------------------------------------------ + * Column Headers with Menus + *------------------------------------------------------------ + */ + + var trHead = table.insertRow(table.rows.length); + DOM.bind( + $(trHead.insertCell(trHead.cells.length)) + .attr("colspan", "3") + .addClass("column-header") + .html('
    All
    ') + ).dropdownMenu.click(function() { + self._createMenuForAllColumns(this); + }); + this._columnHeaderUIs = []; + var createColumnHeader = function(column, index) { + var td = trHead.insertCell(trHead.cells.length); + $(td).addClass("column-header"); + if (column.name in self._collapsedColumnNames) { + $(td).html(" ").attr("title", column.name).click(function(evt) { + delete self._collapsedColumnNames[column.name]; + self.render(); + }); + } else { + var columnHeaderUI = new DataTableColumnHeaderUI(self, column, index, td); + self._columnHeaderUIs.push(columnHeaderUI); + } + }; + + for (var i = 0; i < columns.length; i++) { + createColumnHeader(columns[i], i); + } + + /*------------------------------------------------------------ + * Data Cells + *------------------------------------------------------------ + */ + + var rows = theProject.rowModel.rows; + var renderRow = function(tr, r, row, even) { + $(tr).empty(); + + var cells = row.cells; + + var tdStar = tr.insertCell(tr.cells.length); + var star = $(' ') + .addClass(row.starred ? "data-table-star-on" : "data-table-star-off") + .appendTo(tdStar) + .click(function() { + var newStarred = !row.starred; + + Refine.postCoreProcess( + "annotate-one-row", + { row: row.i, starred: newStarred }, + null, + {}, + { + onDone: function(o) { + row.starred = newStarred; + renderRow(tr, r, row, even); + } + }, + "json" + ); }); - this._columnHeaderUIs = []; - var createColumnHeader = function(column, index) { - var td = trHead.insertCell(trHead.cells.length); - $(td).addClass("column-header"); - if (column.name in self._collapsedColumnNames) { - $(td).html(" ").attr("title", column.name).click(function(evt) { - delete self._collapsedColumnNames[column.name]; - self.render(); - }); - } else { - var columnHeaderUI = new DataTableColumnHeaderUI(self, column, index, td); - self._columnHeaderUIs.push(columnHeaderUI); - } - }; - + + var tdFlag = tr.insertCell(tr.cells.length); + var flag = $(' ') + .addClass(row.flagged ? "data-table-flag-on" : "data-table-flag-off") + .appendTo(tdFlag) + .click(function() { + var newFlagged = !row.flagged; + + Refine.postCoreProcess( + "annotate-one-row", + { row: row.i, flagged: newFlagged }, + null, + {}, + { + onDone: function(o) { + row.flagged = newFlagged; + renderRow(tr, r, row, even); + } + }, + "json" + ); + }); + + var tdIndex = tr.insertCell(tr.cells.length); + if (theProject.rowModel.mode == "record-based") { + if ("j" in row) { + $(tr).addClass("record"); + $('
    ').html((row.j + 1) + ".").appendTo(tdIndex); + } else { + $('
    ').html(" ").appendTo(tdIndex); + } + } else { + $('
    ').html((row.i + 1) + ".").appendTo(tdIndex); + } + + $(tr).addClass(even ? "even" : "odd"); + for (var i = 0; i < columns.length; i++) { - createColumnHeader(columns[i], i); + var column = columns[i]; + var td = tr.insertCell(tr.cells.length); + if (column.name in self._collapsedColumnNames) { + td.innerHTML = " "; + } else { + var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; + new DataTableCellUI(self, cell, row.i, column.cellIndex, td); + } } - - /*------------------------------------------------------------ - * Data Cells - *------------------------------------------------------------ - */ - - var rows = theProject.rowModel.rows; - var renderRow = function(tr, r, row, even) { - $(tr).empty(); - - var cells = row.cells; - - var tdStar = tr.insertCell(tr.cells.length); - var star = $(' ') - .addClass(row.starred ? "data-table-star-on" : "data-table-star-off") - .appendTo(tdStar) - .click(function() { - var newStarred = !row.starred; - - Refine.postCoreProcess( - "annotate-one-row", - { row: row.i, starred: newStarred }, - null, - {}, - { onDone: function(o) { - row.starred = newStarred; - renderRow(tr, r, row, even); - } - }, - "json" - ); - }); + }; - var tdFlag = tr.insertCell(tr.cells.length); - var flag = $(' ') - .addClass(row.flagged ? "data-table-flag-on" : "data-table-flag-off") - .appendTo(tdFlag) - .click(function() { - var newFlagged = !row.flagged; - - Refine.postCoreProcess( - "annotate-one-row", - { row: row.i, flagged: newFlagged }, - null, - {}, - { onDone: function(o) { - row.flagged = newFlagged; - renderRow(tr, r, row, even); - } - }, - "json" - ); - }); - - var tdIndex = tr.insertCell(tr.cells.length); - if (theProject.rowModel.mode == "record-based") { - if ("j" in row) { - $(tr).addClass("record"); - $('
    ').html((row.j + 1) + ".").appendTo(tdIndex); - } else { - $('
    ').html(" ").appendTo(tdIndex); - } - } else { - $('
    ').html((row.i + 1) + ".").appendTo(tdIndex); - } - - $(tr).addClass(even ? "even" : "odd"); - - for (var i = 0; i < columns.length; i++) { - var column = columns[i]; - var td = tr.insertCell(tr.cells.length); - if (column.name in self._collapsedColumnNames) { - td.innerHTML = " "; - } else { - var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; - new DataTableCellUI(self, cell, row.i, column.cellIndex, td); - } - } - }; - - var even = true; - for (var r = 0; r < rows.length; r++) { - var row = rows[r]; - var tr = table.insertRow(table.rows.length); - if (theProject.rowModel.mode == "row-based" || "j" in row) { - even = !even; - } - renderRow(tr, r, row, even); + var even = true; + for (var r = 0; r < rows.length; r++) { + var row = rows[r]; + var tr = table.insertRow(table.rows.length); + if (theProject.rowModel.mode == "row-based" || "j" in row) { + even = !even; } + renderRow(tr, r, row, even); + } }; DataTableView.prototype._showRows = function(start, onDone) { - var self = this; - Refine.fetchRows(start, this._pageSize, function() { - self.render(); - - if (onDone) { - onDone(); - } - }, this._sorting); + var self = this; + Refine.fetchRows(start, this._pageSize, function() { + self.render(); + + if (onDone) { + onDone(); + } + }, this._sorting); }; DataTableView.prototype._onClickPreviousPage = function(elmt, evt) { - this._showRows(theProject.rowModel.start - this._pageSize); + this._showRows(theProject.rowModel.start - this._pageSize); }; DataTableView.prototype._onClickNextPage = function(elmt, evt) { - this._showRows(theProject.rowModel.start + this._pageSize); + this._showRows(theProject.rowModel.start + this._pageSize); }; DataTableView.prototype._onClickFirstPage = function(elmt, evt) { - this._showRows(0); + this._showRows(0); }; DataTableView.prototype._onClickLastPage = function(elmt, evt) { - this._showRows(Math.floor(theProject.rowModel.filtered / this._pageSize) * this._pageSize); + this._showRows(Math.floor(theProject.rowModel.filtered / this._pageSize) * this._pageSize); }; DataTableView.prototype._getSortingCriteriaCount = function() { - return this._sorting.criteria.length; + return this._sorting.criteria.length; }; DataTableView.prototype._sortedByColumn = function(columnName) { - for (var i = 0; i < this._sorting.criteria.length; i++) { - if (this._sorting.criteria[i].column == columnName) { - return true; - } + for (var i = 0; i < this._sorting.criteria.length; i++) { + if (this._sorting.criteria[i].column == columnName) { + return true; } - return false; + } + return false; }; DataTableView.prototype._getSortingCriterionForColumn = function(columnName) { - for (var i = 0; i < this._sorting.criteria.length; i++) { - if (this._sorting.criteria[i].column == columnName) { - return this._sorting.criteria[i]; - } + for (var i = 0; i < this._sorting.criteria.length; i++) { + if (this._sorting.criteria[i].column == columnName) { + return this._sorting.criteria[i]; } - return null; + } + return null; }; DataTableView.prototype._removeSortingCriterionOfColumn = function(columnName) { - for (var i = 0; i < this._sorting.criteria.length; i++) { - if (this._sorting.criteria[i].column == columnName) { - this._sorting.criteria.splice(i, 1); - break; - } + for (var i = 0; i < this._sorting.criteria.length; i++) { + if (this._sorting.criteria[i].column == columnName) { + this._sorting.criteria.splice(i, 1); + break; } - this.update(); + } + this.update(); }; DataTableView.prototype._addSortingCriterion = function(criterion, alone) { - if (alone) { - this._sorting.criteria = []; - } else { - for (var i = 0; i < this._sorting.criteria.length; i++) { - if (this._sorting.criteria[i].column == criterion.column) { - this._sorting.criteria[i] = criterion; - this.update(); - return; - } - } + if (alone) { + this._sorting.criteria = []; + } else { + for (var i = 0; i < this._sorting.criteria.length; i++) { + if (this._sorting.criteria[i].column == criterion.column) { + this._sorting.criteria[i] = criterion; + this.update(); + return; + } } - this._sorting.criteria.push(criterion); - this.update(); + } + this._sorting.criteria.push(criterion); + this.update(); }; DataTableView.prototype._createMenuForAllColumns = function(elmt) { - var self = this; - var menu = [ - { label: "Facet", - id: "core/facets", - width: "200px", - submenu: [ - { - label: "Facet by star", - id: "core/facet-by-star", - click: function() { - ui.browsingEngine.addFacet( - "list", - { - "name" : "Starred Rows", - "columnName" : "", - "expression" : "row.starred" - }, - { - "scroll" : false - } - ); - } - }, - { - label: "Facet by flag", - id: "core/facet-by-flag", - click: function() { - ui.browsingEngine.addFacet( - "list", - { - "name" : "Flagged Rows", - "columnName" : "", - "expression" : "row.flagged" - }, - { - "scroll" : false - } - ); - } - } - ] + var self = this; + var menu = [ + { + label: "Facet", + id: "core/facets", + width: "200px", + submenu: [ + { + label: "Facet by star", + id: "core/facet-by-star", + click: function() { + ui.browsingEngine.addFacet( + "list", + { + "name" : "Starred Rows", + "columnName" : "", + "expression" : "row.starred" + }, + { + "scroll" : false + } + ); + } }, - {}, - { label: "Edit rows", - id: "core/edit-rows", - width: "200px", - submenu: [ - { - label: "Star rows", - id: "core/star-rows", - click: function() { - Refine.postCoreProcess("annotate-rows", { "starred" : "true" }, null, { rowMetadataChanged: true }); - } - }, - { - label: "Unstar rows", - id: "core/unstar-rows", - click: function() { - Refine.postCoreProcess("annotate-rows", { "starred" : "false" }, null, { rowMetadataChanged: true }); - } - }, - {}, - { - label: "Flag rows", - id: "core/flag-rows", - click: function() { - Refine.postCoreProcess("annotate-rows", { "flagged" : "true" }, null, { rowMetadataChanged: true }); - } - }, - { - label: "Unflag rows", - id: "core/unflag-rows", - click: function() { - Refine.postCoreProcess("annotate-rows", { "flagged" : "false" }, null, { rowMetadataChanged: true }); - } - }, - {}, - { - label: "Remove all matching rows", - id: "core/remove-rows", - click: function() { - Refine.postCoreProcess("remove-rows", {}, null, { rowMetadataChanged: true }); - } - } - ] - }, - { label: "Edit columns", - id: "core/edit-columns", - width: "200px", - submenu: [ - { - label: "Reorder columns...", - id: "core/reorder-columns", - click: function() { - new ColumnReorderingDialog(); - } - } - ] - }, - {}, - { label: "View", - id: "core/view", - width: "200px", - submenu: [ - { - label: "Collapse all columns", - id: "core/collapse-all-columns", - click: function() { - for (var i = 0; i < theProject.columnModel.columns.length; i++) { - self._collapsedColumnNames[theProject.columnModel.columns[i].name] = true; - } - self.render(); - } - }, - { - label: "Expand all columns", - id: "core/expand-all-columns", - click: function() { - self._collapsedColumnNames = []; - self.render(); - } - } - ] + { + label: "Facet by flag", + id: "core/facet-by-flag", + click: function() { + ui.browsingEngine.addFacet( + "list", + { + "name" : "Flagged Rows", + "columnName" : "", + "expression" : "row.flagged" + }, + { + "scroll" : false + } + ); + } } - ]; - - for (var i = 0; i < DataTableView._extenders.length; i++) { - DataTableView._extenders[i].call(null, this, menu); + ] + }, + {}, + { + label: "Edit rows", + id: "core/edit-rows", + width: "200px", + submenu: [ + { + label: "Star rows", + id: "core/star-rows", + click: function() { + Refine.postCoreProcess("annotate-rows", { "starred" : "true" }, null, { rowMetadataChanged: true }); + } + }, + { + label: "Unstar rows", + id: "core/unstar-rows", + click: function() { + Refine.postCoreProcess("annotate-rows", { "starred" : "false" }, null, { rowMetadataChanged: true }); + } + }, + {}, + { + label: "Flag rows", + id: "core/flag-rows", + click: function() { + Refine.postCoreProcess("annotate-rows", { "flagged" : "true" }, null, { rowMetadataChanged: true }); + } + }, + { + label: "Unflag rows", + id: "core/unflag-rows", + click: function() { + Refine.postCoreProcess("annotate-rows", { "flagged" : "false" }, null, { rowMetadataChanged: true }); + } + }, + {}, + { + label: "Remove all matching rows", + id: "core/remove-rows", + click: function() { + Refine.postCoreProcess("remove-rows", {}, null, { rowMetadataChanged: true }); + } + } + ] + }, + { + label: "Edit columns", + id: "core/edit-columns", + width: "200px", + submenu: [ + { + label: "Reorder columns...", + id: "core/reorder-columns", + click: function() { + new ColumnReorderingDialog(); + } + } + ] + }, + {}, + { + label: "View", + id: "core/view", + width: "200px", + submenu: [ + { + label: "Collapse all columns", + id: "core/collapse-all-columns", + click: function() { + for (var i = 0; i < theProject.columnModel.columns.length; i++) { + self._collapsedColumnNames[theProject.columnModel.columns[i].name] = true; + } + self.render(); + } + }, + { + label: "Expand all columns", + id: "core/expand-all-columns", + click: function() { + self._collapsedColumnNames = []; + self.render(); + } + } + ] } - - MenuSystem.createAndShowStandardMenu(menu, elmt, { width: "120px", horizontal: false }); + ]; + + for (var i = 0; i < DataTableView._extenders.length; i++) { + DataTableView._extenders[i].call(null, this, menu); + } + + MenuSystem.createAndShowStandardMenu(menu, elmt, { width: "120px", horizontal: false }); }; DataTableView.prototype._createSortingMenu = function(elmt) { - var self = this; - var items = [ - { - "label" : "Remove sort", - "click" : function() { - self._sorting.criteria = []; - self.update(); + var self = this; + var items = [ + { + "label" : "Remove sort", + "click" : function() { + self._sorting.criteria = []; + self.update(); + } + }, + { + "label" : "Reorder rows permanently", + "click" : function() { + Refine.postCoreProcess( + "reorder-rows", + null, + { "sorting" : JSON.stringify(self._sorting) }, + { rowMetadataChanged: true }, + { + onDone: function() { + self._sorting.criteria = []; } - }, - { - "label" : "Reorder rows permanently", - "click" : function() { - Refine.postCoreProcess( - "reorder-rows", - null, - { "sorting" : JSON.stringify(self._sorting) }, - { rowMetadataChanged: true }, - { - onDone: function() { - self._sorting.criteria = []; - } - } - ); - } - }, - {} - ]; - - var getColumnHeaderUI = function(columnName) { - for (var i = 0; i < self._columnHeaderUIs.length; i++) { - var columnHeaderUI = self._columnHeaderUIs[i]; - if (columnHeaderUI.getColumn().name == columnName) { - return columnHeaderUI; - } - } - return null; + } + ); + } + }, + {} + ]; + + var getColumnHeaderUI = function(columnName) { + for (var i = 0; i < self._columnHeaderUIs.length; i++) { + var columnHeaderUI = self._columnHeaderUIs[i]; + if (columnHeaderUI.getColumn().name == columnName) { + return columnHeaderUI; + } } - var createSubmenu = function(criterion) { - var columnHeaderUI = getColumnHeaderUI(criterion.column); - if (columnHeaderUI != null) { - items.push({ - "label" : "By " + criterion.column, - "submenu" : columnHeaderUI.createSortingMenu() - }) - } - }; - for (var i = 0; i < this._sorting.criteria.length; i++) { - createSubmenu(this._sorting.criteria[i]); + return null; + } + var createSubmenu = function(criterion) { + var columnHeaderUI = getColumnHeaderUI(criterion.column); + if (columnHeaderUI != null) { + items.push({ + "label" : "By " + criterion.column, + "submenu" : columnHeaderUI.createSortingMenu() + }) } - - MenuSystem.createAndShowStandardMenu(items, elmt, { horizontal: false }); + }; + for (var i = 0; i < this._sorting.criteria.length; i++) { + createSubmenu(this._sorting.criteria[i]); + } + + MenuSystem.createAndShowStandardMenu(items, elmt, { horizontal: false }); }; DataTableView.prototype._updateCell = function(rowIndex, cellIndex, cell) { - var rows = theProject.rowModel.rows; - for (var r = 0; r < rows.length; r++) { - var row = rows[r]; - if (row.i === rowIndex) { - while (cellIndex >= row.cells.length) { - row.cells.push(null); - } - row.cells[cellIndex] = cell; - break; - } + var rows = theProject.rowModel.rows; + for (var r = 0; r < rows.length; r++) { + var row = rows[r]; + if (row.i === rowIndex) { + while (cellIndex >= row.cells.length) { + row.cells.push(null); + } + row.cells[cellIndex] = cell; + break; } + } }; DataTableView.sampleVisibleRows = function(column) { - var rowIndices = []; - var values = []; - - var rows = theProject.rowModel.rows; - for (var r = 0; r < rows.length; r++) { - var row = rows[r]; - - rowIndices.push(row.i); - - var v = null; - if (column && column.cellIndex < row.cells.length) { - var cell = row.cells[column.cellIndex]; - if (cell !== null) { - v = cell.v; - } - } - values.push(v); + var rowIndices = []; + var values = []; + + var rows = theProject.rowModel.rows; + for (var r = 0; r < rows.length; r++) { + var row = rows[r]; + + rowIndices.push(row.i); + + var v = null; + if (column && column.cellIndex < row.cells.length) { + var cell = row.cells[column.cellIndex]; + if (cell !== null) { + v = cell.v; + } } - - return { - rowIndices: rowIndices, - values: values - }; + values.push(v); + } + + return { + rowIndices: rowIndices, + values: values + }; }; DataTableView.promptExpressionOnVisibleRows = function(column, title, expression, onDone) { - var o = DataTableView.sampleVisibleRows(column); - - var self = this; - new ExpressionPreviewDialog( - title, - column.cellIndex, - o.rowIndices, - o.values, - expression, - onDone - ); + var o = DataTableView.sampleVisibleRows(column); + + var self = this; + new ExpressionPreviewDialog( + title, + column.cellIndex, + o.rowIndices, + o.values, + expression, + onDone + ); }; diff --git a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js index ba0a00ea0..00a9d4958 100644 --- a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js +++ b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,318 +29,319 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) { - var doTextTransform = function(expression, onError, repeat, repeatCount) { - Refine.postCoreProcess( - "text-transform", - { - columnName: column.name, - expression: expression, - onError: onError, - repeat: repeat, - repeatCount: repeatCount - }, - null, - { cellsChanged: true } - ); + var doTextTransform = function(expression, onError, repeat, repeatCount) { + Refine.postCoreProcess( + "text-transform", + { + columnName: column.name, + expression: expression, + onError: onError, + repeat: repeat, + repeatCount: repeatCount + }, + null, + { cellsChanged: true } + ); + }; + + var doTextTransformPrompt = function() { + var frame = $( + DOM.loadHTML("core", "scripts/views/data-table/text-transform-dialog.html") + .replace("$EXPRESSION_PREVIEW_WIDGET$", ExpressionPreviewDialog.generateWidgetHtml())); + + var elmts = DOM.bind(frame); + elmts.dialogHeader.text("Custom text transform on column " + column.name); + + var level = DialogSystem.showDialog(frame); + var dismiss = function() { DialogSystem.dismissUntil(level - 1); }; + + elmts.cancelButton.click(dismiss); + elmts.okButton.click(function() { + doTextTransform( + previewWidget.getExpression(true), + $('input[name="text-transform-dialog-onerror-choice"]:checked')[0].value, + elmts.repeatCheckbox[0].checked, + elmts.repeatCountInput[0].value + ); + dismiss(); + }); + + var o = DataTableView.sampleVisibleRows(column); + var previewWidget = new ExpressionPreviewDialog.Widget( + elmts, + column.cellIndex, + o.rowIndices, + o.values, + null + ); + previewWidget._prepareUpdate = function(params) { + params.repeat = elmts.repeatCheckbox[0].checked; + params.repeatCount = elmts.repeatCountInput[0].value; }; - - var doTextTransformPrompt = function() { - var frame = $( - DOM.loadHTML("core", "scripts/views/data-table/text-transform-dialog.html") - .replace("$EXPRESSION_PREVIEW_WIDGET$", ExpressionPreviewDialog.generateWidgetHtml())); + elmts.repeatCheckbox.click(function() { + previewWidget.update(); + }); + }; - var elmts = DOM.bind(frame); - elmts.dialogHeader.text("Custom text transform on column " + column.name); + var doFillDown = function() { + Refine.postCoreProcess( + "fill-down", + { + columnName: column.name + }, + null, + { modelsChanged: true } + ); + }; - var level = DialogSystem.showDialog(frame); - var dismiss = function() { DialogSystem.dismissUntil(level - 1); }; + var doBlankDown = function() { + Refine.postCoreProcess( + "blank-down", + { + columnName: column.name + }, + null, + { modelsChanged: true } + ); + }; - elmts.cancelButton.click(dismiss); - elmts.okButton.click(function() { - doTextTransform( - previewWidget.getExpression(true), - $('input[name="text-transform-dialog-onerror-choice"]:checked')[0].value, - elmts.repeatCheckbox[0].checked, - elmts.repeatCountInput[0].value - ); - dismiss(); - }); - - var o = DataTableView.sampleVisibleRows(column); - var previewWidget = new ExpressionPreviewDialog.Widget( - elmts, - column.cellIndex, - o.rowIndices, - o.values, - null - ); - previewWidget._prepareUpdate = function(params) { - params.repeat = elmts.repeatCheckbox[0].checked; - params.repeatCount = elmts.repeatCountInput[0].value; - }; - elmts.repeatCheckbox.click(function() { - previewWidget.update(); - }); - }; - - var doFillDown = function() { - Refine.postCoreProcess( - "fill-down", - { - columnName: column.name - }, - null, - { modelsChanged: true } - ); - }; - - var doBlankDown = function() { - Refine.postCoreProcess( - "blank-down", - { - columnName: column.name - }, - null, - { modelsChanged: true } - ); - }; - - var doJoinMultiValueCells = function() { - var separator = window.prompt("Enter separator to use between values", ", "); - if (separator !== null) { - Refine.postCoreProcess( - "join-multi-value-cells", - { - columnName: column.name, - keyColumnName: theProject.columnModel.keyColumnName, - separator: separator - }, - null, - { rowsChanged: true } - ); - } - }; - - var doSplitMultiValueCells = function() { - var separator = window.prompt("What separator currently separates the values?", ","); - if (separator !== null) { - Refine.postCoreProcess( - "split-multi-value-cells", - { - columnName: column.name, - keyColumnName: theProject.columnModel.keyColumnName, - separator: separator, - mode: "plain" - }, - null, - { rowsChanged: true } - ); - } - }; - - MenuSystem.appendTo(menu, [ "core/edit-cells" ], [ + var doJoinMultiValueCells = function() { + var separator = window.prompt("Enter separator to use between values", ", "); + if (separator !== null) { + Refine.postCoreProcess( + "join-multi-value-cells", { - id: "core/text-transform", - label: "Transform...", - click: function() { doTextTransformPrompt(); } + columnName: column.name, + keyColumnName: theProject.columnModel.keyColumnName, + separator: separator + }, + null, + { rowsChanged: true } + ); + } + }; + + var doSplitMultiValueCells = function() { + var separator = window.prompt("What separator currently separates the values?", ","); + if (separator !== null) { + Refine.postCoreProcess( + "split-multi-value-cells", + { + columnName: column.name, + keyColumnName: theProject.columnModel.keyColumnName, + separator: separator, + mode: "plain" + }, + null, + { rowsChanged: true } + ); + } + }; + + MenuSystem.appendTo(menu, [ "core/edit-cells" ], [ + { + id: "core/text-transform", + label: "Transform...", + click: function() { doTextTransformPrompt(); } + }, + { + id: "core/common-transforms", + label: "Common transforms", + submenu: [ + { + id: "core/trim-whitespace", + label: "Trim leading and trailing whitespace", + click: function() { doTextTransform("value.trim()", "store-blank", false, ""); } }, { - id: "core/common-transforms", - label: "Common transforms", - submenu: [ - { - id: "core/trim-whitespace", - label: "Trim leading and trailing whitespace", - click: function() { doTextTransform("value.trim()", "store-blank", false, ""); } - }, - { - id: "core/collapse-whitespace", - label: "Collapse consecutive whitespace", - click: function() { doTextTransform("value.replace(/\\s+/,' ')", "store-blank", false, ""); } - }, - {}, - { - id: "core/unescape-html-entities", - label: "Unescape HTML entities", - click: function() { doTextTransform("value.unescape('html')", "store-blank", true, 10); } - }, - {}, - { - id: "core/to-titlecase", - label: "To titlecase", - click: function() { doTextTransform("value.toTitlecase()", "store-blank", false, ""); } - }, - { - id: "core/to-uppercase", - label: "To uppercase", - click: function() { doTextTransform("value.toUppercase()", "store-blank", false, ""); } - }, - { - id: "core/to-lowercase", - label: "To lowercase", - click: function() { doTextTransform("value.toLowercase()", "store-blank", false, ""); } - }, - {}, - { - id: "core/to-number", - label: "To number", - click: function() { doTextTransform("value.toNumber()", "store-blank", false, ""); } - }, - { - id: "core/to-date", - label: "To date", - click: function() { doTextTransform("value.toDate()", "store-blank", false, ""); } - }, - { - id: "core/to-text", - label: "To text", - click: function() { doTextTransform("value.toString()", "store-blank", false, ""); } - }, - {}, - { - id: "core/to-blank", - label: "Blank out cells", - click: function() { doTextTransform("null", "store-blank", false, ""); } - } - ] + id: "core/collapse-whitespace", + label: "Collapse consecutive whitespace", + click: function() { doTextTransform("value.replace(/\\s+/,' ')", "store-blank", false, ""); } }, {}, { - id: "core/fill-down", - label: "Fill down", - click: doFillDown - }, - { - id: "core/blank-down", - label: "Blank down", - click: doBlankDown + id: "core/unescape-html-entities", + label: "Unescape HTML entities", + click: function() { doTextTransform("value.unescape('html')", "store-blank", true, 10); } }, {}, { - id: "core/split-multi-valued-cells", - label: "Split multi-valued cells...", - click: doSplitMultiValueCells + id: "core/to-titlecase", + label: "To titlecase", + click: function() { doTextTransform("value.toTitlecase()", "store-blank", false, ""); } }, { - id: "core/join-multi-valued-cells", - label: "Join multi-valued cells...", - click: doJoinMultiValueCells + id: "core/to-uppercase", + label: "To uppercase", + click: function() { doTextTransform("value.toUppercase()", "store-blank", false, ""); } + }, + { + id: "core/to-lowercase", + label: "To lowercase", + click: function() { doTextTransform("value.toLowercase()", "store-blank", false, ""); } }, {}, { - id: "core/cluster", - label: "Cluster and edit...", - click: function() { new ClusteringDialog(column.name, "value"); } - } - ]); - - var doTransposeColumnsIntoRows = function() { - var dialog = $(DOM.loadHTML("core", "scripts/views/data-table/transpose-columns-into-rows.html")); - - var elmts = DOM.bind(dialog); - elmts.dialogHeader.text('Transpose Cells Across Columns into Rows'); - - var level = DialogSystem.showDialog(dialog); - var dismiss = function() { - DialogSystem.dismissUntil(level - 1); - }; - - var columns = theProject.columnModel.columns; - - elmts.cancelButton.click(function() { dismiss(); }); - elmts.okButton.click(function() { - var config = { - startColumnName: elmts.fromColumnSelect[0].value, - columnCount: elmts.toColumnSelect[0].value, - combinedColumnName: $.trim(elmts.combinedColumnNameInput[0].value), - prependColumnName: elmts.prependColumnNameCheckbox[0].checked, - separator: elmts.separatorInput[0].value, - ignoreBlankCells: elmts.ignoreBlankCellsCheckbox[0].checked - }; - - Refine.postCoreProcess( - "transpose-columns-into-rows", - config, - null, - { modelsChanged: true } - ); - dismiss(); - }); - - for (var i = 0; i < columns.length; i++) { - var column2 = columns[i]; - var option = $('