home *** CD-ROM | disk | FTP | other *** search
- /* ***** BEGIN LICENSE BLOCK *****
- *
- * Pearltrees add-on AMO, Copyright(C), 2009, Broceliand SAS, Paris, France
- * (company in charge of developing Pearltrees)
- *
- * This file is part of ΓÇ£Pearltrees add-on AMOΓÇ¥.
- *
- * Pearltrees add-on AMO is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License version 3 as published by the Free Software Foundation.
- *
- * Pearltrees add-on AMO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with Pearltrees add-on AMO.
- * If not, see <http://www.gnu.org/licenses/>
- *
- * ***** END LICENSE BLOCK ***** */
-
- // ///////////////////////////////////////////////////////////////////////////////
- // Note Controller
- // ///////////////////////////////////////////////////////////////////////////////
-
- var BRO_noteController = {
-
- numCommentsOnCurrentUrl : 0,
- defaultText : "",
-
- init : function() {
- this.numCommentsOnCurrentUrl = 0;
- },
-
- onClickCancelNote:function() {
- this.cancelNote();
- },
-
- onClickValidateNote:function() {
- var noteText = document.getElementById('BRO_notePanelContent').text;
- if(!noteText || BRO_tools.trim(noteText) == "") {
- return;
- }
-
- this.closePopup();
- this.saveNoteAndRecordIfNotRecorded(noteText);
- },
-
- onPanelShowing:function() {
- // Use small timeout whereas XBL setters don't work...
- // Don't know why yet :(
- BRO_tools.callWithDelay('BRO_noteController.initPanel()', 20);
- },
-
- initPanel:function() {
- var panelContent = document.getElementById('BRO_notePanelContent');
- panelContent.focus();
- var defaultText = this.getDefaultText();
- if(panelContent.text != defaultText) {
- panelContent.text = "";
- panelContent.defaultText = defaultText;
- }
- },
-
- getDefaultText:function () {
- if (this.numCommentsOnCurrentUrl == 0) {
- this.defaultText = BRO_locale.getString('comment.textbox.defaultValue');
- } else {
- this.defaultText = BRO_locale.getString('comment.textbox.addValue');
- }
- return this.defaultText;
- },
-
- closePopup:function() {
- var notePanel = document.getElementById('BRO_notePanel');
- if (notePanel) {
- notePanel.hidePopup();
- }
- },
-
- cancelNote:function() {
- this.closePopup();
- },
-
- saveNoteAndRecordIfNotRecorded:function(noteText) {
- if(!noteText || BRO_tools.trim(noteText) == "") {
- return;
- }
- if(BRO_toolbar.isCurrentUrlRecorded()) {
- BRO_noteController.saveNote(noteText);
- if (BRO_toolbar.recordingMode == RECORING_MODE_ONE_BY_ONE) {
- BRO_buttonEffectHelper.runIsRecordingEffect();
- BRO_tools.callWithDelay('BRO_buttonEffectHelper.stopIsRecordingEffect()', BRO_buttonEffectHelper.START_RECORDING_EFFECT_TIME);
- }
- }
- else if(!BRO_navListener.urlLoading && BRO_model.isValidUrl(BRO_browserManager.getSelectedBrowserUrl())) {
- var url = BRO_browserManager.getSelectedBrowserUrl();
- if (BRO_toolbar.recordingMode == RECORING_MODE_ONE_BY_ONE && BRO_model.isValidUrl(url)) {
- BRO_toolbar.setRecording(true);
- BRO_ButtonsHandler.recordCurrentPage();
- BRO_tools.callWithDelay('BRO_toolbar.setRecording(false)', BRO_buttonEffectHelper.START_RECORDING_EFFECT_TIME);
- } else if (BRO_toolbar.recordingMode == RECORING_MODE_CONTINUOUS) {
- BRO_toolbar.setRecording(true);
- BRO_ButtonsHandler.recordCurrentPage();
- }
- BRO_tools.callWithDelay("BRO_noteController.saveNote('"+noteText+"')",200);
- }
- },
-
- saveNote : function(noteText) {
- if (BRO_toolbar.recordingMode == RECORING_MODE_CONTINUOUS && !BRO_toolbar.isRecording) {
- return;
- }
- var url = BRO_browserManager.getSelectedBrowserUrl();
- var browserID = BRO_browserManager.getSelectedBrowserID();
- var time = BRO_tools.getTime();
- var comment = null;
- if (noteText) {
- comment = BRO_tools.trim(noteText);
- }
- if (BRO_model.isValidUrl(url) && comment != '' && comment != this.getDefaultText()) {
- this.numCommentsOnCurrentUrl++;
- BRO_model.addComment(url, browserID, time, comment);
- }
- }
- }