source: trunk/prototype/modules/mail/js/label.js @ 5573

Revision 5573, 16.0 KB checked in by thiago, 12 years ago (diff)

Ticket #2486 - Trocado algumas traduções nos marcadores

  • Property svn:executable set to *
Line 
1function configureLabel(event, ui){
2        var idmarkernow = $(this).find('[name="labelItemId"]').val();
3        winElement.find('.edit-label').val(idmarkernow);
4        winElement.find('.input-nome').val($(this).find("span").text());
5       
6        var colorpicker = winElement.find('.lebals-colorpicker');
7        colorpicker.find('input[name="backgroundColor"]').val(rgb2hex($(this).css("backgroundColor")))
8        .css("background-color", $(this).css("backgroundColor")).focus().end()
9        .find('input[name="fontColor"]').val(rgb2hex($(this).css("color"))).css("background-color", $(this).css("color")).focus().end()
10        .find('input[name="borderColor"]').val(rgb2hex($(this).css("border-left-color"))).css("background-color", $(this).css("border-left-color")).focus().end()
11        .find('.preview-label-outer').css({
12                'background-color':$(this).css("backgroundColor"),
13                'color':$(this).css("color"),
14                'border-color':$(this).css("border-left-color")
15        })             
16        winElement.find(".preview-label-inner").text($(this).text());
17}
18
19function editLabel(){   
20        var conteudoSpan = $(this).parent().find(".text-list").text();
21        var span = $(this).parent().find(".text-list");
22        $(this).parent().trigger('click').unbind('click', configureLabel).find("span.text-list")
23        .html('<input name="edit-value-list" class="edit-value-list" type="text" value="'+conteudoSpan+'">').find("input[name='edit-value-list']").keydown(function(event){
24                event.stopPropagation();
25                $("input.edit-value-list").keyup(function () {
26                        var value = $(this).val();
27                        winElement.find('.input-nome').val(value);
28                }).keyup();
29                if(event.keyCode == 13){
30                        $(span).html($(".label-list").find(".edit-value-list").val())
31                        .parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel).trigger("click");
32                        save_editLabel();
33                       
34                }else if( event.keyCode == 27){
35                        $(this).trigger("focusout");
36                }
37        }).focusout(function(){
38                $(span).html(conteudoSpan)
39                .parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel);
40        }).focus();
41        $(this).addClass("hidden");
42}
43
44function deleteLabel(event){
45        var id = $(this).parents(".label-item").attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/)[1];
46        confirmDelete(id);
47        event.stopImmediatePropagation();
48}
49
50function colors_suggestions(){
51        return [
52                                {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'},
53                                {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'},
54                                {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'},
55                                {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'},
56                                {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'}
57                        ]               
58}
59
60function rgb2hex(rgb){
61 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
62 return "#" +
63  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
64  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
65  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
66}
67
68function confirmDelete(id){
69        $.Zebra_Dialog('<strong>Deseja excluir esse marcador?</strong>', {
70                'type':     'question',
71                'title':    'Atenção',
72                'buttons': ['Sim','Não'],       
73                'onClose':  function(caption) {
74                        if(caption == 'Sim'){
75                                delete_label(id);
76                        }
77                }
78        });     
79}               
80       
81function save_editLabel(){             
82        var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
83        // salvar marcador
84        if(qtdLi > 0){
85                $(".save-label").button("disable");
86                var labelEdited = {
87                        id : winElement.find(".edit-label").val(),
88                        uid: User.me.id,
89                        name : winElement.find('.input-nome').val(),
90                        backgroundColor : winElement.find("input[name='backgroundColor']").val(),
91                        fontColor : winElement.find("input[name='fontColor']").val(),
92                        borderColor : winElement.find("input[name='borderColor']").val()
93                }
94                $(".label-list-container .label-list li").each(function(){
95                        var regex_match_2 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
96                       
97                         if(regex_match_2 && regex_match_2[1] && regex_match_2[1] == labelEdited.id){
98                           $(this).html("<input type='hidden' name='labelItemId' class='id-item-list' value='"+labelEdited.id+"'>"+"<span class='text-list'>"+labelEdited.name+"</span><div class='button close tiny' style='float: right'></div><div class='button edit tiny' style='float: right'></div>").css({
99                                "background" : labelEdited.backgroundColor,
100                                "color" : labelEdited.fontColor,
101                                "border-color" : labelEdited.borderColor       
102                           });
103                         }     
104                });
105               
106                $("#MyMarckersList .label-list li").each(function(){
107                        var regex_match_2 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
108                       
109                        if(regex_match_2 && regex_match_2[1] && regex_match_2[1] == labelEdited.id){
110                                $(this).html("<input type='hidden' name='labelItemId' class='id-item-list' value='"+labelEdited.id+"'>"+"<span>"+labelEdited.name+"</span>");
111                                $(this).find(".square-color").css('background', labelEdited.backgroundColor);
112                        }       
113                });
114                DataLayer.put('label', labelEdited.id, labelEdited);
115                DataLayer.commit(false, false, function(){
116                        winElement.find(".insert-label").val("");
117                        $.Watermark.ShowAll();
118                       
119                        $(".label-list-container .label-list li").find('.button').button()
120                                .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
121                                .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
122                               
123                        winElement.find('.edit').unbind("click").click(editLabel);                             
124                        winElement.find('.close').click(deleteLabel);
125                       
126                        draw_tree_labels();
127                       
128                        /**
129                        * Atualiza menu remove o menu presente em cada mensagem listada em uma pasta
130                        * e carrega novamente para que os dados sejam atualizados
131                        */
132                        $.contextMenu( 'destroy', ".table_box tbody tr");
133                        loadMenu();
134                });
135        // criar marcador
136        } else {
137                var nameLabel = winElement.find(".input-nome").val();
138                if(nameLabel.length >= 2){
139                        new_label(nameLabel, false);                           
140                        winElement.find(".insert-label").val("");
141                        $.Watermark.ShowAll();                         
142                } else {
143                        alert("Mínimo 2 caracteres");
144                }
145        }                               
146        $(".label-list-container .label-list").find(".label-item-"+labelEdited.id).trigger("click");
147}
148
149function delete_label(id){
150        $(".label-list li").each(function () {
151                var regex_match = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
152                if (regex_match && regex_match[1] && regex_match[1] == id) {   
153                        $(this).remove();
154                }
155        });
156        DataLayer.remove('label', id);
157        DataLayer.commit();
158        winElement.find(".label-list li:first").trigger("click");
159       
160        if($(".label-list li").length == 0){
161                winElement.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">'+get_lang("No labels found")+'.</li></ul>');                     
162        }
163        var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
164        if (qtdLi == 0){
165                $(".my-labels").addClass("hidden");
166                $(".label-list-container ul").find(".empty-item").css("display","");
167                winElement.find(".buttons .save-label .ui-button-text").text('Criar');
168                $(".delete-label").button("disable");   
169                               
170                winElement.find('.input-nome').val("");
171                winElement.find(".preview-label-inner").text("");
172       
173                var colorpicker = winElement.find('.lebals-colorpicker');
174                colorpicker.find('input[name="backgroundColor"]').val("#ebebeb")
175                .css("background-color", "#ebebeb").focus().end()
176                .find('input[name="fontColor"]').val("#000000").css("background-color", "#000000").focus().end()
177                .find('input[name="borderColor"]').val("#000000").css("background-color", "#000000").focus().end()
178                .find('.preview-label-outer').css({
179                        'background-color':"#ebebeb",
180                        'color':"#000000",
181                        'border-color':"#000000"
182                });
183                $(".input-nome").keyup(function () {
184                        var value = $(this).val();
185                        winElement.find('.preview-label-inner').text(value);
186                }).keyup();                             
187        }               
188}
189
190function new_label(nameLabel, isNew){
191        var labelCreated = {
192                uid: User.me.id,
193                name : nameLabel,
194                backgroundColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
195                fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
196                borderColor :!!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
197        }
198        DataLayer.put('label', labelCreated);
199       
200        $(".add-label-button").removeClass("ui-icon ui-icon-plus")
201        .html('<img alt="Carregando" title="Carregando" style="margin-left:10px;" src="../prototype/modules/mail/img/loader.gif" />');
202       
203        DataLayer.commit(false, false, function(){
204
205                labels = DataLayer.get('label',{criteria:{order: 'id'}}, true);
206                newLabel = {
207                        id: labels[labels.length - 1].id,
208                        name : labels[labels.length- 1].name,
209                        uid: User.me.id,
210                        bgColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
211                        fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
212                        borderColor : !!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
213                };
214
215                $(".label-list-container ul").find(".empty-item").css("display","none");
216                $(".label-list-container ul")
217                .prepend(DataLayer.render("../prototype/modules/mail/templates/label_listitem.ejs", newLabel))
218                .find("li:first")
219                .fadeIn("slow").click(configureLabel);
220               
221                draw_tree_labels();
222
223                $(".label-list-container .label-list li").not(".empty-item").click(function(){
224                        $(".label-list-container .label-list li").find("img").remove();
225                        $(".label-list-container .label-list li.label-item").removeClass("selected");
226                        $(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
227                        $(this).addClass("selected");
228                });
229               
230                $(".label-list-container .label-list li").find('.button').button()
231                .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
232                .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
233               
234                //posiciona para edição o label inserido                       
235                winElement.find("ul.label-list li:first").trigger("click");                     
236                winElement.find(".buttons .save-label .ui-button-text").text('Salvar');
237                $(".delete-label").button("enable");
238               
239                winElement.find('.edit').unbind("click").click(editLabel);                             
240                winElement.find('.close').click(deleteLabel);
241               
242                $(".my-labels").removeClass("hidden");
243               
244                $.contextMenu( 'destroy', ".table_box tbody tr");
245                loadMenu();
246               
247                $(".add-label-button").empty()
248                .addClass("ui-icon ui-icon-plus");
249        });
250}
251
252function init_label(data){
253
254        winElement = data.window;
255       
256        //TODO Mudar quando API abstrair atualizações no cache
257        DataLayer.remove('label',false);
258        labels = DataLayer.get('label',{criteria:{order: 'name'}});
259       
260        if(labels){
261                Label_List = winElement
262                .find(".label-list-container").html(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels: labels}));
263               
264        }else{
265                //Exibe a mensagem informando o usuário de que não há nenhum marcador cadastrado.
266                Label_List = winElement
267                .find(".label-list-container").html('<ul class="label-list"><li class="empty-item">'+get_lang("No labels found")+'.</li></ul>');
268               
269        }
270        Label_List.end()
271        .find('.button').button()
272        .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
273        .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});       
274       
275        winElement.find('.edit').click(editLabel);
276        winElement.find('.close').click(deleteLabel);
277       
278        //marca 'd agua
279        winElement.find(".insert-label").Watermark(winElement.find(".insert-label").val());
280       
281        $("input.insert-label").keyup(function () {
282                $.Watermark.HideAll();
283                var value = $(this).val();
284                winElement.find('.input-nome').val(value);
285        }).keyup();
286       
287        if (!(labels)){
288                winElement.find(".buttons .save-label .ui-button-text").text('Criar');
289                $(".delete-label").button("disable");
290        }else{
291                winElement.find(".label-list li:first").addClass("selected").prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
292        }
293        $(".save-label").button("disable");
294        /**
295        * seta a ação de click para os marcadores listados na tela
296        */
297        winElement.find(".label-list li").not(".empty-item").click(configureLabel);
298       
299        if (data.selectedItem)
300                winElement.find(".label-list li.label-item-"+data.selectedItem).trigger("click");
301        else
302                winElement.find(".label-list li:first").trigger("click");
303               
304        var dataColorPicker = {
305                colorsSuggestions: colors_suggestions()
306        };
307       
308        winElement.find('select.color-suggestions').change(function() {
309                $(".save-label").button("enable");
310                var colorpicker = winElement.find('.lebals-colorpicker');
311                var colors;
312                if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) {
313                        colorpicker
314                        .find('input[name="fontColor"]').val(colors.font).focus().end()
315                        .find('input[name="backgroundColor"]').val(colors.background).focus().end()
316                        .find('input[name="borderColor"]').val(colors.border).focus().end()
317
318                        .find('.preview-label-outer').css({
319                                'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background,
320                                'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border,
321                                'color':dataColorPicker.colorsSuggestions[$(this).val()].font
322                        });
323                }                                       
324        });
325        var colorpickerPreviewChange = function(color) {
326                       
327                var pickedup = winElement.find('.colorwell-selected').val(color).css('background-color', color);
328
329                $(".save-label").button("enable");
330               
331                var colorpicker = winElement.find('.lebals-colorpicker');                       
332
333                if (pickedup.is('input[name="backgroundColor"]')) {
334                        colorpicker.find('.preview-label-outer').css('background-color',color);
335                } else if (pickedup.is('input[name="fontColor"]')) {
336                        colorpicker.find('.preview-label-outer').css('color',color);
337                } else if (pickedup.is('input[name="borderColor"]')) {
338                        colorpicker.find('.preview-label-outer').css('border-color',color);
339                }               
340        }
341               
342        var f = $.farbtastic(winElement.find('.colorpicker'), colorpickerPreviewChange);
343        var selected;
344                               
345        winElement.find('.colorwell').each(function () {
346                f.linkTo(this);
347        })
348        .focus(function() {
349                if (selected) {
350                        $(selected).removeClass('colorwell-selected');
351                }
352                $(selected = this).addClass('colorwell-selected');
353                f.linkTo(this, colorpickerPreviewChange);
354                f.linkTo(colorpickerPreviewChange);
355        });
356       
357        winElement.find(".add-label-button").click(function (event) {
358                $.Watermark.HideAll();
359                var nameLabel = winElement.find(".insert-label").val();
360                if(nameLabel.length >= 2){
361                        new_label(nameLabel, true);
362                        $.Watermark.ShowAll();
363                        winElement.find(".insert-label").val("");
364                        } else {
365                                alert("Mínimo 2 caracteres");
366                        }
367                event.stopImmediatePropagation();
368        });
369       
370        winElement.find('.insert-label').keydown(function(event, ui) {
371                if (event.keyCode == 13)
372                        winElement.find(".add-label-button").trigger('click');
373        });
374       
375        //excluir marcador {deve ser para o botão grande na janela de edição e nao o pequeno da lista}
376        winElement.find(".buttons .delete-label").click(function(event){
377                var id = winElement.find(".edit-label").val();
378                confirmDelete(id);
379                event.stopImmediatePropagation();
380        });
381       
382        $(".label-list-container .label-list li").not(".empty-item").click(function(){
383                $(".label-list-container .label-list li").find("img").remove();
384                $(".label-list-container .label-list li.label-item").removeClass("selected");
385                $(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
386                $(this).addClass("selected");
387        });
388               
389        //salvar/criar marcador
390        winElement.find(".buttons .save-label").click(function(){
391                save_editLabel();
392        });     
393        //desfazer marcador
394        winElement.find(".buttons .undo-label").click(function(event){
395                var edit = winElement.find(".edit-label").val();               
396                $(".label-list-container .label-list li").each(function(){
397                        var regex_match_3 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
398                        if(regex_match_3 && regex_match_3[1] && regex_match_3[1] == edit){
399                                $(this).trigger("click");
400                        }
401                });
402        });
403       
404        //fechar
405        $(".button-close-window .close-window").click(function(){
406                $(".label-configure-win").dialog("close");
407        });     
408                       
409        $(".configure-label-content").find("input[type='text']").focus(function () {
410                $(this).keyup(function(){
411                        var value = $(this).val();
412                        if(value){
413                                $(".save-label").button("enable");     
414                        }else{
415                                $(".save-label").button("disable");     
416                        }
417                });
418        });     
419       
420        $(".input-nome").keyup(function () {
421                                var value = $(this).val();
422                                winElement.find('.preview-label-inner').text(value);
423        }).keyup();     
424}
425
426/**
427 * TODO:
428 * * Qunado excluir um marcador deve ser removido das mensagens sem que seja necessario atualizar o Expresso.
429 * * Quando editado um marcador dever ser atualizado na lista de mensagem onde esse marcador foi aplicado.
430 */
Note: See TracBrowser for help on using the repository browser.