{"size": 2039, "ext": "js", "max_stars_repo_path": "app/ns-framework-modules-category/file-system/update/update-page.js", "max_stars_repo_name": "JackBaltzer/nativescript-sdk-examples-js", "max_stars_repo_stars_event_min_datetime": "2018-05-31T06:43:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T06:46:57.000Z", "max_issues_repo_path": "app/ns-framework-modules-category/file-system/update/update-page.js", "max_issues_repo_name": "JackBaltzer/nativescript-sdk-examples-js", "max_issues_repo_issues_event_min_datetime": "2018-06-22T06:45:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:48.000Z", "max_forks_repo_path": "app/ns-framework-modules-category/file-system/update/update-page.js", "max_forks_repo_name": "JackBaltzer/nativescript-sdk-examples-js", "max_forks_repo_forks_event_min_datetime": "2018-05-02T10:27:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T19:12:57.000Z"}
{"max_stars_count": 55, "max_issues_count": 154, "max_forks_count": 186, "avg_line_length": 30.8939393939, "max_line_length": 80, "alphanum_fraction": 0.5649828347}
import { Dialogs, Observable, knownFolders } from "@nativescript/core";
let file;
let myFolder;
export function onNavigatingTo(args) {
    const page = args.object;
    const vm = new Observable();

    const documents = knownFolders.documents();
    file = documents.getFile("TestFileName.txt");
    myFolder = documents.getFolder("TestFolderName");

    vm.set("fileName", "TestFileName");
    vm.set("fileSuccessMessage", "");
    vm.set("folderName", "TestFolderName");
    vm.set("folderSuccessMessage", "");
    vm.set("isItemVisible", false);
    vm.set("isFolderItemVisible", false);

    page.bindingContext = vm;
}

export function onFileRename(args) {
    const page = args.object.page;
    const vm = page.bindingContext;
    // >> fs-update-rename-file-code
    const fileName = vm.get("fileName");
    file.rename(`${fileName}.txt`)
        .then((res) => {
            // File Successfully Renamed.
            vm.set("fileSuccessMessage", `File renamed to:  ${fileName}.txt`);
            vm.set("isItemVisible", true);
        }).catch((err) => {
            // Error!
            console.log("Error: ");
            console.log(err);
            Dialogs.alert(err)
            .then(() => {
                console.log("Dialog closed!");
            });
        });
    // << fs-update-rename-file-code
}

export function onFolderRename(args) {
    const page = args.object.page;
    const vm = page.bindingContext;
    // >> fs-update-rename-folder-code
    const folderName = vm.get("folderName");
    myFolder.rename(folderName)
        .then((res) => {
            // Folder Successfully Renamed.
            vm.set("folderSuccessMessage", `Folder renamed to:  ${folderName}`);
            vm.set("isFolderItemVisible", true);
        }).catch((err) => {
            // Error!
            console.log("Error: ");
            console.log(err);
            Dialogs.alert(err)
            .then(() => {
                console.log("Dialog closed!");
            });
        });
    // << fs-update-rename-folder-code
}

