markerMoveStream.onValue(function(latlng) { $streetViewContainer.show(); if (!container) { container = streetView.create({ streetViewElem: $streetViewContainer[0], noStreetViewText: options.config.trans.noStreetViewText, hideAddress: true, location: latlng }); } container.update(latlng); });
exports.init = function(options) { var $ecoBenefits = $(options.ecoBenefits), detailUrl = window.location.href; if (U.getLastUrlSegment(detailUrl) == 'edit') { detailUrl = U.removeLastUrlSegment(detailUrl); } // Set up cross-site forgery protection $.ajaxSetup(csrf.jqueryAjaxSetupOptions); var prompter = statePrompter.init({ warning: options.config.trans.exitWarning, question: options.config.trans.exitQuestion }); // Add threaded comments "reply" links var commentFormTempl = $("#template-comment").html(); $('a[data-comment-id]').click(function () { var $a = $(this); // Close other forms $(".comment-reply-form").remove(); var templ = $("#template-comment").html(); $a.closest(".comment").append(_.template(commentFormTempl, { parent: $a.data("comment-id"), classname: 'comment-reply-form' })); }); if (options.config.loggedIn) { $('#comments-container').append(_.template(commentFormTempl, { parent: '', classname: 'comment-create-form' })); } var imageFinishedStream = imageUploadPanel.init(options.imageUploadPanel); var shouldBeInEditModeBus = new Bacon.Bus(); var shouldBeInEditModeStream = shouldBeInEditModeBus.merge( $(window).asEventStream('popstate') .map(function() { return U.getLastUrlSegment() === 'edit'; })); var form = inlineEditForm.init( _.extend(options.inlineEditForm, { config: options.config, updateUrl: detailUrl, onSaveBefore: onSaveBefore, shouldBeInEditModeStream: shouldBeInEditModeStream, errorCallback: alerts.makeErrorCallback(options.config) })); var deleter = plotDelete.init({ config: options.config, delete: options.delete, deleteConfirm: options.deleteConfirm, deleteCancel: options.deleteCancel, deleteConfirmationBox: options.deleteConfirmationBox, treeIdColumn: options.treeIdColumn }); if (options.config.instance.supportsEcobenefits) { var updateEcoUrl = U.appendSegmentToUrl('eco', detailUrl); form.saveOkStream .map($ecoBenefits) .onValue('.load', updateEcoUrl); } var sidebarUpdate = form.saveOkStream.merge(imageFinishedStream), updateSidebarUrl = U.appendSegmentToUrl('sidebar', detailUrl); sidebarUpdate .map($(options.sidebar)) .onValue('.load', updateSidebarUrl); form.inEditModeProperty.onValue(function(inEditMode) { var hrefHasEdit = U.getLastUrlSegment() === 'edit'; if (inEditMode) { prompter.lock(); if (!hrefHasEdit) { History.replaceState(null, document.title, U.appendSegmentToUrl('edit')); } } else { prompter.unlock(); if (hrefHasEdit) { History.replaceState(null, document.title, U.removeLastUrlSegment()); } } }); if (options.startInEditMode) { if (options.config.loggedIn) { shouldBeInEditModeBus.push(true); } else { window.location = options.config.loginUrl + window.location.href; } } var mapManager = new MapManager(); mapManager.createTreeMap({ config: options.config, domId: 'map', disableScrollWithMouseWheel: true, centerWM: options.location.point, zoom: mapManager.ZOOM_PLOT }); plotMarker.init(options.config, mapManager.map); plotMarker.useTreeIcon(options.useTreeIcon); reverseGeocodeStreamAndUpdateAddressesOnForm( options.config, plotMarker.moveStream, options.form); var currentPlotMover = plotMover.init({ mapManager: mapManager, plotMarker: plotMarker, inlineEditForm: form, editLocationButton: options.location.edit, cancelEditLocationButton: options.location.cancel, location: options.location.point }); var detailUrlPrefix = U.removeLastUrlSegment(detailUrl), clickedIdStream = mapManager.map.utfEvents .map('.data.' + options.config.utfGrid.mapfeatureIdKey) .filter(BU.isDefinedNonEmpty); clickedIdStream .filter(BU.not, options.featureId) .map(_.partialRight(U.appendSegmentToUrl, detailUrlPrefix, false)) .onValue(_.bind(window.location.assign, window.location)); function onSaveBefore(data) { currentPlotMover.onSaveBefore(data); } if (options.config.instance.basemap.type === 'google') { var $streetViewContainer = $(options.streetView); $streetViewContainer.show(); var panorama = streetView.create({ streetViewElem: $streetViewContainer[0], noStreetViewText: options.config.trans.noStreetViewText, location: options.location.point }); form.saveOkStream .map('.formData') .map(BU.getValueForKey, 'plot.geom') .filter(BU.isDefined) .onValue(panorama.update); } return { inlineEditForm: form }; };
exports.init = function(options) { var $addTree = $(options.addTree), $noTreeMessage = $(options.noTreeMessage), $cancelAddTree = $(options.cancelAddTree), $addTreeSection = $(options.addTreeSection), $treeSection = $(options.treeSection), $ecoBenefits = $(options.ecoBenefits); // Set up cross-site forgery protection $.ajaxSetup(csrf.jqueryAjaxSetupOptions); otmTypeahead.bulkCreate(options.typeaheads); var prompter = statePrompter.init({ warning: options.config.exitWarning, question: options.config.exitQuestion }); // Add threaded comments "reply" links var commentFormTempl = $("#template-comment").html(); $('a[data-comment-id]').click(function () { var $a = $(this); // Close other forms $(".comment-reply-form").remove(); var templ = $("#template-comment").html(); $a.closest(".comment").append(_.template(commentFormTempl, { parent: $a.data("comment-id"), classname: 'comment-reply-form' })); }); if (options.config.loggedIn) { $('#comments-container').append(_.template(commentFormTempl, { parent: '', classname: 'comment-create-form' })); } var udfRowTemplate = _.template( '<tr data-value-id="">' + '<% _.each(fields, function (field) { %>' + '<td> <%= field %> </td>' + '<% }) %>' + '</tr>'); // Wire up collection udfs $('a[data-udf-id]').click(function() { var id = $(this).data('udf-id'); var fields = $('table[data-udf-id="' + id + '"] * [data-field-name]').toArray(); var data = _.map(fields, function(field) { if ($(field).attr('data-moment-date-format')) { return moment($(field).datepicker("getDate")).format($(field).attr('data-moment-date-format')); } else { return $(field).val(); } }); $(this).closest('table').append(udfRowTemplate({ fields: data })); }); $('[data-date-format]').datepicker(); var imageFinishedStream = imageUploadPanel.init(options.imageUploadPanel); var shouldBeInEditModeBus = new Bacon.Bus(); var shouldBeInEditModeStream = shouldBeInEditModeBus.merge( $(window).asEventStream('popstate') .map(function() { return U.getLastUrlSegment() === 'edit'; })); var form = inlineEditForm.init( _.extend(options.inlineEditForm, { config: options.config, onSaveBefore: onSaveBefore, shouldBeInEditModeStream: shouldBeInEditModeStream })); var deleter = plotDelete.init({ config: options.config, delete: options.delete, deleteConfirm: options.deleteConfirm, deleteCancel: options.deleteCancel, deleteConfirmationBox: options.deleteConfirmationBox, treeIdColumn: options.treeIdColumn }); if (options.config.instance.supportsEcobenefits) { form.saveOkStream .map($ecoBenefits) .onValue('.load', options.updateEcoUrl); } var sidebarUpdate = form.saveOkStream.merge(imageFinishedStream); sidebarUpdate .map($(options.sidebar)) .onValue('.load', options.updateSidebarUrl); var startInEditMode = options.startInEditMode; form.inEditModeProperty.onValue(function(inEditMode) { var hrefHasEdit = U.getLastUrlSegment() === 'edit'; if (inEditMode) { prompter.lock(); if (!hrefHasEdit) { History.replaceState(null, '', U.appendSegmentToUrl('edit')); } } else { prompter.unlock(); if (hrefHasEdit) { History.replaceState(null, '', U.removeLastUrlSegment()); } } }); if (startInEditMode) { if (options.config.loggedIn) { shouldBeInEditModeBus.push(true); showAddTree(); } else { window.location = options.config.loginUrl + window.location.href; } } mapManager.init({ config: options.config, selector: '#map', disableScrollWithMouseWheel: true, center: options.plotLocation.location, zoom: mapManager.ZOOM_PLOT }); plotMarker.init(options.config, mapManager.map); reverseGeocodeStreamAndUpdateAddressesOnForm( options.config, plotMarker.moveStream, '#plot-form'); var currentPlotMover = plotMover.init({ mapManager: mapManager, plotMarker: plotMarker, inlineEditForm: form, editLocationButton: options.plotLocation.edit, cancelEditLocationButton: options.plotLocation.cancel, location: options.plotLocation.location }); diameterCalculator({ formSelector: '#plot-form', cancelStream: form.cancelStream, saveOkStream: form.saveOkStream }); function onSaveBefore(data) { currentPlotMover.onSaveBefore(data); } function showAddTree() { $addTree.show(); $noTreeMessage.show(); $cancelAddTree.hide(); } function hideAddTree() { $addTree.hide(); $noTreeMessage.hide(); $cancelAddTree.hide(); } $(options.inlineEditForm.edit).click(showAddTree); $(options.inlineEditForm.cancel).click(hideAddTree); $addTree.click(function() { var $editFields = $(options.inlineEditForm.editFields), plotId = FH.getSerializableField($editFields, 'plot.id').val(); $addTree.hide(); $noTreeMessage.hide(); $cancelAddTree.show(); $treeSection.show(); FH.getSerializableField($editFields, 'tree.plot').val(plotId); }); $cancelAddTree.click(function() { var $editFields = $(options.inlineEditForm.editFields); $addTree.show(); $noTreeMessage.show(); $cancelAddTree.hide(); $treeSection.hide(); FH.getSerializableField($editFields, 'tree.plot').val(''); }); form.saveOkStream.onValue(hideAddTree); var newTreeIdStream = form.saveOkStream .map('.responseData.treeId') .filter(BU.isDefined); newTreeIdStream.onValue(function (val) { initializeTreeIdSection(val); $addTreeSection.hide(); }); function initializeTreeIdSection (id) { var $section = $(options.treeIdColumn); $section.attr('data-tree-id', id); $section.html('<a href="trees/' + id + '/">' + id + '</a>'); } if (options.config.instance.basemap.type === 'google') { var $streetViewContainer = $(options.streetView); $streetViewContainer.show(); var panorama = streetView.create({ streetViewElem: $streetViewContainer[0], noStreetViewText: options.config.noStreetViewText, location: options.plotLocation.location }); form.saveOkStream .map('.formData') .map(BU.getValueForKey, 'plot.geom') .filter(BU.isDefined) .onValue(panorama.update); } };