Skip to content

Commit

Permalink
fix bug: item content is sync with table row
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofox3 committed Sep 20, 2013
1 parent b1d6033 commit edb304e
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 119 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@

## v0.1.3
* reset the selectionAll state on page change

## v0.1.4
* fix sync issue with the content of an item and its smart-table row
160 changes: 83 additions & 77 deletions Smart-Table.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
})(window, angular);



/* Directives */
(function (angular) {
"use strict";
Expand Down Expand Up @@ -199,16 +198,21 @@
link: function (scope, element) {
var
column = scope.column,
isSimpleCell = !column.isEditable,
row = scope.dataRow,
format = filter('format'),
getter = parse(column.map),
childScope;

//can be useful for child directives
scope.formatedValue = format(getter(row), column.formatFunction, column.formatParameter);
scope.$watch('dataRow', function (value) {
scope.formatedValue = format(getter(row), column.formatFunction, column.formatParameter);
if (isSimpleCell === true) {
element.text(scope.formatedValue);
}
}, true);

function defaultContent() {
//clear content
if (column.isEditable) {
element.html('<div editable-cell="" row="dataRow" column="column" type="column.type"></div>');
compile(element.contents())(scope);
Expand All @@ -223,6 +227,8 @@
//we have to load the template (and cache it) : a kind of ngInclude
http.get(value, {cache: templateCache}).success(function (response) {

isSimpleCell = false;

//create a scope
childScope = scope.$new();
//compile the element with its new content and new scope
Expand Down Expand Up @@ -268,7 +274,9 @@

//init values
scope.isEditMode = false;
scope.value = getter(scope.row);
scope.$watch('row', function () {
scope.value = getter(scope.row);
}, true);


scope.submit = function () {
Expand All @@ -285,8 +293,8 @@
scope.isEditMode = scope.isEditMode !== true;
};

scope.$watch('isEditMode', function (newValue, oldValue) {
if (newValue) {
scope.$watch('isEditMode', function (newValue) {
if (newValue === true) {
input[0].select();
input[0].focus();
}
Expand Down Expand Up @@ -604,87 +612,86 @@
})(angular);



angular.module('smartTable.templates', ['partials/defaultCell.html', 'partials/defaultHeader.html', 'partials/editableCell.html', 'partials/globalSearchCell.html', 'partials/pagination.html', 'partials/selectAllCheckbox.html', 'partials/selectionCheckbox.html', 'partials/smartTable.html']);

angular.module("partials/defaultCell.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/defaultCell.html",
"{{formatedValue}}");
angular.module("partials/defaultCell.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/defaultCell.html",
"{{formatedValue}}");
}]);

angular.module("partials/defaultHeader.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/defaultHeader.html",
"<span class=\"header-content\" ng-class=\"{'sort-ascent':column.reverse==true,'sort-descent':column.reverse==false}\">{{column.label}}</span>");
angular.module("partials/defaultHeader.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/defaultHeader.html",
"<span class=\"header-content\" ng-class=\"{'sort-ascent':column.reverse==true,'sort-descent':column.reverse==false}\">{{column.label}}</span>");
}]);

angular.module("partials/editableCell.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/editableCell.html",
"<div ng-dblclick=\"toggleEditMode($event)\">\n" +
" <span ng-hide=\"isEditMode\">{{value | format:column.formatFunction:column.formatParameter}}</span>\n" +
"\n" +
" <form ng-submit=\"submit()\" ng-show=\"isEditMode\" name=\"myForm\">\n" +
" <input name=\"myInput\" ng-model=\"value\" type=\"type\" input-type/>\n" +
" </form>\n" +
"</div>");
angular.module("partials/editableCell.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/editableCell.html",
"<div ng-dblclick=\"toggleEditMode($event)\">\n" +
" <span ng-hide=\"isEditMode\">{{value | format:column.formatFunction:column.formatParameter}}</span>\n" +
"\n" +
" <form ng-submit=\"submit()\" ng-show=\"isEditMode\" name=\"myForm\">\n" +
" <input name=\"myInput\" ng-model=\"value\" type=\"type\" input-type/>\n" +
" </form>\n" +
"</div>");
}]);

angular.module("partials/globalSearchCell.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/globalSearchCell.html",
"<label>Search :</label>\n" +
"<input type=\"text\" ng-model=\"searchValue\"/>");
angular.module("partials/globalSearchCell.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/globalSearchCell.html",
"<label>Search :</label>\n" +
"<input type=\"text\" ng-model=\"searchValue\"/>");
}]);

