Yoji SHIDARA
null+****@clear*****
Wed Oct 3 15:39:56 JST 2012
Yoji SHIDARA 2012-10-03 15:39:56 +0900 (Wed, 03 Oct 2012) New Revision: 7c41cb55cb6081a8e87cbe2aa15c5e491dbff20f https://github.com/groonga/gcs/commit/7c41cb55cb6081a8e87cbe2aa15c5e491dbff20f Log: Add code to creating domain Note: This implementation does not handle ajax errors. Modified files: public/js/gcs/models.js public/js/gcs/views.js Modified: public/js/gcs/models.js (+66 -36) =================================================================== --- public/js/gcs/models.js 2012-10-03 11:13:43 +0900 (588cc1f) +++ public/js/gcs/models.js 2012-10-03 15:39:56 +0900 (7c52acc) @@ -1,4 +1,42 @@ App.Adapter = DS.Adapter.extend({ + processDomainStatus: function(domainElement, callback) { + var name = domainElement.find('DomainName').text(); + var searchEndpoint = domainElement.find('SearchService > Endpoint').text(); + var docEndpoint = domainElement.find('DocService > Endpoint').text(); + + var self = this; + $.ajax({ + type: 'GET', + url: self.configurationEndpoint, + data: { + Version: '2011-02-01', + Action: 'DescribeIndexFields', + DomainName: name + }, + dataType: 'xml', + success: function(data) { + var indexFields = []; + $(data).find('IndexFields > member').each(function(index) { + var field = $(this); + var name = field.find('IndexFieldName').text(); + indexFields.push({ + id: name, + name: name + }); + }); + + var domain = { + id: name, + name: name, + search_endpoint: searchEndpoint, + doc_endpoint: docEndpoint, + index_fields: indexFields, + configuration_endpoint: self.configurationEndpoint + }; + callback(domain); + } + }); + }, findAll: function(store, type) { if (type === App.Domain) { var self = this; @@ -13,42 +51,8 @@ App.Adapter = DS.Adapter.extend({ success: function(data) { var domainStatusMembers = $(data).find('DomainStatusList > member'); domainStatusMembers.each(function(index) { - var domainElement = $(this); - var name = domainElement.find('DomainName').text(); - var searchEndpoint = domainElement.find('SearchService > Endpoint').text(); - var docEndpoint = domainElement.find('DocService > Endpoint').text(); - - var self = this; - $.ajax({ - type: 'GET', - url: self.configurationEndpoint, - data: { - Version: '2011-02-01', - Action: 'DescribeIndexFields', - DomainName: name - }, - dataType: 'xml', - success: function(data) { - var indexFields = []; - $(data).find('IndexFields > member').each(function(index) { - var field = $(this); - var name = field.find('IndexFieldName').text(); - indexFields.push({ - id: name, - name: name - }); - }); - - var domain = { - id: name, - name: name, - search_endpoint: searchEndpoint, - doc_endpoint: docEndpoint, - index_fields: indexFields, - configuration_endpoint: self.configurationEndpoint - }; - store.load(type, name, domain); - } + self.processDomainStatus($(this), function(domain) { + store.load(type, domain.name, domain); }); }); } @@ -59,6 +63,32 @@ App.Adapter = DS.Adapter.extend({ }, find: function(store, type, id) { this.findAll(store, type); // Fetch all for the simplicity + }, + createRecord: function(store, type, model) { + var self = this; + if (type === App.Domain) { + $.ajax({ + type: 'GET', + url: self.configurationEndpoint, + data: { + Version: '2011-02-01', + Action: 'CreateDomain', + DomainName: model.get('name') + }, + success: function(data) { + var domainStatus = $(data).find('CreateDomainResult > DomainStatus'); + self.processDomainStatus(domainStatus, function(domain) { + store.didCreateRecord(model, domain); + }); + }, + error: function(data) { + console.log(data); + store.recordWasInvalid(model, {name: "invalid"}); + } + }); + } else { + throw "Unsupported model"; + } } }); Modified: public/js/gcs/views.js (+3 -1) =================================================================== --- public/js/gcs/views.js 2012-10-03 11:13:43 +0900 (a9ea7fb) +++ public/js/gcs/views.js 2012-10-03 15:39:56 +0900 (b49bf81) @@ -66,7 +66,9 @@ App.DomainCreateView = Ember.View.extend({ submit: function(event) { event.preventDefault(); var domainName = this.get('controller.domainName'); - alert("TODO: create " + domainName); + var domain = App.store.createRecord(App.Domain, {name: domainName}); + // TODO treat ajax errors (but how?) + App.store.commit(); } }) }); -------------- next part -------------- HTML����������������������������...Download