فهرست منبع

[search] Add a new template button

Romain Rigaux 11 سال پیش
والد
کامیت
02e574600e

+ 2 - 0
apps/search/src/search/templates/search2.mako

@@ -157,6 +157,8 @@ ${ commonheader(_('Search'), "search", user, "60px") | n,unicode }
       <button type="button" title="${ _('Settings') }" rel="tooltip" data-placement="bottom" data-bind="css: {'btn': true}"><i class="fa fa-cogs"></i></button>    
       <button type="button" title="${ _('Save') }" rel="tooltip" data-placement="bottom" data-loading-text="${ _("Saving...") }"  data-bind="click: save, css: {'btn': true}"><i class="fa fa-save"></i></button>
       <button type="button" title="${ _('History') }" rel="tooltip" data-placement="bottom" data-bind="css: {'btn': true}"><i class="fa fa-archive"></i></button>
+      &nbsp;&nbsp;&nbsp;            
+      <a class="btn" href="${ url('search:new_search') }" title="${ _('New') }" rel="tooltip" data-placement="bottom" data-bind="css: {'btn': true}"><i class="fa fa-file-o"></i></a>
       <a class="btn" href="${ url('search:admin_collections') }" title="${ _('Collections') }" rel="tooltip" data-placement="bottom" data-bind="css: {'btn': true}"><i class="fa fa-tags"></i></a> 
     </div>
   % endif

+ 1 - 0
apps/search/src/search/urls.py

@@ -21,6 +21,7 @@ urlpatterns = patterns('search.views',
   url(r'^$', 'index', name='index'),
   url(r'^search$', 'search', name='search'),
   url(r'^save$', 'save', name='save'),
+  url(r'^new_search', 'new_search', name='new_search'),
   url(r'^download/(?P<format>(csv|xls))$', 'download', name='download'),
 
   url(r'^dashboard$', 'dashboard', name='dashboard'),

+ 14 - 2
apps/search/src/search/views.py

@@ -70,13 +70,25 @@ def index(request):
   })
 
 
+def new_search(request):
+  collection = Collection(name='twitter_demo', label='New Twitter Template', enabled=True)
+  query = {'q': '', 'fq': {}}
+
+  return render('search2.mako', request, {
+    'collection': collection,
+    'query': query,
+  })
+
+
 def search(request):
   response = {}  
   
   collection = json.loads(request.POST.get('collection', '{}')) # TODO decorator with doc model perms
   query = json.loads(request.POST.get('query', '{}'))
-  hue_collection = Collection.objects.get(id=collection['id']) # TODO perms
-  # collection['name']=
+
+  if collection['id']:
+    hue_collection = Collection.objects.get(id=collection['id']) # TODO perms
+    # collection['name']=
   
   print request.POST
   print collection

+ 1 - 1
apps/search/static/js/search.ko.js

@@ -307,7 +307,7 @@ var SearchViewModel = function (collection_json, query_json) {
   self.getFacetFromQuery = function (facet_id) {	
     var _facet = null;
     if (self.norm_facets() !== undefined) {
-	  $.each(self.norm_facets(), function (index, norm_facet) {//alert(ko.mapping.toJSON(norm_facet.id + " " + facet_id()));  
+	  $.each(self.norm_facets(), function (index, norm_facet) {  
 	    if (norm_facet.id == facet_id()) {
 	      _facet = norm_facet;
 	    }