/* Copyright 2011, Google Inc. All rights reserved. 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 notice, this list of conditions and the following disclaimer. * 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 contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 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. */ //Internationalization init var lang = navigator.language.split("-")[0] || navigator.userLanguage.split("-")[0]; var dictionary = ""; $.ajax({ url : "command/core/load-language?", type : "POST", async : false, data : { module : "gdata", // lang : lang }, success : function(data) { dictionary = data['dictionary']; lang = data['lang']; } }); $.i18n().load(dictionary, lang); // End internationalization Refine.GDataImportingController = function(createProjectUI) { this._createProjectUI = createProjectUI; this._parsingPanel = createProjectUI.addCustomPanel(); createProjectUI.addSourceSelectionUI({ label: "Google Data", id: "gdata-source", ui: new Refine.GDataSourceUI(this) }); $('#gdata-authorize').text($.i18n('gdata-auth/authorize-label')); $('#gdata-authorized').text($.i18n('gdata-auth/authorized-label')); }; Refine.CreateProjectUI.controllers.push(Refine.GDataImportingController); Refine.GDataImportingController.prototype.startImportingDocument = function(doc) { var dismiss = DialogSystem.showBusy($.i18n('gdata-import/preparing')); var self = this; Refine.postCSRF( "command/core/create-importing-job", null, function(data) { Refine.wrapCSRF(function(token) { $.post( "command/core/importing-controller?" + $.param({ "controller": "gdata/gdata-importing-controller", "subCommand": "initialize-parser-ui", "docUrl": doc.docSelfLink, "docType": doc.type, "csrf_token": token }), null, function(data2) { dismiss(); if (data2.status == 'ok') { self._doc = doc; self._jobID = data.jobID; self._options = data2.options; self._showParsingPanel(); } else { alert(data2.message); } }, "json" ); }); }, "json" ); }; Refine.GDataImportingController.prototype.getOptions = function() { var options = { docUrl: this._doc.docSelfLink, docType: this._doc.type, }; var parseIntDefault = function(s, def) { try { var n = parseInt(s); if (!isNaN(n)) { return n; } } catch (e) { // Ignore } return def; }; if (this._doc.type != 'table') { this._parsingPanelElmts.sheetRecordContainer.find('input').each(function() { if (this.checked) { options.sheetUrl = this.getAttribute('sheetUrl'); options.worksheetIndex = this.getAttribute('worksheetIndex'); } }); if (this._parsingPanelElmts.ignoreCheckbox[0].checked) { options.ignoreLines = parseIntDefault(this._parsingPanelElmts.ignoreInput[0].value, -1); } else { options.ignoreLines = -1; } if (this._parsingPanelElmts.headerLinesCheckbox[0].checked) { options.headerLines = parseIntDefault(this._parsingPanelElmts.headerLinesInput[0].value, 0); } else { options.headerLines = 0; } } if (this._parsingPanelElmts.skipCheckbox[0].checked) { options.skipDataLines = parseIntDefault(this._parsingPanelElmts.skipInput[0].value, 0); } else { options.skipDataLines = 0; } if (this._parsingPanelElmts.limitCheckbox[0].checked) { options.limit = parseIntDefault(this._parsingPanelElmts.limitInput[0].value, -1); } else { options.limit = -1; } options.storeBlankRows = this._parsingPanelElmts.storeBlankRowsCheckbox[0].checked; options.storeBlankCellsAsNulls = this._parsingPanelElmts.storeBlankCellsAsNullsCheckbox[0].checked; options.disableAutoPreview = this._parsingPanelElmts.disableAutoPreviewCheckbox[0].checked; return options; }; Refine.GDataImportingController.prototype._showParsingPanel = function() { var self = this; this._parsingPanel.unbind().empty().html( DOM.loadHTML("gdata", 'scripts/index/gdata-parsing-panel.html')); this._parsingPanelElmts = DOM.bind(this._parsingPanel); this._parsingPanelElmts.gdata_worksheet.html($.i18n('gdata-parsing/worksheet')); this._parsingPanelElmts.gdata_ignore_first.html($.i18n('gdata-parsing/ignore-first')); this._parsingPanelElmts.gdata_ignore.html($.i18n('gdata-parsing/ignore')); this._parsingPanelElmts.gdata_parse_next.html($.i18n('gdata-parsing/parse-next')); this._parsingPanelElmts.gdata_parse.html($.i18n('gdata-parsing/parse')); this._parsingPanelElmts.startOverButton.html($.i18n('gdata-parsing/start-over')); this._parsingPanelElmts.gdata_conf_pars.html($.i18n('gdata-parsing/conf-pars')); this._parsingPanelElmts.gdata_proj_name.html($.i18n('gdata-parsing/proj-name')); this._parsingPanelElmts.createProjectButton.html($.i18n('gdata-parsing/create-proj')); this._parsingPanelElmts.gdata_options.html($.i18n('gdata-parsing/option')); this._parsingPanelElmts.gdata_disable_auto_preview.text($.i18n('gdata-parsing/disable-auto-preview')); this._parsingPanelElmts.previewButton.html($.i18n('gdata-parsing/preview-button')); this._parsingPanelElmts.gdata_updating.html($.i18n('gdata-parsing/updating-preview')); this._parsingPanelElmts.gdata_discard_next.html($.i18n('gdata-parsing/discard-next')); this._parsingPanelElmts.gdata_discard.html($.i18n('gdata-parsing/discard')); this._parsingPanelElmts.gdata_limit_next.html($.i18n('gdata-parsing/limit-next')); this._parsingPanelElmts.gdata_limit.html($.i18n('gdata-parsing/limit')); this._parsingPanelElmts.gdata_store_row.html($.i18n('gdata-parsing/store-row')); this._parsingPanelElmts.gdata_store_cell.html($.i18n('gdata-parsing/store-cell')); if (this._parsingPanelResizer) { $(window).unbind('resize', this._parsingPanelResizer); } this._parsingPanelResizer = function() { var elmts = self._parsingPanelElmts; var width = self._parsingPanel.width(); var height = self._parsingPanel.height(); var headerHeight = elmts.wizardHeader.outerHeight(true); var controlPanelHeight = 250; 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(); this._parsingPanelElmts.startOverButton.click(function() { // explicitly cancel the import job Refine.CreateProjectUI.cancelImportingJob(self._jobID); delete self._doc; delete self._jobID; delete self._options; self._createProjectUI.showSourceSelectionPanel(); }); this._parsingPanelElmts.createProjectButton.click(function() { self._createProject(); }); this._parsingPanelElmts.previewButton.click(function() { self._updatePreview(); }); this._parsingPanelElmts.projectNameInput[0].value = this._doc.title; if (this._doc.type != 'table') { var sheetTable = this._parsingPanelElmts.sheetRecordContainer[0]; $.each(this._options.worksheets, function(i, v) { var id = 'gdata_worksheet-' + Math.round(Math.random() * 1000000); var tr = sheetTable.insertRow(sheetTable.rows.length); var td0 = $(tr.insertCell(0)).attr('width', '1%'); var checkbox = $('') .attr('id', id) .attr('type', 'radio') .attr('name', 'gdata-importing-parsing-worksheet') .attr('sheetUrl', this.link) .attr('worksheetIndex', this.worksheetIndex) .appendTo(td0); if (i === 0) { checkbox.prop("checked", true); } $('