Skip to content

Commit

Permalink
see #1: add a Backbone structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ziodave committed Oct 29, 2015
1 parent f774151 commit 1c05808
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/admin/class-helixware-mico-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Helixware_Mico_Admin {
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;

Expand All @@ -36,21 +36,22 @@ class Helixware_Mico_Admin {
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
* @var string $version The current version of this plugin.
*/
private $version;

/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {

$this->plugin_name = $plugin_name;
$this->version = $version;
$this->version = $version;

}

Expand Down Expand Up @@ -97,6 +98,11 @@ public function enqueue_scripts() {
*/

wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/helixware-mico-admin.js', array( 'jquery' ), $this->version, false );
// wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/admin.js', array(
// 'jquery',
// 'underscore',
// 'backbone'
// ), $this->version, false );

}

Expand Down
80 changes: 77 additions & 3 deletions src/admin/js/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/admin/js/src/admin.manifest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
var $ = jQuery;

var helixware = window.helixware = window.helixware || {};
helixware.model = helixware.model || {};
helixware.controller = helixware.controller || {};
helixware.view = helixware.view || {};

helixware.controller.Test = require( './controllers/test-controller.js' );
helixware.model.FaceDetectionFragment = require( './models/face-detection-fragment' );
helixware.model.FaceDetectionFragments = require( './models/face-detection-fragments' );
helixware.view.FragmentView = require( './views/fragment-view' );
helixware.view.FragmentsView = require( './views/fragments-view' );
helixware.controller.Test = require( './controllers/test-controller' );
8 changes: 7 additions & 1 deletion src/admin/js/src/controllers/test-controller.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
var x = 10;
var x = 10;

var fragments = new helixware.model.FaceDetectionFragments( [] );
fragments.fetch();

var fragmentsView = new helixware.view.FragmentsView( fragments );

3 changes: 3 additions & 0 deletions src/admin/js/src/models/face-detection-fragment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var FaceDetectionFragment = Backbone.Model.extend( {} );

module.exports = FaceDetectionFragment;
6 changes: 6 additions & 0 deletions src/admin/js/src/models/face-detection-fragments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var FaceDetectionFragments = Backbone.Collection.extend( {
model: helixware.model.FaceDetectionFragment,
url: '/wp-admin/admin-ajax.php?action=hw_face_detection_fragments&id=191'
} );

module.exports = FaceDetectionFragments;
24 changes: 24 additions & 0 deletions src/admin/js/src/views/fragment-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var FragmentView = Backbone.View.extend( {

tagName: 'li',

template: _.template( '<#= start #>' ),

initialize: function ( options ) {

options = options || {};

this.model = options.model || null;
this.parentView = options.parentView || null;

},

render: function () {

this.$el.html( this.template( this.model.attributes ) );

}

} );

module.exports = FragmentView;
23 changes: 23 additions & 0 deletions src/admin/js/src/views/fragments-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var FragmentView = helixware.view.FragmentView;

var FragmentsView = Backbone.View.extend( {

el: 'body',

initialize: function () {

this.listenTo( this.model, 'change', this.render );

},

render: function () {

_.each( this.model, function ( item ) {
this.$el.append( new FragmentView( item.attributes ) );
} );

}

} );

module.exports = FragmentsView;

0 comments on commit 1c05808

Please sign in to comment.