Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support of disabled option #50

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/DependencyInjection/FlagbitTableAttributeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('query_builders.xml');
$loader->load('factories.xml');
$loader->load('doctrine.xml');
$loader->load('copiers.xml');
}
}
18 changes: 18 additions & 0 deletions src/Resources/config/copiers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="pcmt.updater.copier.table_attribute"
class="%pim_catalog.updater.copier.value.class%"
parent="pim_catalog.updater.copier.abstract">
<tag name="pim_catalog.updater.copier"/>
<argument type="service" id="pim_standard_format_serializer" />
<argument type="collection">
<argument>flagbit_catalog_table</argument>
</argument>
<argument type="collection">
<argument>flagbit_catalog_table</argument>
</argument>
</service>

</services>
</container>
13 changes: 9 additions & 4 deletions src/Resources/public/js/inittable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define(
function ($, _) {
'use strict';
return {
init: function ($target, columns) {
init: function ($target, columns, editMode) {

var $headerRow = $target.find('thead tr');
if($headerRow[0].innerHTML && $headerRow[0].innerHTML.length != 0){
Expand Down Expand Up @@ -39,7 +39,7 @@ define(

htmlColumns.push(this.createColumn(column, value));
}.bind(this));
$tbody.append(this.createRow(htmlColumns));
$tbody.append(this.createRow(htmlColumns, editMode));
}.bind(this));
},
createColumn: function (column, value) {
Expand All @@ -48,13 +48,18 @@ define(

return td;
},
createRow: function (htmlColumns) {
createRow: function (htmlColumns, editMode) {
var row = $('<tr class="flagbit-table-row AknGrid-bodyRow editable-item-row"></tr>');
row.append($('<td class="AknGrid-bodyCell"><span class="handle"><i class="icon-reorder"></i></span></td>'));
_.each(htmlColumns, function (htmlColumn) {
row.append(htmlColumn);
});
row.append($('<td class="AknGrid-bodyCell"><span class="btn btn-small AknButton AknButton--small AknIconButton--important delete-row"><i class="icon-trash"></i></span></td>'));

if (editMode === 'view') {
row.append($('<td class="AknGrid-bodyCell"></td>'));
} else {
row.append($('<td class="AknGrid-bodyCell"><span class="btn btn-small AknButton AknButton--small AknIconButton--important delete-row"><i class="icon-trash"></i></span></td>'));
}

return row;
},
Expand Down
13 changes: 7 additions & 6 deletions src/Resources/public/js/product/field/table-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ define([
var column = this.convertBackendItem(value);
this.columns[column.id] = column;
}.bind(this));
initTable.init(this.$('.flagbit-table-attribute'), this.columns);
initTable.init(this.$('.flagbit-table-attribute'), this.columns, this.getEditMode());
// initialize dran & drop sorting
this.$('.flagbit-table-values tbody').sortable({
handle: ".handle",
Expand Down Expand Up @@ -107,7 +107,8 @@ define([
text: i18n.getLabel(item.labels, UserContext.get('catalogLocale'), item.code),
config: item.type_config,
type: item.type,
func: this.createColumnFunctions(item)
func: this.createColumnFunctions(item),
editMode: this.getEditMode()
};
},
createColumnFunctions: function(item) {
Expand All @@ -127,10 +128,10 @@ define([

switch (item.type) {
case "text":
fieldTemplate = "<input data-type='<%= column.type %>' type='text' name='<%= column.id %>' class='<%= column.id %> AknTextField' value='<%= _.escape(column.func.formTypeValue(value)) %>' />";
fieldTemplate = "<input data-type='<%= column.type %>' type='text' name='<%= column.id %>' class='<%= column.id %> AknTextField' value='<%= _.escape(column.func.formTypeValue(value)) %>' <%= column.editMode === 'view' ? 'disabled' : '' %>/>";
break;
case "number":
fieldTemplate = "<input data-type='<%= column.type %>' type='number' name='<%= column.id %>' class='<%= column.id %> AknTextField' value='<%= _.escape(column.func.formTypeValue(value)) %>' step='<%= \'is_decimal\' in column.config && true === column.config.is_decimal ? 0.1 : 1 %>' />";
fieldTemplate = "<input data-type='<%= column.type %>' type='number' name='<%= column.id %>' class='<%= column.id %> AknTextField' value='<%= _.escape(column.func.formTypeValue(value)) %>' step='<%= \'is_decimal\' in column.config && true === column.config.is_decimal ? 0.1 : 1 %>' <%= column.editMode === 'view' ? 'disabled' : '' %>/>";
if ('is_decimal' in item.type_config && item.type_config.is_decimal === true) {
parser = function (td) {
return parseFloat($('input', td).val());
Expand All @@ -142,7 +143,7 @@ define([
}
break;
case "select":
fieldTemplate = "<input data-type='<%= column.type %>' type='text' name='<%= column.id %>' class='<%= column.id %>' value='<%= _.escape(column.func.formTypeValue(value)) %>' />";
fieldTemplate = "<input data-type='<%= column.type %>' type='text' name='<%= column.id %>' class='<%= column.id %>' value='<%= _.escape(column.func.formTypeValue(value)) %>' <%= column.editMode === 'view' ? 'disabled' : '' %>/>";

parser = function (td) {
var option = $('input', td).select2('data');
Expand Down Expand Up @@ -174,7 +175,7 @@ define([
}.bind(this);
break;
case "select_from_url":
fieldTemplate = "<input data-type='<%= column.type %>' type='text' name='<%= column.id %>' class='<%= column.id %>' value='<%= _.escape(column.func.formTypeValue(value)) %>' />";
fieldTemplate = "<input data-type='<%= column.type %>' type='text' name='<%= column.id %>' class='<%= column.id %>' value='<%= _.escape(column.func.formTypeValue(value)) %>' <%= column.editMode === 'view' ? 'disabled' : '' %>/>";

parser = function (td) {
var option = $('input', td).select2('data');
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/public/templates/product/field/table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="flagbit-table-attribute asset-gallery">
<header>
<button class="btn btn-success AknButton AknButton--apply item-add pull-right"><%- _.__('flagbit.table_attribute.add_new_row.label') %></button>
<% if(editMode === 'edit') { %>
<button class="btn btn-success AknButton AknButton--apply item-add pull-right"><%- _.__('flagbit.table_attribute.add_new_row.label') %></button>
<% } %>
</header>
<table class="flagbit-table-values attribute-option-view ui-sortable AknGrid AknGrid--unclickable" style="width: 100%; overflow-x: visible">
<thead>
Expand Down