Skip to content

Instantly share code, notes, and snippets.

@gorhgorh
Created November 1, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorhgorh/2cded2f536d3bbac8e3f64feda601e7d to your computer and use it in GitHub Desktop.
Save gorhgorh/2cded2f536d3bbac8e3f64feda601e7d to your computer and use it in GitHub Desktop.
define([
'coreJS/adapt',
'coreViews/menuView'
], function(Adapt, MenuView) {
var BoxMenuView = MenuView.extend({
events: {
'click .platformBt' : 'onClickPlatformButton'
},
onClickPlatformButton: function (event) {
if(event && event.preventDefault) event.preventDefault();
console.log('curr model', this.model)
console.log('test model', this.model.get('_isAndroid'))
this.model.set('_isAndroid', !this.model.get('_isAndroid'))
Backbone.history.navigate('#/', {trigger: true});
// Backbone.history.navigate('#/', {trigger: true});
},
postRender: function() {
var _isAndroid = this.model.get('_isAndroid')
console.group('post render')
console.log('_isAndroid', _isAndroid)
console.log('model', this.model)
console.groupEnd()
var nthChild = 0;
this.model.getChildren().each(function(item,index) {
console.log(item.get('_isAndroid'))
var itemForAndroid = item.get('_isAndroid')
if (itemForAndroid !== _isAndroid) {
console.log(_isAndroid ? 'Android' : 'Windows', 'current item', itemForAndroid)
item.set('_isHidden', true)
} else {
item.set('_isHidden', false)
}
if (item.get('_isAvailable')) {
nthChild++;
//console.log('check lock: ' + item.get('_isLocked'));
item.set("_nthChild", nthChild);
this.$('.buttons_menu').append(new BoxMenuItemView({model: item}).$el);
if (!item.get('_isLocked')) {
this.$('.buttons_menu').addClass("part-"+index+"-unlocked")
this.$('.plane,.segment').addClass("part-"+index+"-unlocked")
}
}
});
}
}, {
template: 'boxmenu'
});
var BoxMenuItemView = MenuView.extend({
events: {
'click button' : 'onClickMenuItemButton'
},
className: function() {
var nthChild = this.model.get("_nthChild");
return [
'menu-item',
'menu-item-' + this.model.get('_id') ,
this.model.get('_classes'),
this.model.get('_isVisited') ? 'visited' : '',
this.model.get('_isComplete') ? 'completed' : '',
this.model.get('_isLocked') ? 'locked' : '',
'nth-child-' + nthChild,
nthChild % 2 === 0 ? 'nth-child-even' : 'nth-child-odd'
].join(' ');
},
preRender: function() {
this.model.checkCompletionStatus();
this.model.checkInteractionCompletionStatus();
},
postRender: function() {
var graphic = this.model.get('_graphic');
if (graphic && graphic.src && graphic.src.length > 0) {
this.$el.imageready(_.bind(function() {
this.setReadyStatus();
}, this));
} else {
this.setReadyStatus();
}
},
onClickMenuItemButton: function(event) {
if(event && event.preventDefault) event.preventDefault();
if(this.model.get('_isLocked')) return;
Backbone.history.navigate('#/id/' + this.model.get('_id'), {trigger: true});
}
}, {
template: 'boxmenu-item'
});
Adapt.on('router:menu', function(model) {
$('#wrapper').append(new BoxMenuView({model: model}).$el);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment