diff --git a/lib/edit/dbAttachmentStore.js b/lib/edit/dbAttachmentStore.js index d1a6cb5..c37ffe6 100644 --- a/lib/edit/dbAttachmentStore.js +++ b/lib/edit/dbAttachmentStore.js @@ -218,11 +218,11 @@ define([],function() this.init = function(callback) { var request = indexedDB.open(this._localEnum().DB_NAME, 4); - callback = callback? callback : function(success) { console.log("DbStore::init() success:", success)}.bind(this); + callback = callback? callback : function(success) { console.log("dbAttachmentStore::init() success:", success)}.bind(this); request.onerror = function(event) { - console.log("indexedDB error: " + event.target.errorCode); + console.log("dbAttachmentStore error: " + event.target.errorCode); callback(false,event.target.errorCode); }.bind(this); diff --git a/lib/edit/offlineFeaturesManager.js b/lib/edit/offlineFeaturesManager.js index 44fa4da..2de7135 100644 --- a/lib/edit/offlineFeaturesManager.js +++ b/lib/edit/offlineFeaturesManager.js @@ -2,6 +2,7 @@ define([ "edit/editsStore", + "edit/dbAttachmentStore", "dojo/Evented", "dojo/_base/Deferred", "dojo/promise/all", @@ -13,7 +14,8 @@ define([ "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/request"], - function(editsStore,Evented,Deferred,all,declare,lang,GraphicsLayer,Graphic,SimpleMarkerSymbol,SimpleLineSymbol,SimpleFillSymbol,esriRequest) + function(editsStore,DbAttachmentStore,Evented, + Deferred,all,declare,lang,GraphicsLayer,Graphic,SimpleMarkerSymbol,SimpleLineSymbol,SimpleFillSymbol,esriRequest) { return declare([Evented], { @@ -37,7 +39,7 @@ define([ * @param layer * @returns deferred */ - extend: function(layer) + extend: function(layer,callback) { var self = this; @@ -49,6 +51,22 @@ define([ layer._addAttachment = layer.addAttachment; layer._queryAttachmentInfos = layer.queryAttachmentInfos; + try{ + layer.offline = { + online: true, + store: new DbAttachmentStore(), + proxyPath: "../../lib/proxy.php" + }; + + if( /*false &&*/ layer.offline.store.isSupported() ) + layer.offline.store.init(callback); + else + return callback(false, "indexedDB not supported"); + } + catch(err){ + console.log("problem! " + err.toString()) + } + layer.queryAttachmentInfos = function(objectId,callback,errback){ if( self.getOnlineStatus() == self.ONLINE) { diff --git a/samples/attachments-editor.html b/samples/attachments-editor.html index c2c7128..3c854c4 100644 --- a/samples/attachments-editor.html +++ b/samples/attachments-editor.html @@ -102,20 +102,20 @@ mode: FeatureLayer.MODE_ONDEMAND }); -// map.infoWindow.setContent("
"); -// map.infoWindow.resize(350,200); -// var attachmentEditor = new AttachmentEditor({}, dom.byId("content")); -// attachmentEditor.startup(); + map.infoWindow.setContent(""); + map.infoWindow.resize(350,200); + var attachmentEditor = new AttachmentEditor({}, dom.byId("content")); + attachmentEditor.startup(); featureLayer.on("click", function(evt) { var objectId = evt.graphic.attributes[featureLayer.objectIdField]; map.infoWindow.setTitle(objectId); - featureLayer.queryAttachmentInfos(objectId,function(evt){ - console.log("AHAHAHA") - },function(err){ - console.log("Problem querying attachments: " + err.toString()) - }) - //attachmentEditor.showAttachments(evt.graphic,featureLayer); +// featureLayer.queryAttachmentInfos(objectId,function(evt){ +// console.log("AHAHAHA") +// },function(err){ +// console.log("Problem querying attachments: " + err.toString()) +// }) + attachmentEditor.showAttachments(evt.graphic,featureLayer); map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint)); }); @@ -133,7 +133,6 @@ updateConnectivityIndicator(); updateStorageInfo(); - Offline.options = { checks: { image: { @@ -156,7 +155,12 @@ try{ var test = featureLayer.allowGeometryUpdates; console.log("type " + test) - offlineFeaturesManager.extend(featureLayer); + offlineFeaturesManager.extend(featureLayer,function(success){ + console.log("extend "); + if(success){ + + } + }); layer.on('update-end', logCurrentObjectIds); //handle errors that happen while storing offline edits