Răsfoiți Sursa

[search] Add field modal preview and cancel functions

Romain Rigaux 11 ani în urmă
părinte
comite
f7c57eeb30

+ 8 - 3
apps/search/src/search/templates/search2.mako

@@ -742,7 +742,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
        placeholder="${_('Filter fields')}" class="input-xlarge" />
       <ul data-bind="foreach: $root.collection.template.filteredFieldsAttributes().sort(function (l, r) { return l.name() > r.name() ? 1 : -1 })"
           class="unstyled inline fields-chooser">
-        <li data-bind="click: addFacetDemiModalFieldClick">
+        <li data-bind="click: addFacetDemiModalFieldPreview">
           <span class="badge badge-info" style="font-size:20px"><span data-bind="text: name(), attr: {'title': type()}"></span>
           </span>
         </li>
@@ -1357,7 +1357,8 @@ $(document).ready(function () {
       $('#addFacetInput').typeahead({
           'source': viewModel.collection.template.availableWidgetFieldsNames(), 
           'updater': function(item) {
-              addFacetDemiModalFieldClick({'name': function(){return item}});
+              addFacetDemiModalFieldPreview({'name': function(){return item}});
+              // todo close modal here too?
               return item;
            }
       });
@@ -1373,7 +1374,7 @@ $(document).ready(function () {
   }
 
 
-  function addFacetDemiModalFieldClick(field) {
+  function addFacetDemiModalFieldPreview(field) {
     var _existingFacet = viewModel.collection.getFacetById(selectedWidget.id());
     if (selectedWidget != null) {
       selectedWidget.isLoading(true);
@@ -1385,6 +1386,10 @@ $(document).ready(function () {
       viewModel.search();
     }
   }
+  
+  function addFacetDemiModalFieldCancel(field) {
+    viewModel.removeWidget(selectedWidget.id());
+  }
 </script>
 
 ${ commonfooter(messages) | n,unicode }

+ 4 - 2
apps/search/static/js/search.ko.js

@@ -347,7 +347,7 @@ var Collection = function (vm, collection) {
   self.template.fieldsSelected.subscribe(function () {
     vm.search();
   });
-  self.template.template.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 3000 } });
+  self.template.template.extend({rateLimit: {timeout: 3000, method: "notifyWhenChangesStop"}});
   self.template.template.subscribe(function () {
     vm.search();
   });
@@ -363,7 +363,7 @@ var Collection = function (vm, collection) {
   self.template.rows.subscribe(function(){
 	vm.search();
   });
-  self.template.rows.extend({ rateLimit: { timeout: 1500, method: "notifyWhenChangesStop" } });
+  self.template.rows.extend({rateLimit: {timeout: 1500, method: "notifyWhenChangesStop"}});
 
   self.fields = ko.mapping.fromJS(collection.fields);
   self.availableFacetFields = ko.computed(function() {
@@ -378,6 +378,8 @@ var Collection = function (vm, collection) {
   self.selectedDocument = ko.observable({});
 
   self.addFacet = function (facet_json) {
+    self.removeFacet(function(){return facet_json.widget_id});
+	  
     $.post("/search/template/new_facet", {
       "collection": ko.mapping.toJSON(self),
         "id": facet_json.widget_id,