User:BZPN/PNHelper.js

From Test Wiki
Revision as of 16:25, 20 November 2024 by BZPN (talk | contribs) (Restored revision 53155 by BZPN (Restorer))
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// <nowiki>
mw.loader.using(['oojs-ui-core', 'oojs-ui-windows'], function () {
    mw.hook('wikipage.content').add(function ($content) {
        // Tworzenie przycisku
        var $button = $('<li id="t-custom-task"><a href="#"></a></li>');
        $button.find('a').text('Dodaj zadanie');

        // Dodanie przycisku do paska narzędzi
        $('#p-tb ul').append($button);

        // Funkcja tworząca okno dialogowe
        function createDialog() {
            var dialog = new OO.ui.MessageDialog({
                size: 'medium'
            });

            // Tworzenie pól formularza
            var titleInput = new OO.ui.TextInputWidget({
                placeholder: 'Wpisz tytuł zadania'
            });

            var descriptionInput = new OO.ui.MultilineTextInputWidget({
                placeholder: 'Wpisz opis zadania',
                rows: 5
            });

            var addLinkButton = new OO.ui.ButtonWidget({
                label: 'Dodaj link',
                disabled: true // Na razie nieaktywny
            });

            // Konfiguracja okna dialogowego
            var config = {
                title: 'Dodaj nowe zadanie',
                message: new OO.ui.FieldsetLayout({
                    items: [
                        new OO.ui.FieldLayout(titleInput, {
                            label: 'Tytuł',
                            align: 'top'
                        }),
                        new OO.ui.FieldLayout(descriptionInput, {
                            label: 'Opis',
                            align: 'top'
                        }),
                        new OO.ui.FieldLayout(addLinkButton, {
                            align: 'top'
                        })
                    ]
                }),
                actions: [
                    {
                        action: 'cancel',
                        label: 'Anuluj',
                        flags: 'safe'
                    },
                    {
                        action: 'submit',
                        label: 'Zapisz',
                        flags: ['primary', 'progressive']
                    }
                ]
            };

            // Otwieranie okna dialogowego
            var windowManager = new OO.ui.WindowManager();
            $('body').append(windowManager.$element);
            windowManager.addWindows([dialog]);
            windowManager.openWindow(dialog, config);

            // Obsługa zamykania okna
            dialog.on('closing', function (windowManager, promise) {
                promise.done(function (data) {
                    if (data && data.action === 'submit') {
                        console.log('Zapisano zadanie:', titleInput.getValue(), descriptionInput.getValue());
                    }
                });
            });
        }

        // Dodanie obsługi kliknięcia przycisku
        $button.on('click', function (e) {
            e.preventDefault();
            createDialog();
        });
    });
});
// </nowiki>