|
24 | 24 |
|
25 | 25 | var module = angular.module("tableview", []);
|
26 | 26 |
|
27 |
| - module.provider("$tableView", function () { |
| 27 | + module.provider("$tableView", function tableViewProvider() { |
28 | 28 |
|
29 | 29 | var that = this;
|
30 | 30 |
|
|
34 | 34 | };
|
35 | 35 |
|
36 | 36 | }).directive("tableviewAutofocus", function tableviewAutofocusDirective($timeout) {
|
| 37 | + // noinspection JSUnusedGlobalSymbols |
37 | 38 | return {
|
38 | 39 | restrict: "A",
|
39 | 40 | link: function ($scope, $element, $attributes) {
|
|
48 | 49 | };
|
49 | 50 | }).directive("tableview", function tableviewDirective($compile, $http, $templateCache, $tableView) {
|
50 | 51 |
|
| 52 | + var isString = function isString(value) { |
| 53 | + return ('' + value) === value; |
| 54 | + }; |
| 55 | + |
| 56 | + var isUndefined = function isUndefined(value) { |
| 57 | + return void 0 === value; |
| 58 | + }; |
| 59 | + |
| 60 | + var isObject = function isObject(value) { |
| 61 | + return null !== value && 'object' === typeof value; |
| 62 | + }; |
| 63 | + |
| 64 | + var isBoolean = function isBoolean(value) { |
| 65 | + return true === value || false === value; |
| 66 | + }; |
| 67 | + |
| 68 | + var isFunction = function isFunction(value) { |
| 69 | + return 'function' === typeof value; |
| 70 | + }; |
| 71 | + |
| 72 | + var isNumber = function isNumber(value) { |
| 73 | + return (value - 0) === value; |
| 74 | + }; |
| 75 | + |
51 | 76 | var MODULE_NAME = "angular.tableview";
|
52 | 77 |
|
53 | 78 | var getModuleURL = function getModuleURL() {
|
|
215 | 240 | }
|
216 | 241 |
|
217 | 242 | if (
|
218 |
| - "string" == typeof $scope.tableview.request.like[field] |
| 243 | + isString($scope.tableview.request.like[field]) |
219 | 244 | &&
|
220 | 245 | !$scope.tableview.request.like[field].trim()
|
221 | 246 | ) {
|
|
235 | 260 | return {message: "", status: true};
|
236 | 261 | };
|
237 | 262 |
|
238 |
| - if (!column.editable || "object" !== typeof column.editable) { |
| 263 | + if (!column.editable || !isObject(column.editable)) { |
239 | 264 | $mode.validation = valid();
|
240 | 265 | return true;
|
241 |
| - } else if ("function" !== typeof column.editable.validate) { |
| 266 | + } else if (!isFunction(column.editable.validate)) { |
242 | 267 | column.editable.validate = valid;
|
243 | 268 | }
|
244 | 269 |
|
245 | 270 | var result = column.editable.validate(column, $row, column.field, $mode.value);
|
246 |
| - if ("boolean" === typeof result) { |
| 271 | + if (isBoolean(result)) { |
247 | 272 | result = result ? valid() : {message: "", status: false};
|
248 | 273 | }
|
249 | 274 |
|
250 |
| - result = (result && "object" === typeof result) ? result : {}; |
| 275 | + result = (result && isObject(result) ? result : {}); |
251 | 276 | result.status = !!result.status;
|
252 |
| - result.message = "string" === typeof result.message ? result.message : ""; |
| 277 | + result.message = isString(result.message) ? result.message : ""; |
253 | 278 | $mode.validation = result;
|
254 | 279 |
|
255 | 280 | return result.status;
|
|
267 | 292 | $mode.value = $row[column.field];
|
268 | 293 | }
|
269 | 294 |
|
270 |
| - if ( |
271 |
| - validation |
272 |
| - && changed |
273 |
| - && column.editable |
274 |
| - && "object" === typeof column.editable |
275 |
| - && "function" === typeof column.editable.change |
276 |
| - ) { |
| 295 | + if (validation && changed && isObject(column.editable) && isFunction(column.editable.change)) { |
277 | 296 | column.editable.change(column, $row, column.field, $row[column.field]);
|
278 | 297 | }
|
279 | 298 |
|
|
302 | 321 |
|
303 | 322 | $scope.getRowSelectionIndex = function getRowSelectionIndex($row) {
|
304 | 323 | if (
|
305 |
| - "string" !== typeof $scope.tableview.selectableBy |
| 324 | + isString($scope.tableview.selectableBy) |
306 | 325 | ||
|
307 | 326 | !$scope.tableview.selectableBy.trim().length
|
308 | 327 | ||
|
309 |
| - "undefined" === typeof $row[$scope.tableview.selectableBy] |
| 328 | + isUndefined($row[$scope.tableview.selectableBy]) |
310 | 329 | ) {
|
311 | 330 | return;
|
312 | 331 | }
|
313 | 332 |
|
314 | 333 | var key = $scope.tableview.selectableBy;
|
315 | 334 | var val = $row[$scope.tableview.selectableBy];
|
316 | 335 |
|
317 |
| - for (var i = 0; i < $scope.tableview.selection.length; i+=1) { |
| 336 | + for (var i = 0; i < $scope.tableview.selection.length; i += 1) { |
318 | 337 | if ($scope.tableview.selection[i][key] == val) {
|
319 | 338 | return i * 1;
|
320 | 339 | }
|
|
327 | 346 | $scope.switchRowSelection = function switchRowSelection($row, sign) {
|
328 | 347 |
|
329 | 348 | var index = $scope.getRowSelectionIndex($row);
|
330 |
| - if ("number" !== typeof index) { |
| 349 | + if (!isNumber(index)) { |
331 | 350 | return;
|
332 | 351 | }
|
333 | 352 |
|
334 |
| - if ("boolean" === typeof sign) { |
| 353 | + if (isBoolean(sign)) { |
335 | 354 | if (index < 0 && sign) {
|
336 | 355 | $scope.tableview.selection.push(angular.copy($row));
|
337 | 356 | } else if (index >= 0 && !sign) {
|
|
349 | 368 |
|
350 | 369 | $scope.isRowSelected = function isRowSelected($row) {
|
351 | 370 | var i = $scope.getRowSelectionIndex($row);
|
352 |
| - return !!("number" === typeof i && i >= 0); |
| 371 | + return !!(isNumber(i) && 0 <= i); |
353 | 372 | };
|
354 | 373 |
|
355 | 374 | $scope.isRowsSelected = function isRowsSelected() {
|
|
376 | 395 | $scope.themeTemplateName = function themeTemplateName(name) {
|
377 | 396 | if ($scope.theme && name) {
|
378 | 397 | name = ["tableview", $scope.theme, name].join(".");
|
379 |
| - return "string" === typeof $templateCache.get(name) ? name : undefined; |
| 398 | + return isString($templateCache.get(name)) ? name : undefined; |
380 | 399 | }
|
381 | 400 | };
|
382 | 401 |
|
|
392 | 411 | // theme.template
|
393 | 412 | // default
|
394 | 413 |
|
395 |
| - var $0 = "undefined" !== typeof $index && $scope.tableview.columns[$index] && $scope.tableview.columns[$index].template ? $scope.tableview.columns[$index].template : {}; |
396 |
| - var $1 = $scope.tableview.template && "object" === typeof $scope.tableview.template ? $scope.tableview.template : {}; |
397 |
| - var $2 = $scope.$provider.template && "object" === typeof $scope.$provider.template ? $scope.$provider.template : {}; |
| 414 | + var $0 = (!isUndefined($index) && $scope.tableview.columns[$index] && $scope.tableview.columns[$index].template ? $scope.tableview.columns[$index].template : {}); |
| 415 | + var $1 = ($scope.tableview.template && isObject($scope.tableview.template) ? $scope.tableview.template : {}); |
| 416 | + var $2 = ($scope.$provider.template && isObject($scope.$provider.template) ? $scope.$provider.template : {}); |
398 | 417 | var tpl = $0[name] || $1[name] || $2[name] || $scope.themeTemplateName(name) || $scope.defaultTemplateName(name);
|
399 | 418 |
|
400 |
| - return "string" === typeof $templateCache.get(tpl) ? tpl : undefined; |
| 419 | + return (isString($templateCache.get(tpl)) ? tpl : undefined); |
401 | 420 |
|
402 | 421 | };
|
403 | 422 |
|
404 | 423 | $scope.exec();
|
| 424 | + |
405 | 425 | };
|
406 | 426 | }
|
407 | 427 | };
|
|
0 commit comments