Skip to content

Commit

Permalink
Made prepare call look up true resource type by resource id
Browse files Browse the repository at this point in the history
Because of alternate resource types in the URL instead of a real type, prepare was failing.

Same issue with the backbone forms edit schema, so this was moved into the call for retrieving the prepare object itself - just added as another field.  One less AJAX call.
  • Loading branch information
Dave Foster committed Jun 7, 2013
1 parent 7afac63 commit 6f56ab3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.py
Expand Up @@ -556,7 +556,7 @@ def edit(resource_type, resource_id):
@app.route('/resource_type_edit/<resource_type>/<resource_id>/', methods=['GET', 'PUT'])
def resource_type_edit(resource_type, resource_id):
if request.method == 'GET':
resource = ServiceApi.get_prepare(resource_type, resource_id, None)
resource = ServiceApi.get_prepare(resource_type, resource_id, None, True)
return render_json_response(resource)
if request.method == 'PUT':
data = json.loads(request.data)
Expand Down
12 changes: 11 additions & 1 deletion service_api.py
Expand Up @@ -600,7 +600,13 @@ def create_resource(resource_type, org_id):
return [resp, resp2]

@staticmethod
def get_prepare(resource_type, resource_id, user_id):
def get_prepare(resource_type, resource_id, user_id, get_backbone_schema=False):

# because of the way the UI changes the type that comes in here, we can't really trust it
# this means we need to read the resource to get the type first then use that.
res = service_gateway_get('resource_registry', 'read', params={'object_id': resource_id})
resource_type = res['type_']

if resource_type == 'InstrumentDevice':
params = {}
if resource_id:
Expand Down Expand Up @@ -640,6 +646,10 @@ def get_prepare(resource_type, resource_id, user_id):

prepare = service_gateway_get('resource_registry', 'prepare_resource_support', params=params)

# now, get the backbone schema if requested, using the converted type we got above
if get_backbone_schema:
prepare['resource_backbone_schema'] = ServiceApi.resource_type_schema(resource_type)

return prepare

"""
Expand Down
9 changes: 1 addition & 8 deletions static/js/ux-editform.js
Expand Up @@ -227,14 +227,7 @@ IONUX.Models.EditResourceModel = Backbone.Model.extend({
},

get_resource_type_schema: function(){
/* NOTE: this is a blocking ajax call (async:false) */
var url = "/resource_type_schema/"+this.resource_type + "/";
var data = null;
$.ajax({url:url, type:"GET", dataType:"json", async:false})
.always(function(){})
.done(function(resp){data = resp;})
.fail(function(){})
return data["schema"];
return this.prepare.resource_backbone_schema;
},

nest_depth: function(val){
Expand Down

0 comments on commit 6f56ab3

Please sign in to comment.