first commit
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use_helper('stCategory');
|
||||
|
||||
function object_category(appProductAttribute $app_product_attribute, $method, $options = array())
|
||||
{
|
||||
$context = sfContext::getInstance();
|
||||
|
||||
$request = $context->getRequest();
|
||||
|
||||
$defaults = array();
|
||||
|
||||
if ($request->hasErrors())
|
||||
{
|
||||
$parameters = $request->getParameter($options['control_name']);
|
||||
$defaults = stJQueryToolsHelper::parseTokensFromRequest($parameters);
|
||||
}
|
||||
elseif ($app_product_attribute->isNew())
|
||||
{
|
||||
$filters = $context->getUser()->getAttributeHolder()->getAll('soteshop/stAdminGenerator/appProductAttributeBackend/list/filters');
|
||||
|
||||
if (isset($filters['category']) && $filters['category'])
|
||||
{
|
||||
$c = new Criteria();
|
||||
|
||||
$c->add(CategoryPeer::ID, $filters['category']);
|
||||
|
||||
$defaults = ProductPeer::doSelectCategoriesTokens($c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$defaults = appProductAttributePeer::doSelectCategoriesForTokenInput($app_product_attribute);
|
||||
}
|
||||
|
||||
return category_picker_input_tag($options['control_name'], $defaults, array('show_default' => false, 'allow_assign_parents_only' => true, 'allow_assign_root' => true));
|
||||
}
|
||||
|
||||
function app_product_attribute_variant_tokenizer(appProductAttribute $attribute, Product $product)
|
||||
{
|
||||
static $fc = null;
|
||||
|
||||
if (null === $fc)
|
||||
{
|
||||
$fc = new stFunctionCache('appProductAttributeVariant');
|
||||
}
|
||||
|
||||
$id = $attribute->getId();
|
||||
|
||||
$type = $attribute->getType();
|
||||
|
||||
$dc = new Criteria();
|
||||
|
||||
$dc->addJoin(appProductAttributeVariantPeer::ID, appProductAttributeHasVariantPeer::VARIANT_ID);
|
||||
|
||||
$dc->addJoin(appProductAttributeVariantPeer::ID, appProductAttributeVariantHasProductPeer::VARIANT_ID);
|
||||
|
||||
$dc->add(appProductAttributeVariantHasProductPeer::PRODUCT_ID, $product->getId());
|
||||
|
||||
$dc->add(appProductAttributeHasVariantPeer::ATTRIBUTE_ID, $attribute->getId());
|
||||
|
||||
$vc = new Criteria();
|
||||
|
||||
$vc->addJoin(appProductAttributeVariantPeer::ID, appProductAttributeHasVariantPeer::VARIANT_ID);
|
||||
|
||||
$vc->add(appProductAttributeHasVariantPeer::ATTRIBUTE_ID, $id);
|
||||
|
||||
if ($type == 'B')
|
||||
{
|
||||
$checked = appProductAttributeVariantPeer::doCount($dc);
|
||||
|
||||
$vc->addSelectColumn(appProductAttributeVariantPeer::ID);
|
||||
|
||||
$variant_id = appProductAttributeVariantPeer::doSelectSingleScalar($vc);
|
||||
|
||||
return checkbox_tag('app_product_attribute_variant['.$id.']', $variant_id, $checked, array('id' => 'token-input-app_product_attribute_variant_'.$id));
|
||||
}
|
||||
elseif ($type == 'T' || $type == 'C' || $type == 'S')
|
||||
{
|
||||
$defaults = appProductAttributeVariantPeer::doSelectTokens($dc, $type);
|
||||
|
||||
$variants = $fc->cacheCall(array('appProductAttributeVariantPeer', 'doSelectTokens'), array($vc, $type));
|
||||
|
||||
$tokenizer = array(
|
||||
'createNew' => $type != 'C',
|
||||
'preventDuplicates' => true,
|
||||
'hintText' => __('Wpisz nazwę szukanego wariantu'),
|
||||
'tokenLimit' => 20,
|
||||
'animateDropdown' => false,
|
||||
'propertyToSearch' => $type == 'C' ? 'name' : 'value'
|
||||
);
|
||||
|
||||
if ($type == 'C')
|
||||
{
|
||||
$tokenizer['resultsFormatter'] = _variant_tokens_results_formatter();
|
||||
$tokenizer['tokenFormatter'] = _variant_tokens_token_formatter();
|
||||
}
|
||||
elseif ($type == 'S')
|
||||
{
|
||||
$tokenizer['onBeforeAdd'] = _variant_tokens_on_add();
|
||||
}
|
||||
|
||||
|
||||
return st_tokenizer_input_tag(
|
||||
'app_product_attribute_variant['.$id.']',
|
||||
$variants,
|
||||
$defaults,
|
||||
array('tokenizer' => $tokenizer)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function _variant_tokens_results_formatter()
|
||||
{
|
||||
return "function (item, token_input, query) {
|
||||
if (item['type'] == 'C') {
|
||||
var style = 'background-color: #'+item['value'];
|
||||
} else {
|
||||
var style = 'background-image: url(/'+item['value']+')';
|
||||
}
|
||||
return '<li class=\"app_variant_token\"><div class=\"background\"><div style=\"'+style+'\"></div></div><span class=\"name\">'+item['name']+'</span></li>';
|
||||
}";
|
||||
}
|
||||
|
||||
function _variant_tokens_token_formatter()
|
||||
{
|
||||
return "function (item, token_input, query) {
|
||||
if (item['type'] == 'C') {
|
||||
var style = 'background-color: #'+item['value'];
|
||||
} else {
|
||||
var style = 'background-image: url(/'+item['value']+')';
|
||||
}
|
||||
return '<li class=\"app_variant_token\"><div class=\"background\"><div style=\"'+style+'\"></div></div><span class=\"name\">'+item['name']+'</span></li>';
|
||||
}";
|
||||
}
|
||||
|
||||
function _variant_tokens_on_add()
|
||||
{
|
||||
return "function(item) {
|
||||
|
||||
$(this).data('tokenInputObject').clear();
|
||||
|
||||
}";
|
||||
}
|
||||
Reference in New Issue
Block a user