Last active
December 25, 2015 12:19
-
-
Save saintc0d3r/6975960 to your computer and use it in GitHub Desktop.
[Ext.js][ASP NET MVC] Simple SPA using Ext.js & ASP .NET MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.application({ | |
appFolder: '/Extjs/Application', | |
controllers: ['HomeController'], | |
name: AppNamespace, | |
launch: function() { | |
Ext.create('Ext.container.Viewport', { | |
layout: 'fit', | |
items: [{ | |
xtype: 'specialOffers' | |
}] | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define(AppNamespace + '.view.EditSpecialOffersDialog', { | |
extend: 'Ext.window.Window', | |
alias:'widget.editSpecialOffers', | |
title: '.:: Edit Special Offered Item ::.', | |
layout: 'fit', | |
width: 500, | |
autoShow: true, | |
initComponent: function() { | |
this.items = [{ | |
xtype: 'form', | |
items: [{ | |
xtype: 'textfield', | |
anchor: '100%', | |
name: 'Title', | |
fieldLabel: 'Name' | |
}, { | |
xtype: 'numberfield', | |
anchor: '100%', | |
name: 'Price', | |
fieldLabel: 'Price' | |
}] | |
}]; | |
this.buttons = [{ | |
text: 'save', | |
action: 'save' | |
}, { | |
text: 'cancel', | |
scope: this, | |
handler: this.close | |
}]; | |
this.callParent(arguments); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define(AppNamespace + '.controller.HomeController', { | |
extend: 'Ext.app.Controller', | |
views: ['SpecialOffersView', 'EditSpecialOffersDialog'], | |
stores: ['SpecialOffersStore'], | |
models: ['SpecialOfferModel'], | |
init: function () { | |
this.control({ | |
"specialOffers": { | |
celldblclick: function(tableview, td, cellIndex, record) { | |
var view = Ext.widget('editSpecialOffers'); | |
view.down('form').loadRecord(record); | |
}, | |
}, | |
"editSpecialOffers button[action=save]": { | |
click: this.updateUser | |
} | |
}); | |
}, | |
updateUser: function (button) { | |
var dialog = button.up('window'); | |
var form = dialog.down('form'); | |
form.getRecord().set(form.getValues()); | |
dialog.close(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using System.Web.Optimization | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Xtreme Gaming Store</title> | |
<script src="~/Extjs/Application/Constants.js"></script> | |
<script src="~/Extjs/ext-all.js"></script> | |
<link rel="stylesheet" href="~/Extjs/Resources/css/ext-all.css"> | |
</head> | |
<body> | |
<script src="/Extjs/Application/Application.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Web.Http; | |
using Xtreme.Gaming.Store.Domain.Services; | |
using Xtreme.Gaming.Store.Web.Spa.Models; | |
using Xtreme.Gaming.Store.Web.Spa.Models.Product; | |
namespace Xtreme.Gaming.Store.Web.Spa.Controllers | |
{ | |
public class ProductController : ApiController | |
{ | |
private readonly IProductService _productService; | |
public ProductController(IProductService productService) | |
{ | |
_productService = productService; | |
} | |
// | |
// GET: /SpecialOffers | |
[AcceptVerbs("GET")] | |
public IEnumerable<SpecialOffer> SpecialOffers() | |
{ | |
// Get a list of Products which are offered as current discounted items | |
var getSpecialOffersResponse = _productService.GetSpecialOffers(); | |
return getSpecialOffersResponse.IsSuccess ? getSpecialOffersResponse.Products.AsSpecialOffers() : new SpecialOffer[0]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define(AppNamespace + '.model.SpecialOfferModel', { | |
extend: 'Ext.data.Model', | |
fields: [ | |
{ name: 'Id', type: 'int' }, | |
{ name: 'Title', type: 'string' }, | |
{ name: 'Price', type: 'float' } | |
] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define(AppNamespace + '.store.SpecialOffersStore', { | |
extend: 'Ext.data.Store', | |
model: AppNamespace + '.model.SpecialOfferModel', | |
proxy: { | |
type: 'rest', | |
url: '/api/product/specialoffers', | |
reader: { | |
type: 'json', | |
idProperty: 'Id' | |
} | |
}, | |
autoLoad: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define(AppNamespace+ '.view.SpecialOffersView', { | |
extend: 'Ext.grid.Panel', | |
title: 'Special Offers', | |
alias: 'widget.specialOffers', | |
store: 'SpecialOffersStore', | |
initComponent: function () { | |
this.columns = [{ header: 'Name', dataIndex: 'Title', flex: 1 }, | |
{ header: 'Price', dataIndex: 'Price', flex: 2 }]; | |
this.callParent(arguments); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment