Browse Source

found (kinda) smart solution to add new examples in menu&shortcut links

Benoît Hubert 8 years ago
parent
commit
91c8d42c3a
3 changed files with 18 additions and 1 deletions
  1. 4 0
      js/ws-forms.js
  2. 12 0
      js/ws-menu.js
  3. 2 1
      js/ws-ui-parts.js

+ 4 - 0
js/ws-forms.js

@@ -153,6 +153,10 @@ function checkPropsExist(obj, props) {
     onAddSuccess: function(example) {
       _ws.notify('success', 'Exemple crée: ' + example.title);
       _ws.navigateTo('/' + _ws.repo.path + '/' + example.slug);
+
+      // console.log('##### addExample success', _ws, _ws.ui.menuExample.$elem.find('ul[data-id="' + example.category + '"]') )
+      _ws.ui.menuExample.addExampleLink(example, '/' + _ws.repo.path + '/' + example.slug);
+      _ws.ui.shortcutExample.addExampleLink(example, '/' + _ws.repo.path + '/' + example.slug);
     },
     onAddError: function(err) {
      _ws.notify('error', "Impossible de créer l'exemple: " + err.message); 

+ 12 - 0
js/ws-menu.js

@@ -136,10 +136,20 @@
       _ws.navigateTo($link.prop('href'));
     }
 
+    function addExampleLink(cb) {
+      return function(example, href) {
+        var $targetList = this.$elem.find('ul[data-id="' + example.category + '"]');
+        var $newItem = $('<li><a href="' + href + '">' + example.title + '</a></li>').appendTo($targetList);
+        $newItem.find('a').on('click', cb);
+      }
+    }
+
     /**
      * Initialize menu-example view
      */
     _ws.makeView('menu-example', {
+      addExampleLink: addExampleLink(menuItemClicked),
+
       events: {
         'click a': menuItemClicked
       }
@@ -170,6 +180,8 @@
      * Initialize shortcut-example view
      */
     _ws.makeView('shortcut-example', {
+      addExampleLink: addExampleLink(shortcutItemClicked),
+
       events: {
         'click a': shortcutItemClicked
       }

+ 2 - 1
js/ws-ui-parts.js

@@ -120,7 +120,8 @@
           // console.log('pass props: ignore', p);
           continue;
         }
-        v[p] = props[p];
+        var prop = props[p];
+        v[p] = typeof prop !== 'function' ? prop : prop.bind(v);
       }
 
       v.show = viewElemShow.bind(v);