Browse Source

[search] Update template and field list of new collections

Romain Rigaux 11 years ago
parent
commit
4b95e6596b
1 changed files with 9 additions and 3 deletions
  1. 9 3
      apps/search/static/js/search.ko.js

+ 9 - 3
apps/search/static/js/search.ko.js

@@ -344,8 +344,8 @@ var Collection = function (vm, collection) {
   self.id = collection.id;
   self.name = ko.mapping.fromJS(collection.name);
   self.label = ko.mapping.fromJS(collection.label);
-  self.enabled= ko.mapping.fromJS(collection.enabled);
-  self.idField = collection.idField;
+  self.enabled = ko.mapping.fromJS(collection.enabled);
+  self.idField = ko.observable(collection.idField);
   self.template = ko.mapping.fromJS(collection.template);
   self.template.fieldsSelected.subscribe(function () {
     vm.search();
@@ -519,6 +519,12 @@ var Collection = function (vm, collection) {
         name: self.name()
 	  }, function (data) {
 	    if (data.status == 0) {
+	      self.idField(data.collection.collection.idField);
+	      self.template.template(data.collection.collection.template.template);
+	      self.template.fieldsAttributes.removeAll();
+	      $.each(data.collection.collection.template.fieldsAttributes, function(index, field) {
+		    self.template.fieldsAttributes.push(ko.mapping.fromJS(field));
+		  });
 	      self.fields.removeAll();
 	      $.each(data.collection.collection.fields, function(index, field) {
 	    	self.fields.push(ko.mapping.fromJS(field));
@@ -826,7 +832,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
               } else {
                 row.push(ko.mapping.toJSON(item)); 
               }
-              var doc = {'id': item[self.collection.idField], 'row': row};
+              var doc = {'id': item[self.collection.idField()], 'row': row};
               self.results.push(doc);
             });
           }