|
207 | 207 | };
|
208 | 208 |
|
209 | 209 | GridStackEngine.prototype.can_move_node = function (node, x, y, width, height) {
|
210 |
| - if (!this.height) |
| 210 | + var has_locked = Boolean(_.find(this.nodes, function (n) { return n.locked })); |
| 211 | + |
| 212 | + if (!this.height && !has_locked) |
211 | 213 | return true;
|
212 | 214 |
|
213 | 215 | var cloned_node;
|
|
220 | 222 |
|
221 | 223 | clone.move_node(cloned_node, x, y, width, height);
|
222 | 224 |
|
223 |
| - return clone.get_grid_height() <= this.height; |
| 225 | + var res = true; |
| 226 | + |
| 227 | + if (has_locked) |
| 228 | + res &= !Boolean(_.find(clone.nodes, function (n) { return n != cloned_node && Boolean(n.locked) && Boolean(n._dirty); })); |
| 229 | + if (this.height) |
| 230 | + res &= clone.get_grid_height() <= this.height; |
| 231 | + |
| 232 | + return res; |
224 | 233 | };
|
225 | 234 |
|
226 | 235 | GridStackEngine.prototype.can_be_placed_with_respect_to_height = function (node) {
|
|
415 | 424 | auto_position: el.attr('data-gs-auto-position'),
|
416 | 425 | no_resize: el.attr('data-gs-no-resize'),
|
417 | 426 | no_move: el.attr('data-gs-no-move'),
|
| 427 | + locked: el.attr('data-gs-locked'), |
418 | 428 | el: el
|
419 | 429 | });
|
420 | 430 | el.data('_gridstack_node', node);
|
|
469 | 479 | drag: function (event, ui) {
|
470 | 480 | var x = Math.round(ui.position.left / cell_width),
|
471 | 481 | y = Math.floor((ui.position.top + cell_height/2) / cell_height);
|
472 |
| - if (self.opts.height && !self.grid.can_move_node(node, x, y, node.width, node.height)) { |
| 482 | + if (!self.grid.can_move_node(node, x, y, node.width, node.height)) { |
473 | 483 | return;
|
474 | 484 | }
|
475 | 485 | self.grid.move_node(node, x, y);
|
|
486 | 496 | resize: function (event, ui) {
|
487 | 497 | var width = Math.round(ui.size.width / cell_width),
|
488 | 498 | height = Math.round(ui.size.height / cell_height);
|
489 |
| - if (self.opts.height && !self.grid.can_move_node(node, node.x, node.y, width, height)) { |
| 499 | + if (!self.grid.can_move_node(node, node.x, node.y, width, height)) { |
490 | 500 | return;
|
491 | 501 | }
|
492 | 502 | self.grid.move_node(node, node.x, node.y, width, height);
|
|
501 | 511 | if (node.no_resize || this._is_one_column_mode()) {
|
502 | 512 | el.resizable('disable');
|
503 | 513 | }
|
| 514 | + |
| 515 | + el.attr('data-gs-locked', node.locked ? 'yes' : null); |
504 | 516 | };
|
505 | 517 |
|
506 | 518 | GridStack.prototype.set_animation = function (enable) {
|
|
585 | 597 | return this;
|
586 | 598 | };
|
587 | 599 |
|
| 600 | + GridStack.prototype.locked = function (el, val) { |
| 601 | + el = $(el); |
| 602 | + el.each(function (index, el) { |
| 603 | + el = $(el); |
| 604 | + var node = el.data('_gridstack_node'); |
| 605 | + if (typeof node == 'undefined') { |
| 606 | + return; |
| 607 | + } |
| 608 | + |
| 609 | + node.locked = (val || false); |
| 610 | + el.attr('data-gs-locked', node.locked ? 'yes' : null); |
| 611 | + }); |
| 612 | + return this; |
| 613 | + }; |
| 614 | + |
588 | 615 | GridStack.prototype._update_element = function (el, callback) {
|
589 | 616 | el = $(el).first();
|
590 | 617 | var node = el.data('_gridstack_node');
|
|
0 commit comments