angular.module("partials/pagination.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/pagination.html",
"<div class=\"pagination\">\n" +
" <ul>\n" +
" <li ng-repeat=\"page in pages\" ng-class=\"{active: page.active, disabled: page.disabled}\"><a\n" +
" ng-click=\"selectPage(page.number)\">{{page.text}}</a></li>\n" +
" </ul>\n" +
"</div> ");
angular.module("partials/pagination.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/pagination.html",
"<div class=\"pagination\">\n" +
" <ul>\n" +
" <li ng-repeat=\"page in pages\" ng-class=\"{active: page.active, disabled: page.disabled}\"><a\n" +
" ng-click=\"selectPage(page.number)\">{{page.text}}</a></li>\n" +
" </ul>\n" +
"</div> ");
}]);

angular.module("partials/selectAllCheckbox.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/selectAllCheckbox.html",
"<input class=\"smart-table-select-all\" type=\"checkbox\" ng-model=\"holder.isAllSelected\"/>");
angular.module("partials/selectAllCheckbox.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/selectAllCheckbox.html",
"<input class=\"smart-table-select-all\" type=\"checkbox\" ng-model=\"holder.isAllSelected\"/>");
}]);

angular.module("partials/selectionCheckbox.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/selectionCheckbox.html",
"<input type=\"checkbox\" ng-model=\"dataRow.isSelected\" stop-event=\"click\"/>");
angular.module("partials/selectionCheckbox.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/selectionCheckbox.html",
"<input type=\"checkbox\" ng-model=\"dataRow.isSelected\" stop-event=\"click\"/>");
}]);

angular.module("partials/smartTable.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("partials/smartTable.html",
"<table class=\"smart-table\">\n" +
" <thead>\n" +
" <tr class=\"smart-table-global-search-row\" ng-show=\"isGlobalSearchActivated\">\n" +
" <td class=\"smart-table-global-search\" column-span=\"{{columns.length}}\" colspan=\"{{columnSpan}}\">\n" +
" </td>\n" +
" </tr>\n" +
" <tr class=\"smart-table-header-row\">\n" +
" <th ng-repeat=\"column in columns\" ng-include=\"column.headerTemplateUrl\"\n" +
" class=\"smart-table-header-cell {{column.headerClass}}\" scope=\"col\">\n" +
" </th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr ng-repeat=\"dataRow in displayedCollection\" ng-class=\"{selected:dataRow.isSelected}\"\n" +
" class=\"smart-table-data-row\">\n" +
" <td ng-repeat=\"column in columns\" class=\"smart-table-data-cell {{column.cellClass}}\"></td>\n" +
" </tr>\n" +
" </tbody>\n" +
" <tfoot ng-show=\"isPaginationEnabled\">\n" +
" <tr class=\"smart-table-footer-row\">\n" +
" <td colspan=\"{{columns.length}}\">\n" +
" <div pagination-smart-table=\"\" num-pages=\"numberOfPages\" max-size=\"maxSize\" current-page=\"currentPage\"></div>\n" +
" </td>\n" +
" </tr>\n" +
" </tfoot>\n" +
"</table>\n" +
"\n" +
"\n" +
"");
angular.module("partials/smartTable.html", []).run(["$templateCache", function ($templateCache) {
$templateCache.put("partials/smartTable.html",
"<table class=\"smart-table\">\n" +
" <thead>\n" +
" <tr class=\"smart-table-global-search-row\" ng-show=\"isGlobalSearchActivated\">\n" +
" <td class=\"smart-table-global-search\" column-span=\"{{columns.length}}\" colspan=\"{{columnSpan}}\">\n" +
" </td>\n" +
" </tr>\n" +
" <tr class=\"smart-table-header-row\">\n" +
" <th ng-repeat=\"column in columns\" ng-include=\"column.headerTemplateUrl\"\n" +
" class=\"smart-table-header-cell {{column.headerClass}}\" scope=\"col\">\n" +
" </th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr ng-repeat=\"dataRow in displayedCollection\" ng-class=\"{selected:dataRow.isSelected}\"\n" +
" class=\"smart-table-data-row\">\n" +
" <td ng-repeat=\"column in columns\" class=\"smart-table-data-cell {{column.cellClass}}\"></td>\n" +
" </tr>\n" +
" </tbody>\n" +
" <tfoot ng-show=\"isPaginationEnabled\">\n" +
" <tr class=\"smart-table-footer-row\">\n" +
" <td colspan=\"{{columns.length}}\">\n" +
" <div pagination-smart-table=\"\" num-pages=\"numberOfPages\" max-size=\"maxSize\" current-page=\"currentPage\"></div>\n" +
" </td>\n" +
" </tr>\n" +
" </tfoot>\n" +
"</table>\n" +
"\n" +
"\n" +
"");
}]);

