Cataloger.window.UpdateProduct = function(config) {
config = config || {};
Ext.applyIf(config,{
title: _('cataloger.product_update')
,url: Cataloger.config.connectorUrl
,baseParams: {
action: 'mgr/product/update'
}
,fields: [{
xtype: 'hidden'
,name: 'id'
},{
xtype: 'textfield'
,fieldLabel: _('cataloger.name')
,name: 'product_no'
,anchor: '100%'
},{
xtype: 'textfield'
,fieldLabel: _('cataloger.name')
,name: 'product_name'
,anchor: '100%'
},{
xtype: 'textarea'
,fieldLabel: _('cataloger.description')
,name: 'description'
,id:'description'
,anchor: '100%'
}
/*Image grid*/
,{
xtype: 'grid'
,url: Cataloger.config.connectorUrl
,id: 'cataloger.grid.imagelist'
,baseParams: { action: 'mgr/product/getList' }
,fieldLabel: _('cataloger.images')
,name: 'images'
,anchor: '100%'
,fields: ['id','image']
,columns:[{
header:_('id')
,dataIndex: 'id'
,sortable:true
,width:60
},{
header: _('cataloger.image')
,dataIndex: 'image'
,sortable:false
,width:150
,editor:{xtype:'textfield'}
}]
}
]
});
Ext.reg('cataloger-grid-images',Cataloger.grid.Images);
Cataloger.window.UpdateProduct.superclass.constructor.call(this,config);
/*once window activates, add TinyMCE*/
this.on('activate',function(w,e) {
if (typeof Tiny != 'undefined') { MODx.loadRTE('description'); }
},this);
};
Ext.extend(Cataloger.window.UpdateProduct,MODx.Window);
Ext.reg('cataloger-window-product-update',Cataloger.window.UpdateProduct);
Cataloger.window.UpdateProduct = function(config) {
config = config || {};
Ext.applyIf(config,{
title: _('cataloger.product_update')
,url: Cataloger.config.connectorUrl
,baseParams: {
action: 'mgr/product/update'
}
,fields: [{
xtype: 'hidden'
,name: 'id'
},{
xtype: 'textfield'
,fieldLabel: _('cataloger.name')
,name: 'product_no'
,anchor: '100%'
},{
xtype: 'textfield'
,fieldLabel: _('cataloger.name')
,name: 'product_name'
,anchor: '100%'
},{
xtype: 'textarea'
,fieldLabel: _('cataloger.description')
,name: 'description'
,id:'description'
,anchor: '100%'
},{
xtype: 'cataloger-grid-images'
,baseParams: {
// send the product id to your processor,
// or you'll get all images :)
action: 'mgr/product/getList'
,id: config.record.id
}
}]
});
Cataloger.window.UpdateProduct.superclass.constructor.call(this,config);
/*once window activates, add TinyMCE*/
this.on('activate',function(w,e) {
if (typeof Tiny != 'undefined') { MODx.loadRTE('description'); }
},this);
};
Ext.extend(Cataloger.window.UpdateProduct,MODx.Window);
Ext.reg('cataloger-window-product-update',Cataloger.window.UpdateProduct);
Cataloger.grid.Images = function(config) {
config = config || {};
Ext.applyIf(config,{
url: Cataloger.config.connectorUrl
,baseParams: { action: 'mgr/product/getList' }
,fieldLabel: _('cataloger.images')
,anchor: '100%'
,fields: ['id','image']
,columns:[{
header:_('id')
,dataIndex: 'id'
,sortable:true
,width:60
},{
header: _('cataloger.image')
,dataIndex: 'image'
,sortable:false
,width:150
,editor:{xtype:'textfield'}
}]
});
Cataloger.grid.Images.superclass.constructor.call(this,config);
};
Ext.extend(Cataloger.grid.Images,MODx.grid.Grid);
Ext.reg('cataloger-grid-images',Cataloger.grid.Images);
class ProductImageGetListProcessor extends modObjectGetListProcessor {
public $classKey = 'Product';
public $languageTopics = array('cataloger:default');
public $defaultSortField = 'product_no';
public $defaultSortDirection = 'ASC';
public $objectType = 'cataloger.product';
public function prepareQueryBeforeCount(xPDOQuery $c) {
$id = $this->getProperty('id');
if(!empty($id)){
$c->where(array(
'id'=> $id
));
}
return $c;
}
}
return 'ProductImageGetListProcessor';
class ProductImageGetListProcessor extends modObjectGetProcessor {
public $classKey = 'Product';
public $languageTopics = array('cataloger:default');
public $objectType = 'cataloger.product';
public function process() {
$list = array();
$count = 0;
$imageList = $this->object->get('images');
$imageArray = $this->modx->fromJSON($imageList);
foreach ($imageArray as $img) {
// this part really depends on how $img is stored. Array?
$list[] = $img;
$count++;
}
return $this->outputArray($list,$count);
}
}
return 'ProductImageGetListProcessor';