Diialog: Some settings were changed. Do you want to save them?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcoc1712
    Senior Member
    • Dec 2009
    • 844

    Diialog: Some settings were changed. Do you want to save them?

    When the user try to leave a setting page without "apply" changes, the dialog "Settings" with message "Some settings were changed. Do you want to save them?" is shown.

    I'm quite fresh with html and JS and i'm fumbling with the code but I could not find where and how is triggered.

    One of my prefs is an hash rendered as a table of CB, moddification of elements in this table is not catched and the Dialog is not show, so I would like to manually trigger it.

    Thx.

    Marco
    __________________________________________________ ______________________
    Author of C-3PO plugin, Squeezelite-R2, Falcon Web interface - See www.marcoc1712.it
  • mherger
    Babelfish's Best Boy
    • Apr 2005
    • 24615

    #2
    Diialog: Some settings were changed. Do you wantto save them?

    > I'm quite fresh with html and JS and i'm fumbling with the code but I
    > could not find where and how is triggered.


    Once the settings page has rendered, it will register change handles to
    check for change:



    > One of my prefs is an hash rendered as a table of CB, moddification of
    > elements in this table is not catched and the Dialog is not show, so I
    > would like to manually trigger it.


    I'm not 100% sure I do understand what you're doing there. But if you
    dynamically load content after the page had been rendered (through some
    ajax call or the like), you'd have to register those change handlers
    yourself. You could just call the same method as outlined above.

    --

    Michael
    Michael

    "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
    (LMS: Settings/Information)

    Comment

    • marcoc1712
      Senior Member
      • Dec 2009
      • 844

      #3
      Originally posted by mherger
      > I'm quite fresh with html and JS and i'm fumbling with the code but I
      > could not find where and how is triggered.


      Once the settings page has rendered, it will register change handles to
      check for change:



      > One of my prefs is an hash rendered as a table of CB, moddification of
      > elements in this table is not catched and the Dialog is not show, so I
      > would like to manually trigger it.


      I'm not 100% sure I do understand what you're doing there. But if you
      dynamically load content after the page had been rendered (through some
      ajax call or the like), you'd have to register those change handlers
      yourself. You could just call the same method as outlined above.

      --

      Michael
      I'm doing this:

      a. PREF FILE:

      Code:
      ...
      codecs:
          aac: ~
          aif: on
          alac: ~
          alc: on
          dff: on
          dsf: on
          flc: on
          mp3: ~
          wav: on
      ...
      b. PlayerSettings.pm sub handler:

      Code:
      my $prefCodecs   = $prefs->client($client)->get('codecs');
      $params->{'prefs'}->{'codecs'}=$prefCodecs;
      c. in player.html

      Code:
      ...
      <table>
              <tr>
                          <td>    
                              <input type="checkbox" name="pref_codecs[% codec.key %]" 
                                     id="codec[% codec.key %]" value="1" 
                                     [% codec.value ? "checked" : "" %]>
                              </input>
                          </td>
              </tr>
      </table>
      ...
      d. then, back in PlayerSettings.pm sub handler:

      Code:
       
      if ($params->{'saveSettings'}){
      
           for my $k (keys %$prefCodecs){
      
              $prefCodecs->{$k} = $params->{'pref_codecs'.$k} ? 'on' : undef;
      
          }
          ...
          $prefs->writeAll();
          $prefs->savenow();
      }
      The above, just to let you understand, is not the actual code.

      adding: onchange="this._checkModified"

      to any checkbox createt, like that:

      Code:
      <input type="checkbox" name="pref_codecs[% codec.key %]" 
                  id="codec[% codec.key %]" value="1" 
                  [% codec.value ? "checked" : "" %]
                  onchange="this._checkModified" 
                  onblur="this._checkModified">
      </input>
      does not work, sure there is something obvious that I miss...

      Thanks for your time.
      __________________________________________________ ______________________
      Author of C-3PO plugin, Squeezelite-R2, Falcon Web interface - See www.marcoc1712.it

      Comment

      • mherger
        Babelfish's Best Boy
        • Apr 2005
        • 24615

        #4
        Diialog: Some settings were changed. Do you wantto save them?

        > The above, just to let you understand, is not the actual code.

        Then please show me the actual code. Because there's no reason to
        discuss code you're not using.

        > adding: onchange="this._checkModified"


        That's not how it works. As I said in my previous mail you would only
        have to care about this if you created your table _after_ the page had
        been rendered, eg. using AJAX.

        --

        Michael
        Michael

        "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
        (LMS: Settings/Information)

        Comment

        • marcoc1712
          Senior Member
          • Dec 2009
          • 844

          #5
          Originally posted by mherger
          > The above, just to let you understand, is not the actual code.

          Then please show me the actual code. Because there's no reason to
          discuss code you're not using.

          > adding: onchange="this._checkModified"


          That's not how it works. As I said in my previous mail you would only
          have to care about this if you created your table _after_ the page had
          been rendered, eg. using AJAX.

          --

          Michael
          here the repo and the branch you could look a (please forgive the typo in the branch name):

          https://github.com/marcoc1712/C-3PO/...ettings_change, files are:

          1. player.html build up the page assembling different smaller components, the one to look at is functionsPerCodecs.html



          2. PlayerSettings.pm :




          and




          thanks.
          __________________________________________________ ______________________
          Author of C-3PO plugin, Squeezelite-R2, Falcon Web interface - See www.marcoc1712.it

          Comment

          • mherger
            Babelfish's Best Boy
            • Apr 2005
            • 24615

            #6
            Diialog: Some settings were changed. Do you wantto save them?

            Wow... what shall I say?... hard to tell what is breaking things.
            There's a lot of potential for it in your code :-). You seem to be
            re-inventing LMS. Transcoding, logging, prefs handling, html templates...

            One potential issue wrt. to your initial request is the fact that you're
            creating multiple html headers in the settings pages. You write your own
            with a few JS snippets, then include LMS' default header. Most likely
            this is killing LMS' JS initialization, as your browser would ignore the
            second header section.

            --

            Michael
            Michael

            "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
            (LMS: Settings/Information)

            Comment

            • marcoc1712
              Senior Member
              • Dec 2009
              • 844

              #7
              Originally posted by mherger
              Wow... what shall I say?... hard to tell what is breaking things.
              There's a lot of potential for it in your code :-). You seem to be
              re-inventing LMS. Transcoding, logging, prefs handling, html templates...

              One potential issue wrt. to your initial request is the fact that you're
              creating multiple html headers in the settings pages. You write your own
              with a few JS snippets, then include LMS' default header. Most likely
              this is killing LMS' JS initialization, as your browser would ignore the
              second header section.

              --

              Michael
              This plugin is born to facilitate transcoding, but - at least in the on line part - it uses all of the standard LMS features, that's why I'm asking how to use this one, if possible.

              Logging, prefs and others are redefined to be used in the 'batch' part of the transcoder, nothing todo with the plugin itself, other than sharing as much code as possible.

              The reason why I need a 'batch' part is that transcoding in LMS 'lack' the capability to setup transcoder chain depending on the actual file/stream being played, patching LMS was maybe simpler, but I did not want take that route.

              Back on the Hash preferenxe problem, I could write a smaller dummy plugin to replicate the problem , if you like to investigate it, but, debugging, I verified that "this._checkModified" is called when I click on one of the CB, but values are always :

              modifed: false
              input.value = 1
              default.value = 1

              no matter the actual value of the CB, so resulting "modified" var is always false, so no alert or dialog is shown. I'll have som further debiugging to uunderstand why this happen.

              Thanks for your help.
              __________________________________________________ ______________________
              Author of C-3PO plugin, Squeezelite-R2, Falcon Web interface - See www.marcoc1712.it

              Comment

              • mherger
                Babelfish's Best Boy
                • Apr 2005
                • 24615

                #8
                Diialog: Some settings were changed. Do you wantto save them?

                > Back on the Hash preferenxe problem, I could write a smaller dummy
                > plugin to replicate the problem , if you like to investigate it, but,
                > debugging, I verified that "this._checkModified" is called when I click
                > on one of the CB, but values are always :


                As I said before: you don't have to call _checkModified. You have to fix
                your HTML.

                --

                Michael
                Michael

                "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
                (LMS: Settings/Information)

                Comment

                • marcoc1712
                  Senior Member
                  • Dec 2009
                  • 844

                  #9
                  Originally posted by mherger
                  > Back on the Hash preferenxe problem, I could write a smaller dummy
                  > plugin to replicate the problem , if you like to investigate it, but,
                  > debugging, I verified that "this._checkModified" is called when I click
                  > on one of the CB, but values are always :


                  As I said before: you don't have to call _checkModified. You have to fix
                  your HTML.

                  --

                  Michael
                  In the version I've submitted to you , _checkModified is not called manually, indeed my intent was just to confirm you that it was triggered, but - seems to me - with wrong values.

                  Anyway,

                  here; https://github.com/marcoc1712/dummy

                  Is a very simple plugin doing NOTHING, no extra html in it, just exposing some fake settings. You could verify the problem I was asking an help for.

                  Sure it's me, but I could not understand what part of HTML I have to modify, could you please articulate a bit for me?

                  thanks.

                  EDIT: the p.s was partially incorrect, please forget it.
                  Last edited by marcoc1712; 2017-04-18, 16:13.
                  __________________________________________________ ______________________
                  Author of C-3PO plugin, Squeezelite-R2, Falcon Web interface - See www.marcoc1712.it

                  Comment

                  • marcoc1712
                    Senior Member
                    • Dec 2009
                    • 844

                    #10
                    HI,

                    with more debugging I've found that the problem rise when you impose the value for the input CB:

                    Code:
                     <input name="pref_checkbox" type="checkbox"[% IF prefs.checkbox %] checked [% END %]>
                    works,

                    Code:
                     <input name="pref_checkbox" type="checkbox" value="on" [% IF prefs.checkbox %] checked [% END %]>
                    does not.

                    this is just becouse the test:


                    Code:
                    modified = modified || (input.value != input.defaultValue);
                    is fired every time the user enter and exits (blur) from the input, BUT with CB is does not really compare current value versus default value, just if a default value where imposed.

                    Works, but not how one could expect and only in certain circumstance.

                    I'll add a note in the code at least.

                    Hope it helps someone to avoid same troubles.
                    __________________________________________________ ______________________
                    Author of C-3PO plugin, Squeezelite-R2, Falcon Web interface - See www.marcoc1712.it

                    Comment

                    • mherger
                      Babelfish's Best Boy
                      • Apr 2005
                      • 24615

                      #11
                      Diialog: Some settings were changed. Do you wantto save them?

                      > is fired every time the user enter and exits (blur) from the input, BUT
                      > with CB is does not really compare current value versus default value,
                      > just if a default value where imposed.


                      Good finding!

                      --

                      Michael
                      Michael

                      "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
                      (LMS: Settings/Information)

                      Comment

                      Working...