(function (angular) {
Expand Down Expand Up @@ -726,7 +733,7 @@ angular.module("partials/smartTable.html", []).run(["$templateCache", function($
* @param index
* @param item
*/
insertAt = function (arrayRef, index, item) {
insertAt = function (arrayRef, index, item) {
if (index >= 0 && index < arrayRef.length) {
arrayRef.splice(index, 0, item);
} else {
Expand All @@ -740,7 +747,7 @@ angular.module("partials/smartTable.html", []).run(["$templateCache", function($
* @param oldIndex
* @param newIndex
*/
moveAt = function (arrayRef, oldIndex, newIndex) {
moveAt = function (arrayRef, oldIndex, newIndex) {
var elementToMove;
if (oldIndex >= 0 && oldIndex < arrayRef.length && newIndex >= 0 && newIndex < arrayRef.length) {
elementToMove = arrayRef.splice(oldIndex, 1)[0];
Expand All @@ -756,7 +763,7 @@ angular.module("partials/smartTable.html", []).run(["$templateCache", function($
* @param reverse
* @returns {*}
*/
sort = function (arrayRef, sortAlgorithm, predicate, reverse) {
sort = function (arrayRef, sortAlgorithm, predicate, reverse) {

if (!sortAlgorithm || !angular.isFunction(sortAlgorithm)) {
return arrayRef;
Expand All @@ -772,7 +779,7 @@ angular.module("partials/smartTable.html", []).run(["$templateCache", function($
* @param predicate
* @returns {*}
*/
filter = function (arrayRef, filterAlgorithm, predicate) {
filter = function (arrayRef, filterAlgorithm, predicate) {
if (!filterAlgorithm || !angular.isFunction(filterAlgorithm)) {
return arrayRef;
} else {
Expand All @@ -787,7 +794,7 @@ angular.module("partials/smartTable.html", []).run(["$templateCache", function($
* @param length
* @returns {*}
*/
fromTo = function (arrayRef, min, length) {
fromTo = function (arrayRef, min, length) {

var out = [],
limit,
Expand Down Expand Up @@ -822,7 +829,6 @@ angular.module("partials/smartTable.html", []).run(["$templateCache", function($
})(angular);



(function (angular) {
angular.module('ui.bootstrap.pagination.smartTable', ['smartTable.templateUrlList'])

Expand Down
Loading

0 comments on commit edb304e

Please sign in to comment.