<commit_before>/*
 * @requires FaultedEarth.js
 */

FaultedEarth.SourceForm = Ext.extend(gxp.plugins.Tool, {
    
    ptype: "app_sourceform",
    
    /** api: config[featureManager]
     *  ``String`` id of the FeatureManager to add uploaded features to
     */
    
    /** api: config[featureEditor]
     *  ``String`` id of the FeatureEditor to modify uploaded features
     */
    
    /** api: config[temporaryWorkspace]
     *  ``String`` temporary GeoServer workspace for shapefile uploads.
     *  Default is "temp".
     */
    temporaryWorkspace: "temp",

    /** api: config[temporaryWorkspaceNamespaceUri]
     *  ``String`` namespace uri of the temporary GeoServer workspace for
     *  shapefile uploads. Default is "http://geonode.org/temporary".
     */
    temporaryWorkspaceNamespaceUri: "http://geonode.org/temporary",
    
    /** private: property[sessionFids]
     *  ``Array`` fids of features added/modified in this session
     */
    sessionFids: null,
    
    autoActivate: false,
    
    init: function(target) {
        FaultedEarth.SourceForm.superclass.init.apply(this, arguments);
        
        this.sessionFids = [];
        var featureManager = target.tools[this.featureManager];
        featureManager.featureLayer.events.on({
            "featureselected": function(e) {
                if (!e.feature.fid) {
                    return;
                }
                if (featureManager.layerRecord.get("name") == "geonode:observations_faultsource") {
                    this.target.summaryId = e.feature.fid;

                    this.current_trace_url = "/observations/traces/join";

                } else if (this.target.summaryId) {
                    this.output[0].ownerCt.enable();
                    this.current_trace_url = "/traces/new/trace_id/" + this.target.summaryId.split(".").pop()
                }
                this.sessionFids.push(this.target.summaryId);
            },
            "featureunselected": function(e) {
                if (this.active && featureManager.layerRecord.get("name") == "geonode:observations_faultsource") {
                    this.sessionFids = [];
                    this.target.summaryId = null;
                }
            },
            scope: this
        });
    },
    
    addOutput: function(config) {
        return FaultedEarth.SourceForm.superclass.addOutput.call(this, {
            xtype: "form",
            labelWidth: 110,
            defaults: {
                anchor: "100%"
            },
            items: [{
                xtype: "box",
                autoEl: {
                    tag: "p",
                    cls: "x-form-item"
                },
                html: "fault source export button goes here..."
            }],<commit_msg>add export feature to ui, still needs testing<commit_after>/*
 * @requires FaultedEarth.js
 */

FaultedEarth.SourceForm = Ext.extend(gxp.plugins.Tool, {
    
    ptype: "app_sourceform",
    
    /** api: config[featureManager]
     *  ``String`` id of the FeatureManager to add uploaded features to
     */
    
    /** api: config[featureEditor]
     *  ``String`` id of the FeatureEditor to modify uploaded features
     */
    
    /** api: config[temporaryWorkspace]
     *  ``String`` temporary GeoServer workspace for shapefile uploads.
     *  Default is "temp".
     */
    temporaryWorkspace: "temp",

    /** api: config[temporaryWorkspaceNamespaceUri]
     *  ``String`` namespace uri of the temporary GeoServer workspace for
     *  shapefile uploads. Default is "http://geonode.org/temporary".
     */
    temporaryWorkspaceNamespaceUri: "http://geonode.org/temporary",
    
    /** private: property[sessionFids]
     *  ``Array`` fids of features added/modified in this session
     */
    sessionFids: null,
    
    autoActivate: false,
    
    init: function(target) {
        FaultedEarth.SourceForm.superclass.init.apply(this, arguments);
        
        this.sessionFids = [];
        var featureManager = target.tools[this.featureManager];
        featureManager.featureLayer.events.on({
            "featureselected": function(e) {
                if (!e.feature.fid) {
                    return;
                }
                if (featureManager.layerRecord.get("name") == "geonode:observations_faultsource") {
                    this.current_fault_source_url = "/observations/faultsource/export";
                    this.sessionFids.push(e.feature.fid.split('.')[1]);
                }
            },
            "featureunselected": function(e) {
                if (this.active && featureManager.layerRecord.get("name") == "geonode:observations_faultsource") {
                    this.sessionFids = [];
                    this.target.summaryId = null;
                }
            },
            scope: this
        });
    },
    
    addOutput: function(config) {
        return FaultedEarth.SourceForm.superclass.addOutput.call(this, {
            xtype: "form",
            labelWidth: 110,
            defaults: {
                anchor: "100%"
            },
            items: [{
                xtype: "box",
                autoEl: {
                    tag: "p",
                    cls: "x-form-item"
                },
                html: "Select a Fault Source from the grid below then click 'Export' to download it."
            },    {
                    xtype: "container",
                    layout: "hbox",
                    items: [{
                        xtype: "button",
                        text: "Export",
                        iconCls: "icon-layer-switcher",
                        handler: function() {
                            var featureManager = this.target.tools[this.featureManager];
                            Ext.Ajax.request({
                                method: "PUT",
                                url: this.target.localGeoNodeUrl + this.target.localHostname + this.current_fault_source_url,
                                params: Ext.encode(this.sessionFids),
                                success: function(response, opts) {
                                    alert('Fault Source record recorded');
                                    this.sessionFids = [];
                                },
                                failure: function(response, opts){
                                    alert('Fault Source record NOT recorded');
                                },
                                
                                scope: this
                            });

                        },
                        scope: this
                        }]
                 }],
{'fraction_non_alphanumeric': 0.10904454777261137, 'fraction_numerical': 0.0020998950052497373, 'mean_word_length': 1.410701373825018, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3393650', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1667, 'n_words': 335}