{"action":"created","issue":{"url":"https://api.github.com/repos/Esri/offline-editor-js/issues/437","labels_url":"https://api.github.com/repos/Esri/offline-editor-js/issues/437/labels{/name}","comments_url":"https://api.github.com/repos/Esri/offline-editor-js/issues/437/comments","events_url":"https://api.github.com/repos/Esri/offline-editor-js/issues/437/events","html_url":"https://github.com/Esri/offline-editor-js/issues/437","id":124830383,"number":437,"title":"Editing not working with full browser restart","user":{"login":"tjones0808","id":10042391,"avatar_url":"https://avatars.githubusercontent.com/u/10042391?v=3","gravatar_id":"","url":"https://api.github.com/users/tjones0808","html_url":"https://github.com/tjones0808","followers_url":"https://api.github.com/users/tjones0808/followers","following_url":"https://api.github.com/users/tjones0808/following{/other_user}","gists_url":"https://api.github.com/users/tjones0808/gists{/gist_id}","starred_url":"https://api.github.com/users/tjones0808/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjones0808/subscriptions","organizations_url":"https://api.github.com/users/tjones0808/orgs","repos_url":"https://api.github.com/users/tjones0808/repos","events_url":"https://api.github.com/users/tjones0808/events{/privacy}","received_events_url":"https://api.github.com/users/tjones0808/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Esri/offline-editor-js/labels/documentation","name":"documentation","color":"207de5"},{"url":"https://api.github.com/repos/Esri/offline-editor-js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":29,"created_at":"2016-01-04T20:18:03Z","updated_at":"2016-01-11T19:09:04Z","closed_at":null,"body":"I have implemented the offline functionality with no problems when using the partial editing offline solutions. I can go offline cut all internet make edits, come back online and everything works fine. The problems arise when restarting the browser. For some reason it seems the extending isn't working, when trying to make any edits, nothing happens. I see an attempting progress bar on the editor widget but then it just quits\r\n\r\nCode that inits layers:\r\n\r\n   \r\n    function extendFeatureLayer(featureLayer, online, callback) {\r\n\r\n        \r\n        var dataStore = {};\r\n        dataStore.featureLayerCollection = JSON.stringify(featureLayer.toJson());\r\n        dataStore.zoomLevel = _map.getZoom();\r\n        dataStore.centerPt = (_map.extent.getCenter()).toJson();\r\n        dataStore.featureLayerUrl = featureLayer.url;\r\n        dataStoreArray.push(dataStore);\r\n\r\n        offlineEdit.extend(featureLayer, function (result, error) {\r\n            if (result) {\r\n                // If the app is online then force OfflineEditAdvanced to its online state\r\n                // This will force the library to check for pending edits and attempt to\r\n                // resend them to the Feature Service.\r\n                if (_isOnline) {\r\n                    goOnline();\r\n                }\r\n                else {\r\n                    goOffline();\r\n                    updateStatus(\"Successfully extended layer for offline use.\");\r\n                }\r\n\r\n                callback(true);\r\n            }\r\n            else {\r\n                callback(false);\r\n                alert(\"Unable to initialize the database. \" + error);\r\n            }\r\n\r\n        }.bind(this), dataStoreArray);\r\n    }\r\n\r\n    function loadFeatureLayerOffline(callback) {\r\n        offlineEdit.getFeatureLayerJSONDataStore(function (success, dataStore) {\r\n            if(success){\r\n\r\n                // Use the feature layer returns from getFeatureDefinition() to reconstitute the layer\r\n                // We don't have to set any other properties on the layer because we are using it\r\n                // in SNAPSHOT mode which downloads all features within the given extent.\r\n                array.forEach(dataStore, function (ds) {\r\n                    featureLayer = new FeatureLayer(JSON.parse(ds.featureLayerCollection));\r\n\r\n                    //if (featureLayer.url == undefined) {\r\n                        featureLayer.url = ds.featureLayerUrl;\r\n                        featureLayer._url = {\r\n                            path: ds.featureLayerUrl,\r\n                            query: null\r\n                        }\r\n                    //}\r\n\r\n                    featureLayerArray.push(featureLayer);                    \r\n                    dataStore = getFeatureLayerJSON(featureLayer);\r\n                   \r\n                });\r\n               \r\n                on(_map, 'layers-add-result', extendOffline);\r\n\r\n                console.log(\"Feature has been added back to the map while offline.\");                           \r\n                \r\n                _map.centerAt(dataStore.centerPt);\r\n                _map.setZoom(dataStore.zoomLevel);\r\n\r\n                callback(true);\r\n            }\r\n            else {\r\n                updateStatus(\"There was a problem retrieving feature layer options object. \" + dataStore);\r\n                callback(false);\r\n            }\r\n        });\r\n    }\r\n\r\n    function extendOffline() {\r\n        array.forEach(featureLayerArray, function (featureLayer) {\r\n            extendFeatureLayer(featureLayer, _isOnline, function (success) {\r\n                updateStatus(\"Feature Layer extended successfully OFFLINE!\");\r\n            });\r\n        });\r\n    }\r\n\r\n   \r\n    function getFeatureLayerJSON(featureLayer) {\r\n        return {\r\n            \"featureLayerCollection\": JSON.stringify(featureLayer.toJson()),\r\n            \"zoomLevel\": _map.getZoom(),\r\n            \"centerPt\": (_map.extent.getCenter()).toJson(),\r\n            \"featureLayerUrl\": featureLayer.url\r\n        }\r\n    }\r\n\r\n    function updateFeatureLayerJSON() {\r\n\r\n        array.forEach(featureLayerArray, function (featureLayer) {\r\n            var fl = getFeatureLayerJSON(featureLayer);\r\n\r\n            featureLayer.setFeatureLayerJSONDataStore(fl, function (result, error) {\r\n                console.log('updateFeatureLayerJson - Result: ' + result + \", error: \" + error);\r\n            });\r\n        });        \r\n    }\r\n\r\n    function initPanZoomListeners() {        \r\n\r\n        _map.on(\"zoom-end\", function (evt) {\r\n            _currentExtent = evt.extent;\r\n            updateFeatureLayerJSON();\r\n        });\r\n\r\n        _map.on(\"pan-end\", function (evt) {\r\n            _currentExtent = evt.extent;\r\n            updateFeatureLayerJSON();\r\n        });\r\n    }\r\n\r\n   \t\tinitMap: function () {\r\n\t\t\tif (has('phone') && !this.config.mapOptions.infoWindow) {\r\n\t\t\t\tthis.config.mapOptions.infoWindow = new PopupMobile(null, put('div'));\r\n\t\t\t}\r\n\t\t\tthis.map = new Map('mapCenter', this.config.mapOptions);\r\n\t\t\t_map = this.map;\r\n\r\n            // initalize offline module and settings\r\n\t\t\tvar initFunc = lang.hitch(this, 'initOfflineEdits');\r\n\t\t\tinitFunc();\r\n            \r\n\t\t\tif (this.config.mapOptions.basemap) {\r\n\t\t\t    this.map.on('load', lang.hitch(this, 'initLayers'));\r\n\t\t\t} else {\r\n\t\t\t\tthis.initLayers();\r\n\t\t\t}\r\n\t\t\tif (this.config.operationalLayers && this.config.operationalLayers.length > 0) {\r\n\t\t\t    if (_isOnline) {\r\n\t\t\t        on(this.map, 'layers-add-result', lang.hitch(this, 'layersAddedEvent'));\r\n\t\t\t    } else {\r\n\t\t\t        var initEvent = lang.hitch(this, 'layersAddedEvent');\r\n\t\t\t        initEvent();\r\n\t\t\t    }\r\n\t\t\t} else {\r\n\t\t\t\tthis.initWidgets();\r\n\t\t\t}\r\n\t\t},\r\n\t\tlayersAddedEvent: function (evt) {\r\n\r\n\t\t    var initWidgets = lang.hitch(this, 'initWidgets');\r\n\t\t    initWidgets();\r\n\t\t    var me = this;\r\n\r\n\t\t    //on.once(this.map, 'update-end', lang.hitch(me, 'initFeaturesListener'));\r\n            \r\n\t\t    if (evt) {\r\n\t\t        array.forEach(evt.layers, function (layerObj) {\r\n\r\n\t\t            var type = layerObj.layer.type;\r\n\r\n\t\t            if (type === \"Feature Layer\") {\r\n\t\t                var fl = layerObj.layer;\r\n\t\t                featureLayerArray.push(fl);\r\n\t\t                on.once(fl, 'update-end', lang.hitch(me, 'initFeaturesListener', fl));\t\r\n\t\t            }\r\n\t\t        })\r\n\t\t        me.initOfflineTiles(me.map);\t\t        \r\n\t\t    } else {\r\n\t\t        me.initOfflineTiles(me.map);\r\n\r\n\t\t        var initFeatsOffline = lang.hitch(me, 'initFeaturesListener');\r\n\t\t        initFeatsOffline();\r\n\t\t    }\r\n\t\t},\t\t\r\n\t\tinitFeaturesListener: function (fl) {  \r\n\t\t    // If app is online then we ONLY need to extend the feature layer.\r\n\t\t    if (_isOnline) {\r\n\t\t        extendFeatureLayer(fl, _isOnline, function (success) {\r\n\t\t            if (success) {\r\n\t\t                initPanZoomListeners();\r\n\t\t            }\r\n\t\t            else {\r\n\t\t                updateStatus(\"There was a problem initializing the map for offline.\");\r\n\t\t            }\r\n\t\t        });\t\t            \r\n\t\t    }\r\n\t\t        // If the app is offline then we need to retrieve the dataStore from OfflineEditAdvanced\r\n\t\t        // and then extend the feature layer using that information.\r\n\t\t    else {\r\n\t\t        loadFeatureLayerOffline(function (success) {\r\n\t\t            if (success) {\r\n\r\n\t\t                _map.addLayers(featureLayerArray);\r\n\t\t            }\r\n\t\t            else {\r\n\t\t                updateStatus(\"There was a problem initializing the map for offline.\");\r\n\t\t            }\r\n\t\t        });\r\n\t\t    }\r\n\t\t},\r\n\t\tinitFeaturesOfflineListener: function (featureLayer) {\r\n\t\t    extendFeatureLayer(featureLayer, _isOnline, function (success) {\r\n\t\t        initPanZoomListeners();\r\n\t\t        updateStatus(\"Feature Layer extended successfully OFFLINE!\");\r\n\t\t    });\t\t                    \r\n        },\r\n\t\tinitOfflineEdits: function () {\r\n\t\t    offlineEdit = new O.esri.Edit.OfflineEditAdvanced();\r\n\r\n            // pull this from config\r\n\r\n\t\t    //offlineEdit.ENABLE_FEATURECOLLECTION = true;\r\n\r\n\t\t    offlineEdit.initAttachments(function (success) {\r\n\t\t        //attachmentsInited = success;\r\n\t\t    });\r\n\r\n\t\t    offlineEdit.on(offlineEdit.events.EDITS_ENQUEUED, updateQuedStatus);\r\n\t\t    offlineEdit.on(offlineEdit.events.EDITS_SENT, updateStatus);\r\n\t\t    offlineEdit.on(offlineEdit.events.ALL_EDITS_SENT, updateStatus);\r\n\t\t    offlineEdit.on(offlineEdit.events.EDITS_SENT_ERROR, editsError);\r\n\t\t    offlineEdit.on(offlineEdit.events.EDITS_ENQUEUED_ERROR, editsError);\r\n\r\n\t\t},\r\n\t\t\r\n\t\tinitLayer: function (layer, Layer) {\r\n\t\t\tvar l = new Layer(layer.url, layer.options);\r\n\t\t\tthis.layers.unshift(l); //unshift instead of push to keep layer ordering on map intact\r\n\t\t\t//Legend LayerInfos array\r\n\t\t\tvar excludeLayerFromLegend = false;\r\n            if ( typeof layer.legendLayerInfos !== 'undefined' && typeof layer.legendLayerInfos.exclude !== 'undefined' ) {\r\n                excludeLayerFromLegend = layer.legendLayerInfos.exclude;\r\n            }\r\n\t\t\tif ( !excludeLayerFromLegend ) {\r\n                var configuredLayerInfo = {};\r\n                if ( typeof layer.legendLayerInfos !== 'undefined' && typeof layer.legendLayerInfos.layerInfo !== 'undefined' ) {\r\n                    configuredLayerInfo = layer.legendLayerInfos.layerInfo;\r\n                }\r\n                var layerInfo = lang.mixin( {\r\n                    layer: l,\r\n                    title: layer.title || null\r\n                }, configuredLayerInfo );\r\n\t\t\t\tthis.legendLayerInfos.unshift ( layerInfo ); //unshift instead of push to keep layer ordering in legend intact\r\n\t\t\t}\r\n\t\t\t//LayerControl LayerInfos array\r\n\t\t\tthis.layerControlLayerInfos.unshift({ //unshift instead of push to keep layer ordering in LayerControl intact\r\n\t\t\t\tlayer: l,\r\n\t\t\t\ttype: layer.type,\r\n\t\t\t\ttitle: layer.title,\r\n\t\t\t\tcontrolOptions: layer.layerControlLayerInfos\r\n\t\t\t});\r\n\t\t\tif (layer.type === 'feature') {\r\n\t\t\t\tvar options = {\r\n\t\t\t\t\tfeatureLayer: l\r\n\t\t\t\t};\r\n\t\t\t\tif (layer.editorLayerInfos) {\r\n\t\t\t\t\tlang.mixin(options, layer.editorLayerInfos);\r\n\t\t\t\t}\r\n\t\t\t\tif (options.exclude !== true) {\r\n\t\t\t\t\tthis.editorLayerInfos.push(options);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (layer.type === 'dynamic' || layer.type === 'feature') {\r\n\t\t\t\tvar idOptions = {\r\n\t\t\t\t\tlayer: l,\r\n\t\t\t\t\ttitle: layer.title\r\n\t\t\t\t};\r\n\t\t\t\tif (layer.identifyLayerInfos) {\r\n\t\t\t\t\tlang.mixin(idOptions, layer.identifyLayerInfos);\r\n\t\t\t\t}\r\n\t\t\t\tif (idOptions.exclude !== true) {\r\n\t\t\t\t\tthis.identifyLayerInfos.push(idOptions);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t},\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Esri/offline-editor-js/issues/comments/170655533","html_url":"https://github.com/Esri/offline-editor-js/issues/437#issuecomment-170655533","issue_url":"https://api.github.com/repos/Esri/offline-editor-js/issues/437","id":170655533,"user":{"login":"andygup","id":510440,"avatar_url":"https://avatars.githubusercontent.com/u/510440?v=3","gravatar_id":"","url":"https://api.github.com/users/andygup","html_url":"https://github.com/andygup","followers_url":"https://api.github.com/users/andygup/followers","following_url":"https://api.github.com/users/andygup/following{/other_user}","gists_url":"https://api.github.com/users/andygup/gists{/gist_id}","starred_url":"https://api.github.com/users/andygup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andygup/subscriptions","organizations_url":"https://api.github.com/users/andygup/orgs","repos_url":"https://api.github.com/users/andygup/repos","events_url":"https://api.github.com/users/andygup/events{/privacy}","received_events_url":"https://api.github.com/users/andygup/received_events","type":"User","site_admin":false},"created_at":"2016-01-11T19:09:04Z","updated_at":"2016-01-11T19:09:04Z","body":"@webmapsolutions @tjones0808 here's the working [branch](https://github.com/andygup/offline-editor-js/tree/3.1) for the sample-in-progress. \r\n\r\nThe new sample is currently called [appcache-features-edit](https://github.com/andygup/offline-editor-js/blob/3.1/samples/appcache-features-edit.html). If you are looking to tackle one of the TODOs above or something I missed, just let me know beforehand. That way we can avoid duplication of effort.\r\n\r\nI'll be addressing number 3 and 4 today. \r\n\r\n "}}