Skip to content

Commit

Permalink
Fix: when page moved , the setModified of type "PAGE_MOVED" has not e…
Browse files Browse the repository at this point in the history
…xcute #943
  • Loading branch information
andrewtelnov committed Sep 7, 2020
1 parent fed3256 commit 972ecfd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
26 changes: 17 additions & 9 deletions src/components/pages-editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ko from "knockout";
import { SurveyHelper, editorLocalization } from '../entries';
import { SurveyHelper, editorLocalization } from "../entries";
import "./pages-editor.scss";
import { PagesEditor } from "../pages-editor";
import { StylesManager } from "../stylesmanager";
Expand All @@ -18,9 +18,7 @@ export class PagesEditorViewModel {
".svd-pages"
);
if (!!pagesElement) {
this.hasScroller(
pagesElement.scrollWidth > pagesElement.offsetWidth
);
this.hasScroller(pagesElement.scrollWidth > pagesElement.offsetWidth);
}
}, 100);

Expand Down Expand Up @@ -55,7 +53,7 @@ export class PagesEditorViewModel {
pagesElement.offsetLeft -
pagesElement.offsetWidth / 2;
this.updateMenuPosition();
}
};

onWheel(model, event) {
var pagesElement = model.element.querySelector(".svd-pages");
Expand Down Expand Up @@ -86,7 +84,9 @@ export class PagesEditorViewModel {

getPageClass = (page) => {
var result =
page === this.model.selectedPage() ? "svd_selected_page svd-light-bg-color" : "";
page === this.model.selectedPage()
? "svd_selected_page svd-light-bg-color"
: "";

if (this.model.pages.indexOf(page) !== this.model.pages.length - 1) {
result += " svd-border-right-none";
Expand All @@ -96,7 +96,8 @@ export class PagesEditorViewModel {
};

getPageMenuIconClass = (page) => {
var baseIconName = StylesManager.currentTheme() === "modern" ? "dots" : "gear";
var baseIconName =
StylesManager.currentTheme() === "modern" ? "dots" : "gear";
return page === this.model.selectedPage() && this.model.isActive()
? "icon-" + baseIconName + "active"
: "icon-" + baseIconName;
Expand All @@ -110,12 +111,14 @@ export class PagesEditorViewModel {
};

public movingPage = null;
private movedFrom: number = -1;
get sortableOptions() {
return {
handle: ".svd-page-name",
animation: 150,
onStart: () => {
this.movingPage = null;
this.movedFrom = -1;
this.model.creator.undoRedoManager.startTransaction(
"pages drag drop transaction"
);
Expand All @@ -126,12 +129,17 @@ export class PagesEditorViewModel {
this.model.blockPagesRebuilt(false);
this.model.creator.undoRedoManager.stopTransaction();
if (!!this.movingPage) {
this.model.selectedPage(this.movingPage);
this.model.movePage(this.movingPage, this.movedFrom);
}
},
onUpdate: (evt, itemV) => {
this.movingPage = itemV;
if (SurveyHelper.moveItemInArray(this.model.pages, itemV, evt.newIndex)) {
if (this.movedFrom < 0) {
this.movedFrom = this.model.pages.indexOf(this.movingPage);
}
if (
SurveyHelper.moveItemInArray(this.model.pages, itemV, evt.newIndex)
) {
// Remove sortables "unbound" element
evt.item.parentNode.removeChild(evt.item);
}
Expand Down
7 changes: 2 additions & 5 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1857,11 +1857,8 @@ export class SurveyCreator implements ISurveyObjectEditorOptions {
public getLocString(str: string) {
return editorLocalization.getString(str);
}
public movePage = (indexFrom: number, indexTo: number) => {
var page = <Survey.Page>this.survey.pages[indexTo];
this.surveyObjects.survey = null; // TODO may be we don't need this hack
this.surveyObjects.survey = this.survey;
this.selectedElement = page;
public movePage = (page: Survey.PageModel, indexFrom: number) => {
var indexTo = this.survey.pages.indexOf(page);
this.setModified({
type: "PAGE_MOVED",
page: page,
Expand Down
5 changes: 5 additions & 0 deletions src/pages-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export class PagesEditor {
this.creator.deletePage();
};

movePage = (page: Survey.PageModel, indexFrom: number) => {
this.selectedPage(page);
this.creator.movePage(page, indexFrom);
};

showPageSettings(page: Survey.PageModel) {
this.creator.showQuestionEditor(page);
}
Expand Down

0 comments on commit 972ecfd

Please sign in to comment.